AnsweredAssumed Answered

Traverse multiple drawing sheets and create views of different parts

Question asked by A. T. on Dec 14, 2015
Latest reply on Dec 16, 2015 by Amen Allah Jlili

Hello, I was wondering if anyone could help me with this. I have an assembly that comprises of 12 parts. I am trying to build a macro that would create 12 sheets in one drawing and then create a standard 3 view of each part, in the corresponding sheet. So far I have managed to create the sheets with a simple loop and then traverse each sheet. What I cannot understand is how to get the name of each part in order to create the views. The 12 sheets are named Part1, Part2,..., Part12. The parts though, don't follow the same name pattern.

 

Dim swapp As SldWorks.SldWorks

Dim swmodel As SldWorks.ModelDoc2

Dim swDraw As SldWorks.DrawingDoc

Dim TemplateName As String

 

Sub main()

Set swapp = Application.SldWorks

Set swmodel = swapp.ActiveDoc

TemplateName = "C:\Templates\Drawing.DRWDOT"

Set swDraw = swapp.NewDocument(TemplateName, swDwgPaperA3size, 0, 0)

Dim retval As Boolean

 

' Loop for creating multiple Sheets

Dim i As Integer

Dim SheetName As Variant

'Dim PartName As Variant

'PartName = "C:\MyParts\Upper_Link.SLDPRT"  ' Example name of a part

 

For i = 1 To 12

SheetName = "Part" & i

swDraw.NewSheet3 SheetName, swDwgPaperA3size, swDwgTemplateA3size, 1, 5, False, "", 0, 0, ""

Next i

 

For i = 1 To 12

swDraw.ActivateSheet ("Part" & i)

'retval = swDraw.Create3rdAngleViews2(PartName)   ' Creates views of the same part to all 12 sheets

Next i

 

End Sub

Outcomes