Solidworks macro to add mass/weight custom properties for cut lists

If you want to list weights of welded parts in a cut list, you’ll have to add properties to weldments by hand, one by one …

Here is a macro that does it automatically.

'AddWeldMass Solidworks macro to add a mass/weight custom property to each weldment
'so that it can be displayed in a cut list
'Author : Ph. Guglielmetti, e-Systems Switzerland, all rights reserved
'Licence: you may use this macro for free, as long as this header is kept untouched.
'License: no support is provided, except for e-Systems customers
'Licence: it is forbidden to sell this code or publish it elsewhere without our permission
'Revision : PGu 2007/01/11 because I was tired to do this by hand …
Option Explicit
Private Const propname As String = "POIDS" ' change to "MASS" or whatever you prefer
Private Const proptype As String = "Texte" ' in english you must change to "Text". See comment in code…
Sub AddMassProps() ' main
    Dim swApp As SldWorks.SldWorks
    Set swApp = Application.SldWorks
    Dim doc As SldWorks.ModelDoc2
    Set doc = swApp.ActiveDoc
    'Traverse all features
    Dim f As Feature: Set f = doc.FirstFeature
    Do While Not f Is Nothing
        If f.GetTypeName = "CutListFolder" Then ' not "SubWeldFolder" as captured by macro recorder ?
            'the following API call is a typical example of mindless localization :
            'the "proptype" string constant depends on the user language, which
	    'prevents the macro from running everywhere without adaptation !
            'this was corrected in the Add2 call available from SW2007…
        	If f.CustomPropertyManager.Add(propname, proptype, Chr(34) + _
			"SW-Mass@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) Then
                	Debug.Print "Property "; propname; " added to feature "; f.Name
            End If
        End If
        Set f = f.GetNextFeature
End Sub

One Response to “AddWeldMass”

  1. This is a great Macro. What would be really cool though would be a Macro that calculates the number of pieces of stock you have to order based on the cut list and the standard stock sizes. For example, if you need a quantity of 3 pieces that are 2 meters each and the stock comes in standard length of 5 meters, then you will need to order 2 pieces of stock.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: