1 Reply Latest reply on Jul 24, 2017 5:44 PM by Nilesh Patel

    How to change the layer of Annotations using API?

    Arun Ariyapattan

      Hi all,

       

      Below is the code for Changing Layer of dimensions using API.I tried to tweak the below code so that I can create a code for changing the layer of annotations.But, all my trials were failure.As I am new to API, I cant understand its flow and root. Please help me in tweaking  for changing layer of annotations.

       

      Const ToLayer               As String = "FORMAT"

      Sub main()
          Dim swApp                   As SldWorks.SldWorks
          Dim swModel                 As SldWorks.ModelDoc2
          Dim swDraw                  As SldWorks.DrawingDoc
          Dim swView                  As SldWorks.View
          Dim swAnn                   As SldWorks.Annotation
          Dim swDispDim               As SldWorks.DisplayDimension
          Dim NumShts                 As Long
          Dim i                       As Long
         
          Set swApp = CreateObject("SldWorks.Application")
          Set swModel = swApp.ActiveDoc
          Set swDraw = swModel
         
          NumShts = swDraw.GetSheetCount
          For i = 1 To NumShts
              swDraw.SheetPrevious
          Next i
         
          For i = 1 To NumShts
              Set swView = swDraw.GetFirstView
              While Not swView Is Nothing
                  Set swDispDim = swView.GetFirstDisplayDimension5
                  While Not swDispDim Is Nothing
                      Set swAnn = swDispDim.GetAnnotation
                     
                      swAnn.Layer = ToLayer
                      Debug.Print "Layer is " & swAnn.Layer
                     
                      Set swDispDim = swDispDim.GetNext5
                  Wend
                 
                  Set swView = swView.GetNextView
              Wend
             
              swDraw.SheetNext
          Next i
      End Sub

       

      Thanks,

      Arun. A