AnsweredAssumed Answered

Insert Auto Arrange Dimensions Macro?

Question asked by Zak Craig on Oct 30, 2014
Latest reply on Oct 30, 2014 by John Kangas

Hi everyone,

 

I'm currently working with a macro that is going to automatically generate drawings for me based on configurations, but the dimensions are giving me a hard time. Since the parts in the configurations vary widely in size, the dimensions in the drawings are flying all over the place and in many cases off of the sheet.

 

I want to insert an Auto Arrange Dimensions command in my macro, but I can't seem to find a way to do it. I'm new to macros and the one that I'm using was found on the forums here somewhere.

 

Here's the macro:

 

Dim swApp As SldWorks.SldWorks

Dim swModel As ModelDoc2

Dim swDrawing As DrawingDoc

Dim configMgr As ConfigurationManager

Dim configs() As String

Dim lErrors As Long, lWarnings As Long

 

Sub main()

 

' MAKE SURE YOU CHANGE THE swDocASSEMBLY 4 lines below to swDocPART if you are opening a part not assembly

Dim modelLocation As String: modelLocation = "C:\Users\user\Desktop\Macro Testing\Ball Nose.sldprt"

Dim drawingLocation As String: drawingLocation = "C:\Users\user\Desktop\Macro Testing\Drawings\Ball Nose.SLDDRW"

Dim outputLocation As String: outputLocation = "C:\Users\user\Desktop\Macro Testing\Drawings\Output\"

 

Set swApp = Application.SldWorks

 

' Start by opening the files and just presume they open fine else this is a pointless excercise anyway

Set swModel = swApp.OpenDoc6(modelLocation, swDocPART, 0, "", lErrors, lWarnings)

Set swDrawing = swApp.OpenDoc6(drawingLocation, swDocDRAWING, 0, "", lErrors, lWarnings)

 

' Get all configuration names for this document

configs = swModel.GetConfigurationNames()

 

' Loop them all

For i = 0 To swModel.GetConfigurationCount() - 1

    ' Activate configuration

    If swModel.ShowConfiguration2(configs(i)) Then

        ' Successfully activated configuration so update model

      '   swModel.ForceRebuild3 True

      

        ' Now make sure we have the drawing active and update that

        swApp.ActivateDoc2 drawingLocation, True, lErrors

      

        ' Loop all views and re-reference them

        Dim view As view

        Set view = swDrawing.GetFirstView

        ' Skip first view which is the sheet

               

        Set view = view.GetNextView

      

        While Not view Is Nothing

            view.ReferencedConfiguration = configs(i)

           

            view.UseSheetScale = False

            view.ScaleDecimal = 2  ' 2 = 2:1   0.2 = 1:5 etc... so set it here however you want based on config name which is in configs(i)

            Set view = view.GetNextView

        Wend

            

        ' Update sheet

        swModel.ForceRebuild3 True

        swDrawing.ForceRebuild

      

        ' And save out the drawing

        swDrawing.Extension.SaveAs outputLocation & configs(i) & ".pdf", 0, 0, Nothing, lErrors, lWarnings

      

    End If

  

Next

 

End Sub

 

Where and how could I insert an Auto Arrange Dimensions command?

Outcomes