Hi everyone
I created this code in order to display the perimeter and bends in each configuration but not work properly...
How can I modify this code so that my perimeter and bends display in every configuration ?
Moreover, how could I change so I subscribe to perimeter values and bends when i run the macro again and again???
for example now i have Bends = 3..... I modify the part and now have 5 bends, and i want to run a macro again to update properties to appear Bends = 5
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeature As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim Prop1 As String
Dim Prop2 As String
Dim Perimeter As String
Dim Bends As String
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim i As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeature = swModel.FirstFeature
While Not swFeature Is Nothing
If swFeature.GetTypeName = "CutListFolder" Then
Set swCustPropMgr = swFeature.CustomPropertyManager
swCustPropMgr.Get4 "Cutting Length-Outer", True, 0, Perimeter
swCustPropMgr.Get4 "Bends", True, 0, Bends
Prop1 = Perimeter
Prop2 = Bends
'Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")
Debug.Print Prop1
Debug.Print Prop2
vConfNameArr = swModel.GetConfigurationNames
For i = 0 To UBound(vConfNameArr)
sConfigName = vConfNameArr(i)
swModel.AddCustomInfo3 sConfigName, "Perimeter", swCustomInfoText, Prop1
swModel.AddCustomInfo3 sConfigName, "Bends", swCustomInfoText, Prop2
Next i
End
End If
Set swFeature = swFeature.GetNextFeature
Wend
End Sub
SolidworksApi macros
Search for cusPropMgr.Add3 and use this with option swCustomPropertyReplaceValue
And use codes from this macro for all configurations:
I don't know where to set the code and how to juggle with properties so appear in each configuration..
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeature As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim Prop1 As String
Dim Prop2 As String
Dim Perimeter As String
Dim Bends As String
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim i As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeature = swModel.FirstFeature
While Not swFeature Is Nothing
If swFeature.GetTypeName = "CutListFolder" Then
Set swCustPropMgr = swFeature.CustomPropertyManager
swCustPropMgr.Get4 "Cutting Length-Outer", True, 0, Perimeter
swCustPropMgr.Get4 "Bends", True, 0, Bends
Prop1 = Perimeter
Prop2 = Bends
'Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")
Debug.Print Prop1
Debug.Print Prop2
vConfNameArr = swModel.GetConfigurationNames
For i = 0 To UBound(vConfNameArr)
sConfigName = vConfNameArr(i)
swModel.AddCustomInfo3 sConfigName, "Perimeter", swCustomInfoText, Prop1
swModel.AddCustomInfo3 sConfigName, "Bends", swCustomInfoText, Prop2
swModel.AddCustomInfo3 "Perimeter", swCustomInfoText, Prop1, swCustomPropertyReplaceValue
swModel.AddCustomInfo3 "Bends", swCustomInfoText, Prop2, swCustomPropertyReplaceValue
Next i
End
End If
Set swFeature = swFeature.GetNextFeature
Wend
End Sub
Debug.Print Prop1
Debug.Print Prop2
vConfNameArr = swModel.GetConfigurationNames
For i = 0 To UBound(vConfNameArr)
sConfigName = vConfNameArr(i)
Set swCustPropMgr = swModel.Extension.CustomPropertyManager(sConfigName)
swCustPropMgr.Add3 "Perimeter", swCustomInfoText, Prop1, True
swCustPropMgr.Add3 "Bends", swCustomInfoText, Prop2, True
Next i
not alter the situation ... appears the same properties of the active configuration to all other...
Try this
work like the first code i posted...
Could you post a sample file to test the macro on?
it's ok??
Not macro but a part file on which you're running the macro.
Ahh
Try these:
IT WORKS LOVELY... Thanks!
Where should add swCustomPropertyReplaceValue to replace values when the macro run for the second time for example?
Replace
with
Deepak, how would you modify it to work with non-sheet metal parts?
What exactly you want to do with non sheet metal and what properties?
I'm trying to find the profile length of all my parts in an assembly. The parts are imported STEP files.
I already run a macro that gets the bounding box dimensions, but the profile is important for estimating the time it takes to cut a part out of sheet stock.
I will start a new thread.
I started a new post called "Find perimeter and count features"