Perimeter & Bends

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
Answers 17
DG
DG 2015-06-22 Best Answer

Search for cusPropMgr.Add3 and use this with option swCustomPropertyReplaceValue

And use codes from this macro for all configurations:

HA
HA 2015-06-23

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

ST
ST 2015-06-23

    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

HA
HA 2015-06-23

not alter the situation ... appears the same properties of the active configuration to all other...

DG
DG 2015-06-23

Try this

<p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">vConfNameArr = swModel.GetConfigurationNames</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">For i = 0 To UBound(vConfNameArr)</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">       sConfigName = vConfNameArr(i) </p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">       Set swCustPropMgr = swModel.Extension.CustomPropertyManager(sConfigName)</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;"></p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">Set swFeature = swModel.FirstFeature</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">While Not swFeature Is Nothing</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">  If swFeature.GetTypeName = "CutListFolder" Then</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">    Set swCustPropMgr = swFeature.CustomPropertyManager</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">   </p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">    swCustPropMgr.Get4 "Cutting Length-Outer", True, 0, Perimeter</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">    swCustPropMgr.Get4 "Bends", True, 0, Bends</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">   </p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">    Prop1 = Perimeter</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">    Prop2 = Bends</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">      </p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">        swCustPropMgr.Add3 "Perimeter", swCustomInfoText, Prop1, True</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">       swCustPropMgr.Add3 "Bends", swCustomInfoText, Prop2, True</p><p></p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;"> End</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;"> End If</p><p></p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">  Set swFeature = swFeature.GetNextFeature</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">Wend</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;"></p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;"><span>Next i</span></p>
HA
HA 2015-06-23

work like the first code i posted...

DG
DG 2015-06-23

Could you post a sample file to test the macro on?

HA
HA 2015-06-23

it's ok??

DG
DG 2015-06-23

Not macro but a part file on which you're running the macro.

HA
HA 2015-06-23

Ahh

DG
DG 2015-06-23

Try these:

<p>Dim swApp As SldWorks.SldWorks</p><p>Dim swModel As SldWorks.ModelDoc2</p><p>Dim swFeature As SldWorks.Feature</p><p>Dim swCustPropMgr As SldWorks.CustomPropertyManager</p><p>Dim Perimeter As String</p><p>Dim Bends As String</p><p>Dim vConfNameArr            As Variant</p><p>Dim sConfigName             As String</p><p>Dim i                       As Long</p><p></p><p>Sub main()</p><p>Set swApp = Application.SldWorks</p><p>Set swModel = swApp.ActiveDoc</p><p></p><p>vConfNameArr = swModel.GetConfigurationNames</p><p>   For i = 0 To UBound(vConfNameArr)</p><p>       sConfigName = vConfNameArr(i)</p><p>       swModel.ShowConfiguration2 sConfigName</p><p>       swModel.ForceRebuild3 True</p><p>       </p><p>    Set swFeature = swModel.FirstFeature</p><p>        While Not swFeature Is Nothing</p><p>                If swFeature.GetTypeName = "CutListFolder" Then</p><p>                Set swCustPropMgr = swFeature.CustomPropertyManager</p><p>                        swCustPropMgr.Get4 "Cutting Length-Outer", True, 0, Perimeter</p><p>                        swCustPropMgr.Get4 "Bends", True, 0, Bends</p><p>    </p><p>        Set swCustPropMgr = swModel.Extension.CustomPropertyManager(sConfigName)</p><p>                swModel.AddCustomInfo3 sConfigName, "Perimeter", swCustomInfoText, Perimeter</p><p>                swModel.AddCustomInfo3 sConfigName, "Bends", swCustomInfoText, Bends</p><p>            End If</p><p>        Set swFeature = swFeature.GetNextFeature</p><p>        Wend</p><p>    Next i</p><p>End Sub</p>
HA
HA 2015-06-23

IT WORKS LOVELY... Thanks!

Where should add  swCustomPropertyReplaceValue ​ to replace values when the macro run for the second time for example?

DG
DG 2015-06-23

Replace

<p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">swModel.AddCustomInfo3 sConfigName, "Perimeter", swCustomInfoText, Perimeter</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">swModel.AddCustomInfo3 sConfigName, "Bends", swCustomInfoText, Bends</p>

with

<p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">swCustPropMgr.Add3 "Perimeter", swCustomInfoText, <span style="color: #333333; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif;">Perimeter</span>, swCustomPropertyReplaceValue</p><p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">swCustPropMgr.Add3 "Bends", swCustomInfoText, <span style="color: #333333; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif;">Bends</span>, swCustomPropertyReplaceValue</p>
TB
TB 2016-08-10

Deepak, how would you modify it to work with non-sheet metal parts?

DG
DG 2016-08-10

What exactly you want to do with non sheet metal and what properties?

TB
TB 2016-08-10

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.

TB
TB 2016-08-10

I started a new post called "Find perimeter and count features"