I am working on a macro that gets the bounding box property value in a Sheet Metal cutlist feature and creates a document custom property with the Bounding Box value. I found a macro in the API Help file that can get me started. The sample macro requires the user to select the cutlist feature. I am trying to use the "FeatureByName" so the user doesnt have to select the feature. The scope for my macro is to traverse all sheetmetal parts in an assembly, creating this custom property for each part, then exporting a BOM with the custom property values of each sheet metal parts bounding box. When I run the macro below, I get an error message that states: Run-time error 91: Object variable or With block variable not set. @ line retVal = swCutlistItem.Select2(False, -1)
I know that error 91 is when you havent "Set" an object. Unless I am missing something, it looks like I set the object.
SolidworksApi macrosOption Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swCutlistItem As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim names As Variant
Dim name As Variant
Dim textexp As String
Dim evalval As String
Dim retVal As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swCutlistItem = swModel.FeatureByName("Cut-List1")
retVal = swCutlistItem.Select2(False, -1)
Set swCustPropMgr = swCutlistItem.CustomPropertyManager
Debug.Print "Custom Properties for Selected Weldment Cut-list Item"
Debug.Print "Number of custom properties = " + CStr(swCustPropMgr.Count)
Debug.Print "Name", "Text Expression", "Value", "Type"
names = swCustPropMgr.GetNames
For Each name In names
swCustPropMgr.Get2 name, textexp, evalval
Debug.Print name, textexp, evalval, swCustPropMgr.GetType(name)
Next name
End Sub