AnsweredAssumed Answered

How can I rename Cutlist Folders

Question asked by Shaun Jalbert on Jun 12, 2015
Latest reply on Jan 19, 2017 by Arif Akbas

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

Outcomes