AnsweredAssumed Answered

Renaming Cutlist Bodies from Weldment Cutlist Custom Properties

Question asked by Dan Vorpahl on Dec 3, 2019
Latest reply on Dec 3, 2019 by Artem Taturevych

I need some help modifying a macro I have found.  The macro is to rename bodies of a weldment.  It works great except for I am wanting it to pull a custom property (named "PART_NUMBER") from the weldment cutlist properties.  I need the prefixName to pull my custom property "PART_NUMBER"

 

 

Dim swApp As Object
Option Explicit

Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swPart As SldWorks.PartDoc
    Dim vBodyArr As Variant

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swPart = swModel

    swModel.ClearSelection2 True
    vBodyArr = swPart.GetBodies2(0, False)
    RenameBodies swModel, vBodyArr
End Sub

Sub RenameBodies(swModel As SldWorks.ModelDoc2, vBodyArr As Variant)
    Dim vBody As Variant
    Dim swBody As SldWorks.Body2
    Dim prefixName As String
    Dim bodycount As Integer

    bodycount = 1

    If IsEmpty(vBodyArr) Then Exit Sub

    prefixName = "NEED THIS TO PULL FROM A CUSTOM WELDMENT PROPERTY (NAMED "PART_NUMBER")"

    For Each vBody In vBodyArr
        vBody.Name = prefixName & bodycount
        bodycount = bodycount + 1
    Next vBody

    swModel.EditRebuild3
End Sub

 

Any help would be greatly appreciated.  I am hoping Deepak Gupta can help out as he seems to be the God of Soildworks macros.

Outcomes