AnsweredAssumed Answered

Macro to autoname sheets based on Custom Property

Question asked by Steve Mlynczak on Aug 21, 2015
Latest reply on Aug 26, 2015 by John Stoltzfus

I have this code below that works on a single sheet. It grabs the the custom property named "Description" from the inserted model and the sheet size and renames the sheet according to that data The problem is when I add another sheet to the file the macro quits working. Will someone take a look and see what I have messed up. I cant get passed this issue. The problem code I think is highlighted in bold letter below



Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swDraw As SldWorks.DrawingDoc

Dim swSheet As SldWorks.Sheet

Dim swModelview2 As Configuration

Dim ConfigName As String

Dim vSheets As Variant

Dim swView As SldWorks.View

Dim i As Integer

Dim Part As SldWorks.ModelDoc2

Dim Count As String

Dim SheetProperties As Variant

Dim paperSize As swDwgPaperSizes_e

Dim width As Double

Dim height As Double

Dim sheetsize As String

Dim CP As String

Dim resolvedValOut  As String

Dim swCustProp      As CustomPropertyManager



Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swDraw = swApp.ActiveDoc

Set swApp = GetObject("", "SldWorks.Application")

Set Part = swApp.ActiveDoc



vSheets = swModel.GetSheetNames

For i = 1 To swModel.GetSheetCount

swModel.ActivateSheet vSheets(i - 1)

Set swSheet = swModel.GetCurrentSheet

Count = swModel.GetModelViewCount

Set swView = swModel.GetFirstView






Set swView = swDraw.GetFirstView

Set swView = swView.GetNextView

Set swModel = swView.ReferencedDocument

Set Sheet = swApp.ActiveDoc.GetCurrentSheet



Set swCustProp = swModel.Extension.CustomPropertyManager("")

swCustProp.Get2 "Description", CP, resolvedValOut

'MsgBox CP



'************ Determine Sheet Size *********************


    SheetProperties = swSheet.GetProperties

    paperSize = swSheet.GetSize(width, height)

    If paperSize = 0 Or paperSize = 1 Then

            sheetsize = "a"

        ElseIf paperSize = 2 Then

            sheetsize = "b"

        ElseIf paperSize = 3 Then

            sheetsize = "c"

        ElseIf paperSize = 4 Then

            sheetsize = "d"

        ElseIf paperSize = 5 Then

            sheetsize = "e"


        sheetsize = "d"

    End If

Do While Not swView Is Nothing

ConfigName = swView.ReferencedConfiguration

Set swView = swView.GetNextView


swSheet.SetName i & sheetsize & " - " & CP

Next i

End Sub