17 Replies Latest reply on Jan 19, 2017 9:37 AM by Arif Akbas

    How can I rename Cutlist Folders

    Shaun Jalbert

      I have a snippit of code that I'm trying to modify but I'm not having any luck. This code finds the file name and renames the cutlist folders to match and adds a sequential instance number after it. Folders looks like:

      <filename>-1

      <filename>-2

      etc..

       

      What I want it to do is look up a custom property called "WLD_MK_NO" instead of the file name, then rename the cutlist folders to match "WLD_MK_NO" and add the sequential instance number after it.

      <WLD_MK_NO>-1

      <WLD_MK_NO>-2

      etc..

       

      How can I achieve this?

       

       

      Dim swApp As Object

      Sub Main()

      Dim swApp As SldWorks.SldWorks

      Set swApp = Application.SldWorks

      Dim doc As SldWorks.ModelDoc2: Set doc = swApp.ActiveDoc

      Dim partdoc As SldWorks.partdoc: Set partdoc = doc

      Dim f As IFeature: Set f = doc.FirstFeature

      Dim bRet As Boolean

      Dim n As Integer: n = 0

      Dim num As String

      Dim modDocExt As SldWorks.ModelDocExtension

      Dim Part As Object

      Dim boolstatus As Boolean

      Dim BodyFolder As SldWorks.BodyFolder

      Dim BodyCount As Long

       

      Do While Not f Is Nothing

      If f.GetTypeName = "CutListFolder" Then  

              Set BodyFolder = f.GetSpecificFeature2

              BodyCount = BodyFolder.GetBodyCount

          If BodyCount > 0 Then

              n = n + 1

              If n < 1000 Then

              num = "-" + Right(Str$(n), Len(Str$(n)) - 1)

              End If

              If n < 100 Then

              num = "-" + Right(Str$(n), Len(Str$(n)) - 1)

              End If

              If n < 10 Then

              num = "-0" + Right(Str$(n), Len(Str$(n)) - 1)

          End If

      End If

       

      If Right(doc.GetTitle, 7) = ".SLDPRT" Or Right(doc.GetTitle, 7) = ".SLDASM" Then

          f.Name = Left(doc.GetTitle, Len(doc.GetTitle) - 7) + num

      Else

          f.Name = Left(doc.GetTitle, Len(doc.GetTitle)) + num

      End If

          • Re: How can I rename Cutlist Folders
            Shaun Jalbert

            Yeah, I looked at that already.

            I'm just uncertain how you take that custom property and add the "sequential" number after it.

              • Re: How can I rename Cutlist Folders
                Adam Hoffman

                If the "num" value is the way you want it, then try this:

                 

                Dim swConfig As SldWorks.Configuration

                Dim sValue As String

                 

                Set swConfig = doc.GetActiveConfiguration

                sValue = ""

                sValue = GetCustomProp(doc, "WLD_MK_NO", swConfig)

                Debug.Print ("The Folder Name Is: " + sValue + num)

                f.Name = sValue + num

                 

                 

                 

                Function GetCustomProp(ByVal TheModel As SldWorks.ModelDoc2, ByVal sPropertyToGet As String, ByVal TheConfig As SldWorks.Configuration) As String

                Dim swCustPropMgr As SldWorks.CustomPropertyManager
                Dim iRet As Integer
                Dim sValOut As String
                Dim sResolved As String
                Dim bResolved As Boolean

                 

                GetCustomProp = ""

                 

                TheModel.ShowConfiguration2 TheConfig.Name

                 

                Set swCustPropMgr = TheConfig.CustomPropertyManager
                  
                iRet = swCustPropMgr.Get5(sPropertyToGet, True, sValOut, sResolved, bResolved)

                 

                If iRet = 2 Then
                  
                   GetCustomProp = sValOut
                  
                End If

                 

                End Function

                  • Re: How can I rename Cutlist Folders
                    Shaun Jalbert

                    Shoot... I buggered this up. I inserted into my script and ran, but I get a "Compile Error: Expected End Sub" at the start of the function you provided:

                    Function GetCustomProp(ByVal TheModel As SldWorks.ModelDoc2, ByVal sPropertyToGet As String, ByVal TheConfig As SldWorks.Configuration) As String

                     

                    Here's my whole script for reference.

                     

                    Option Explicit

                    Private Const propname1 As String = "Mass" ' change to "MASS" or whatever you prefer

                    Private Const propname2 As String = "Description"

                    Private Const propname3 As String = "Type"

                    Private Const propname4 As String = "StockSize"

                    Private Const propname5 As String = "Grade"

                    Private Const propname6 As String = "Length"

                    Private Const propname7 As String = "Mark"

                    Private Const propname8 As String = "PARTNUMBER"

                    Private Const propname9 As String = "Sheet Metal Thickness"

                    Private Const propname10 As String = "ANGLE1"

                    Private Const proptype As String = "Text" ' in english you must change to "Text". See comment in code…

                     

                     

                    Dim swApp As Object

                    Sub Main()

                     

                    Dim swApp As SldWorks.SldWorks

                    Set swApp = Application.SldWorks

                    Dim doc As SldWorks.ModelDoc2: Set doc = swApp.ActiveDoc

                    Dim partdoc As SldWorks.partdoc: Set partdoc = doc

                    Dim f As IFeature: Set f = doc.FirstFeature

                    Dim bRet As Boolean

                    Dim num As String

                    Dim n As Integer: n = 0

                    Dim modDocExt As SldWorks.ModelDocExtension

                    Dim BodyFolder As SldWorks.BodyFolder

                    Dim BodyCount As Long

                     

                    Do While Not f Is Nothing

                    If f.GetTypeName = "CutListFolder" Then

                            Set BodyFolder = f.GetSpecificFeature2

                            BodyCount = BodyFolder.GetBodyCount

                        If BodyCount > 0 Then

                            n = n + 1

                            If n < 1000 Then

                            num = "-" + Right(Str$(n), Len(Str$(n)) - 1)

                            End If

                            If n < 100 Then

                            num = "-" + Right(Str$(n), Len(Str$(n)) - 1)

                            End If

                            If n < 10 Then

                            num = "-0" + Right(Str$(n), Len(Str$(n)) - 1)

                        End If

                    End If

                     

                    Dim swConfig As SldWorks.Configuration

                    Dim sValue As String

                     

                    Set swConfig = doc.GetActiveConfiguration

                    sValue = ""

                    sValue = GetCustomProp(doc, "WLD_MK_NO", swConfig)

                    Debug.Print ("The Folder Name Is: " + sValue + num)

                    f.Name = sValue + num

                     

                     

                    Function GetCustomProp(ByVal TheModel As SldWorks.ModelDoc2, ByVal sPropertyToGet As String, ByVal TheConfig As SldWorks.Configuration) As String

                     

                    Dim swCustPropMgr As SldWorks.CustomPropertyManager

                    Dim iRet As Integer

                    Dim sValOut As String

                    Dim sResolved As String

                    Dim bResolved As Boolean

                     

                    GetCustomProp = ""

                    TheModel.ShowConfiguration2 TheConfig.Name

                    Set swCustPropMgr = TheConfig.CustomPropertyManager

                    iRet = swCustPropMgr.Get5(sPropertyToGet, True, sValOut, sResolved, bResolved)

                    If iRet = 2 Then

                       GetCustomProp = sValOut

                    End If

                     

                     

                    'add 3d bounding box

                       Set Part = swApp.ActiveDoc

                       Set modDocExt = Part.Extension

                       boolstatus = modDocExt.SelectByID2(f.Name, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)

                       modDocExt.Create3DBoundingBox

                      

                                

                                   

                                    'del Mark and PARTNUMBER

                                    bRet = f.CustomPropertyManager.Delete(propname7)

                                    bRet = f.CustomPropertyManager.Delete(propname8)

                                   

                                    'mass

                                    bRet = f.CustomPropertyManager.Delete(propname1)

                                    bRet = f.CustomPropertyManager.Add(propname1, proptype, Chr$(34) + "SW-Mass@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                     

                                   

                                    'type

                                    If f.CustomPropertyManager.Add(propname3, proptype, "PL") Then

                                    Debug.Print "Property "; propname3; " added to feature "; f.Name

                                    End If

                                   

                                   

                                    'Plate & Formed Plate stocksize and Length and desc

                                    If f.CustomPropertyManager.Get(propname10) = "" Then

                                       If f.CustomPropertyManager.Get(propname9) = "" Then

                                           bRet = f.CustomPropertyManager.Delete(propname4)

                                           bRet = f.CustomPropertyManager.Add(propname4, proptype, Chr$(34) + "PL" + "SW-3D-Bounding Box Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-3D-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                           bRet = f.CustomPropertyManager.Delete(propname6)

                                           bRet = f.CustomPropertyManager.Add(propname6, proptype, Chr$(34) + "SW-3D-Bounding Box Length@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                          

                                           'desc plate

                                           bRet = f.CustomPropertyManager.Delete(propname2)

                                           bRet = f.CustomPropertyManager.Add(propname2, proptype, "PLATE")

                       

                     

                                       Else

                                           bRet = f.CustomPropertyManager.Delete(propname4)

                                           bRet = f.CustomPropertyManager.Add(propname4, proptype, Chr$(34) + "PL" + "SW-Sheet Metal Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                       

                                           bRet = f.CustomPropertyManager.Delete(propname6)

                                           bRet = f.CustomPropertyManager.Add(propname6, proptype, Chr$(34) + "SW-Bounding Box Length@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                          

                                           'desc formed plate

                                           bRet = f.CustomPropertyManager.Delete(propname2)

                                           bRet = f.CustomPropertyManager.Add(propname2, proptype, "FORMED PLATE")

                                          

                     

                                       End If

                                    Else

                                    End If

                                  

                                    'grade

                                    If f.CustomPropertyManager.Add(propname5, proptype, Chr$(34) + "SW-Material@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) Then

                                    Debug.Print "Property "; propname5; " added to feature "; f.Name

                                    End If

                                                 

                     

                    End If

                    Set f = f.GetNextFeature

                    Loop

                    End Function

                      • Re: How can I rename Cutlist Folders
                        Ivana Kolin

                        insert

                         

                        Loop
                         
                        End Sub 
                        
                        

                        Before this line

                        Function GetCustomProp(ByVal TheModel As SldWorks.ModelDoc2, ByVal sPropertyToGet As String, ByVal TheConfig As SldWorks.Configuration) As String
                        
                        • Re: How can I rename Cutlist Folders
                          Adam Hoffman

                          Try it this way:

                           

                          Option Explicit

                          Private Const propname1 As String = "Mass" ' change to "MASS" or whatever you prefer

                          Private Const propname2 As String = "Description"

                          Private Const propname3 As String = "Type"

                          Private Const propname4 As String = "StockSize"

                          Private Const propname5 As String = "Grade"

                          Private Const propname6 As String = "Length"

                          Private Const propname7 As String = "Mark"

                          Private Const propname8 As String = "PARTNUMBER"

                          Private Const propname9 As String = "Sheet Metal Thickness"

                          Private Const propname10 As String = "ANGLE1"

                          Private Const proptype As String = "Text" ' in english you must change to "Text". See comment in code…

                           

                           

                          Dim swApp As Object

                          Sub Main()

                           

                          Dim swApp As SldWorks.SldWorks

                          Set swApp = Application.SldWorks

                          Dim doc As SldWorks.ModelDoc2: Set doc = swApp.ActiveDoc

                          Dim partdoc As SldWorks.partdoc: Set partdoc = doc

                          Dim f As IFeature: Set f = doc.FirstFeature

                          Dim bRet As Boolean

                          Dim num As String

                          Dim n As Integer: n = 0

                          Dim modDocExt As SldWorks.ModelDocExtension

                          Dim BodyFolder As SldWorks.BodyFolder

                          Dim BodyCount As Long

                           

                          Do While Not f Is Nothing

                          If f.GetTypeName = "CutListFolder" Then

                                  Set BodyFolder = f.GetSpecificFeature2

                                  BodyCount = BodyFolder.GetBodyCount

                              If BodyCount > 0 Then

                                  n = n + 1

                                  If n < 1000 Then

                                  num = "-" + Right(Str$(n), Len(Str$(n)) - 1)

                                  End If

                                  If n < 100 Then

                                  num = "-" + Right(Str$(n), Len(Str$(n)) - 1)

                                  End If

                                  If n < 10 Then

                                  num = "-0" + Right(Str$(n), Len(Str$(n)) - 1)

                              End If

                          End If

                           

                          Dim swConfig As SldWorks.Configuration

                          Dim sValue As String

                           

                          Set swConfig = doc.GetActiveConfiguration

                          sValue = ""

                          sValue = GetCustomProp(doc, "WLD_MK_NO", swConfig)

                          Debug.Print ("The Folder Name Is: " + sValue + num)

                          f.Name = sValue + num

                           

                          'add 3d bounding box

                            Set Part = swApp.ActiveDoc

                            Set modDocExt = Part.Extension

                            boolstatus = modDocExt.SelectByID2(f.Name, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)

                            modDocExt.Create3DBoundingBox

                           

                                     

                                         

                                          'del Mark and PARTNUMBER

                                          bRet = f.CustomPropertyManager.Delete(propname7)

                                          bRet = f.CustomPropertyManager.Delete(propname8)

                                         

                                          'mass

                                          bRet = f.CustomPropertyManager.Delete(propname1)

                                          bRet = f.CustomPropertyManager.Add(propname1, proptype, Chr$(34) + "SW-Mass@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                           

                                         

                                          'type

                                          If f.CustomPropertyManager.Add(propname3, proptype, "PL") Then

                                          Debug.Print "Property "; propname3; " added to feature "; f.Name

                                          End If

                                         

                                         

                                          'Plate & Formed Plate stocksize and Length and desc

                                          If f.CustomPropertyManager.Get(propname10) = "" Then

                                            If f.CustomPropertyManager.Get(propname9) = "" Then

                                                bRet = f.CustomPropertyManager.Delete(propname4)

                                                bRet = f.CustomPropertyManager.Add(propname4, proptype, Chr$(34) + "PL" + "SW-3D-Bounding Box Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-3D-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                                bRet = f.CustomPropertyManager.Delete(propname6)

                                                bRet = f.CustomPropertyManager.Add(propname6, proptype, Chr$(34) + "SW-3D-Bounding Box Length@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                               

                                                'desc plate

                                                bRet = f.CustomPropertyManager.Delete(propname2)

                                                bRet = f.CustomPropertyManager.Add(propname2, proptype, "PLATE")

                             

                           

                                            Else

                                                bRet = f.CustomPropertyManager.Delete(propname4)

                                                bRet = f.CustomPropertyManager.Add(propname4, proptype, Chr$(34) + "PL" + "SW-Sheet Metal Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                             

                                                bRet = f.CustomPropertyManager.Delete(propname6)

                                                bRet = f.CustomPropertyManager.Add(propname6, proptype, Chr$(34) + "SW-Bounding Box Length@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                               

                                                'desc formed plate

                                                bRet = f.CustomPropertyManager.Delete(propname2)

                                                bRet = f.CustomPropertyManager.Add(propname2, proptype, "FORMED PLATE")

                                               

                           

                                            End If

                                          Else

                                          End If

                                       

                                          'grade

                                          If f.CustomPropertyManager.Add(propname5, proptype, Chr$(34) + "SW-Material@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) Then

                                          Debug.Print "Property "; propname5; " added to feature "; f.Name

                                          End If

                                                       

                           

                          End If

                          Set f = f.GetNextFeature

                          Loop

                           

                          End Sub

                           

                          Function GetCustomProp(ByVal TheModel As SldWorks.ModelDoc2, ByVal sPropertyToGet As String, ByVal TheConfig As SldWorks.Configuration) As String

                           

                          Dim swCustPropMgr As SldWorks.CustomPropertyManager

                          Dim iRet As Integer

                          Dim sValOut As String

                          Dim sResolved As String

                          Dim bResolved As Boolean

                           

                          GetCustomProp = ""

                          TheModel.ShowConfiguration2 TheConfig.Name

                          Set swCustPropMgr = TheConfig.CustomPropertyManager

                          iRet = swCustPropMgr.Get5(sPropertyToGet, True, sValOut, sResolved, bResolved)

                          If iRet = 2 Then

                            GetCustomProp = sValOut

                          End If

                          End Function

                            • Re: How can I rename Cutlist Folders
                              Shaun Jalbert

                              Hi Adam:

                              The code runs (I missed declaring some dims so I fixed those), but it doesn't work as intended. It renames the folders to -01, -02, -03, etc... but seems to be missing the <WLD_MK_NO> property in front.

                               

                              Here's my current code again for reference.

                               

                              Option Explicit

                              Private Const propname1 As String = "Mass" ' change to "MASS" or whatever you prefer

                              Private Const propname2 As String = "Description"

                              Private Const propname3 As String = "Type"

                              Private Const propname4 As String = "StockSize"

                              Private Const propname5 As String = "Grade"

                              Private Const propname6 As String = "Length"

                              Private Const propname7 As String = "Mark"

                              Private Const propname8 As String = "PARTNUMBER"

                              Private Const propname9 As String = "Sheet Metal Thickness"

                              Private Const propname10 As String = "ANGLE1"

                              Private Const propname11 As String = "StockSize_Short"

                               

                              Private Const proptype As String = "Text" ' in english you must change to "Text". See comment in code…

                               

                               

                              Dim swApp As Object

                              Sub Main()

                              Dim swApp As SldWorks.SldWorks

                              Set swApp = Application.SldWorks

                              Dim doc As SldWorks.ModelDoc2: Set doc = swApp.ActiveDoc

                              Dim partdoc As SldWorks.partdoc: Set partdoc = doc

                              Dim f As IFeature: Set f = doc.FirstFeature

                              Dim bRet As Boolean

                              Dim n As Integer: n = 0

                              Dim num As String

                               

                              Dim modDocExt As SldWorks.ModelDocExtension

                               

                              Dim Part As Object

                              Dim boolstatus As Boolean

                               

                              Dim BodyFolder As SldWorks.BodyFolder

                              Dim BodyCount As Long

                               

                               

                              Do While Not f Is Nothing

                              If f.GetTypeName = "CutListFolder" Then

                                      Set BodyFolder = f.GetSpecificFeature2

                                      BodyCount = BodyFolder.GetBodyCount

                                  If BodyCount > 0 Then

                                      n = n + 1

                                      If n < 1000 Then

                                      num = "-" + Right(Str$(n), Len(Str$(n)) - 1)

                                      End If

                                      If n < 100 Then

                                      num = "-" + Right(Str$(n), Len(Str$(n)) - 1)

                                      End If

                                      If n < 10 Then

                                      num = "-0" + Right(Str$(n), Len(Str$(n)) - 1)

                                  End If

                              End If

                               

                              Dim swConfig As SldWorks.Configuration

                              Dim sValue As String

                               

                              Set swConfig = doc.GetActiveConfiguration

                              sValue = ""

                              sValue = GetCustomProp(doc, "WLD_MK_NO", swConfig)

                              Debug.Print ("The Folder Name Is: " + sValue + num)

                              f.Name = sValue + num

                               

                               

                              'add 3d bounding box

                                Set Part = swApp.ActiveDoc

                                Set modDocExt = Part.Extension

                                boolstatus = modDocExt.SelectByID2(f.Name, "SUBWELDFOLDER", 0, 0, 0, False, 0, Nothing, 0)

                                modDocExt.Create3DBoundingBox

                               

                                        

                                            

                                              'del Mark and PARTNUMBER

                                              bRet = f.CustomPropertyManager.Delete(propname7)

                                              bRet = f.CustomPropertyManager.Delete(propname8)

                                            

                                              'mass

                                              bRet = f.CustomPropertyManager.Delete(propname1)

                                              bRet = f.CustomPropertyManager.Add(propname1, proptype, Chr$(34) + "SW-Mass@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                              'bRet = f.CustomPropertyManager.Add(propname1, proptype, Chr$(34) + "SW-Mass@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + " kg")

                                              'If f.CustomPropertyManager.Add(propname1, proptype, Chr$(34) + "SW-Mass@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "kg") Then

                                              'Debug.Print "Property "; propname1; " added to feature "; f.Name

                                              'End If

                                            

                                              'desc

                                              'If f.CustomPropertyManager.Add(propname2, proptype, "PLATE") Then

                                              'Debug.Print "Property "; propname2; " added to feature "; f.Name

                                              'End If

                                            

                                              'type

                                              If f.CustomPropertyManager.Add(propname3, proptype, "PL") Then

                                              Debug.Print "Property "; propname3; " added to feature "; f.Name

                                              End If

                                            

                                            

                                              'Plate & Formed Plate stocksize and Length and desc

                                              If f.CustomPropertyManager.Get(propname10) = "" Then

                                                If f.CustomPropertyManager.Get(propname9) = "" Then

                                                    bRet = f.CustomPropertyManager.Delete(propname4)

                                                    bRet = f.CustomPropertyManager.Add(propname4, proptype, Chr$(34) + "PL" + "SW-3D-Bounding Box Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-3D-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                                    bRet = f.CustomPropertyManager.Add(propname11, proptype, Chr$(34) + "PL" + "SW-3D-Bounding Box Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                                    bRet = f.CustomPropertyManager.Delete(propname6)

                                                    bRet = f.CustomPropertyManager.Add(propname6, proptype, Chr$(34) + "SW-3D-Bounding Box Length@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                                  

                                                    'desc plate

                                                    bRet = f.CustomPropertyManager.Delete(propname2)

                                                    bRet = f.CustomPropertyManager.Add(propname2, proptype, "PLATE")

                                

                                                    'If f.CustomPropertyManager.Add(propname4, proptype, Chr$(34) + "SW-3D-Bounding Box Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-3D-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) Then

                                                    'Debug.Print "Property "; propname4; " added to feature "; f.Name

                                                    'End If

                                                Else

                                                    bRet = f.CustomPropertyManager.Delete(propname4)

                                                    bRet = f.CustomPropertyManager.Add(propname4, proptype, Chr$(34) + "PL" + "SW-Sheet Metal Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                                    bRet = f.CustomPropertyManager.Add(propname11, proptype, Chr$(34) + "PL" + "SW-Sheet Metal Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                

                                                    bRet = f.CustomPropertyManager.Delete(propname6)

                                                    bRet = f.CustomPropertyManager.Add(propname6, proptype, Chr$(34) + "SW-Bounding Box Length@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34))

                                                  

                                                    'desc formed plate

                                                    bRet = f.CustomPropertyManager.Delete(propname2)

                                                    bRet = f.CustomPropertyManager.Add(propname2, proptype, "FORMED PLATE")

                                                  

                                                    'If f.CustomPropertyManager.Add(propname4, proptype, Chr$(34) + "SW-Sheet Metal Thickness@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34) + "x" + Chr(34) + "SW-Bounding Box Width@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) Then

                                                    'Debug.Print "Property "; propname4; " added to feature "; f.Name

                                                    'End If

                                                End If

                                              Else

                                              End If

                                          

                                              'grade

                                              If f.CustomPropertyManager.Add(propname5, proptype, Chr$(34) + "SW-Material@@@" + f.Name + "@" + doc.GetTitle + ".SLDPRT" + Chr(34)) Then

                                              Debug.Print "Property "; propname5; " added to feature "; f.Name

                                              End If

                                                          

                               

                               

                              End If

                              Set f = f.GetNextFeature

                              Loop

                              End Sub

                               

                              Function GetCustomProp(ByVal TheModel As SldWorks.ModelDoc2, ByVal sPropertyToGet As String, ByVal TheConfig As SldWorks.Configuration) As String

                               

                              Dim swCustPropMgr As SldWorks.CustomPropertyManager

                              Dim iRet As Integer

                              Dim sValOut As String

                              Dim sResolved As String

                              Dim bResolved As Boolean

                               

                              GetCustomProp = ""

                              TheModel.ShowConfiguration2 TheConfig.Name

                              Set swCustPropMgr = TheConfig.CustomPropertyManager

                              iRet = swCustPropMgr.Get5(sPropertyToGet, True, sValOut, sResolved, bResolved)

                              If iRet = 2 Then

                                GetCustomProp = sValOut

                              End If

                              End Function

                    • Re: How can I rename Cutlist Folders
                      Stephen Welty

                      I would like to use the original macro of this post for renaming the multibody cutlist folders with filename-P1.  I tried modifying the macro in the original post but it locks up my system.   Could I get some help getting it to work. 

                       

                      Sub Main()

                      Dim swApp As SldWorks.SldWorks

                      Set swApp = Application.SldWorks

                      Dim doc As SldWorks.ModelDoc2: Set doc = swApp.ActiveDoc

                      Dim partdoc As SldWorks.partdoc: Set partdoc = doc

                      Dim f As IFeature: Set f = doc.FirstFeature

                      Dim bRet As Boolean

                      Dim n As Integer: n = 0

                      Dim num As String

                      Dim modDocExt As SldWorks.ModelDocExtension

                      Dim Part As Object

                      Dim boolstatus As Boolean

                      Dim BodyFolder As SldWorks.BodyFolder

                      Dim BodyCount As Long

                       

                      Do While Not f Is Nothing

                      If f.GetTypeName = "CutListFolder" Then

                              Set BodyFolder = f.GetSpecificFeature2

                              BodyCount = BodyFolder.GetBodyCount

                          If BodyCount > 0 Then

                              n = n + 1

                              If n < 1000 Then

                              num = "-P" + Right(Str$(n), Len(Str$(n)) - 1)

                              End If

                              If n < 100 Then

                              num = "-P" + Right(Str$(n), Len(Str$(n)) - 1)

                              End If

                              If n < 10 Then

                              num = "-P" + Right(Str$(n), Len(Str$(n)) - 1)

                              End If

                          End If

                      End If

                       

                      If Right(doc.GetTitle, 7) = ".SLDPRT" Or Right(doc.GetTitle, 7) = ".SLDASM" Then

                          f.Name = Left(doc.GetTitle, Len(doc.GetTitle) - 7) + num

                      Else

                          f.Name = Left(doc.GetTitle, Len(doc.GetTitle)) + num

                      End If

                      Loop

                      End Sub