32 Replies Latest reply on Oct 23, 2018 11:24 AM by Ben Langdon

    Macro to Load Dimension Styles

    Ben Langdon

      So i want to make a macro that will load the styles i have already made for dimensions. i know its just a couple clicks to imput them into a new drawing, but i would like to have it load them in with a shortcut just so i don't have to do the same thing all the time when opening old documents that i need to load them into.


      I tried recording it but it didn't take down any of the things i did so i don't really have anything to start off of

        • Re: Macro to Load Dimension Styles
          Deepak Gupta

          I think you need to use LoadStyle method.

          • Re: Macro to Load Dimension Styles
            Gennadiy Tsybikov

            Use IAnnotation::LoadStyle method. You have to first access IAnnotation Interface and then use LoadStyle method.

            I created a macro that Loads Style for dimensions. Just assign strPathName to your template path and try if it works for you. See below:


            Sub main()

                Dim swApp As SldWorks.SldWorks

                Dim swModel As SldWorks.ModelDoc2

                Dim swDrawDoc As SldWorks.DrawingDoc

                Dim swAnnot As SldWorks.Annotation

                Dim swSheet As SldWorks.Sheet

                Dim swView As SldWorks.View

                Dim vViews As Variant

                Dim vAnnots As Variant

                Dim intAnnotCount As Integer

                Dim strSheetNames() As String

                Dim intSheetCount As Integer

                Dim strPathName As String

                Dim i As Integer

                Dim j As Integer

                Dim k As Integer


                strPathName = "C:\..."


                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc

                Set swDrawDoc = swModel

                intSheetCount = swDrawDoc.GetSheetCount

                ReDim strSheetNames(1 To intSheetCount) As String

                strSheetNames = swDrawDoc.GetSheetNames


                For i = 0 To intSheetCount - 1

                    Set swSheet = swDrawDoc.Sheet(strSheetNames(i))

                    vViews = swSheet.GetViews


                    For j = 0 To UBound(vViews)

                        Set swView = vViews(j)

                        vAnnots = swView.GetAnnotations

                        intAnnotCount = swView.GetAnnotationCount


                        If intAnnotCount > 0 Then

                            For k = 0 To UBound(vAnnots)

                                Set swAnnot = vAnnots(k)

                                swAnnot.LoadStyle (strPathName)

                            Next k

                        End If

                    Next j

                Next i


            End Sub