4 Replies Latest reply on Sep 4, 2017 10:36 PM by Frank Wu Frank Wu

    Can not use api InsertModelAnnotations3 function!

    Frank Wu Frank Wu

      Hi,Hello everyone!

       

      When I use the InsertModelAnnotations3 function to mark dimensions, I can not select the specified Cpmponent.

      Can someone help me?

       

      my code:

       

      Dim swApp As Object

      Dim Part As Object

      Dim boolstatus As Boolean

      Dim longstatus As Long, longwarnings As Long

       

      Sub main()

      Set swApp = Application.SldWorks

       

      Set Part = swApp.ActiveDoc

      boolstatus = Part.ActivateView("Drawing View2")

      boolstatus = Part.Extension.SelectByID2("Drawing View2", "DRAWINGVIEW", 0.515566647479853, 0.531855229830506, 0, False, 0, Nothing, 0)

      Part.SetPickMode

      Part.ClearSelection2 True

      boolstatus = Part.Extension.SelectByID2("Drawing View2", "DRAWINGVIEW", 0.490790813744565, 0.534608100245538, 0, True, 0, Nothing, 0)

       

      boolstatus = Part.Extension.SelectByID2("handle-SectionAssembly-1-1@/handle-1@handle-SectionAssembly-1/Knob-1@handle", "COMPONENT", 0.354523728200479, 0.504326525682979, 400.008, False, 0, Nothing, 0)

      boolstatus = Part.Extension.SelectByID2("handle-SectionAssembly-1-1@/handle-1@handle-SectionAssembly-1/Handle Rod-1@handle", "COMPONENT", 0.335253635295255, 0.43825763572221, 400.008, False, 0, Nothing, 0)

      boolstatus = Part.Extension.SelectByID2("handle-SectionAssembly-1-1@/handle-1@handle-SectionAssembly-1/Connector-1@handle", "COMPONENT", 0.942261561809817, 0.434128330099662, 400.003673334144, False, 0, Nothing, 0)

       

      Dim vAnnotations As Variant

      vAnnotations = Part.InsertModelAnnotations3(2, 32776, False, True, False, True)

      End Sub

        • Re: Can not use api InsertModelAnnotations3 function!
          Manikandan Babu

          Hi WU,

           

          Lets try this code.

           

          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swModelDocExt As SldWorks.ModelDocExtension

          Dim swDrawing As SldWorks.DrawingDoc

          Dim swSelmgr As SldWorks.SelectionMgr

          Dim swView As SldWorks.View

          Dim annotations As Variant

          Dim status As Boolean

          Dim swRootDrawComp As SldWorks.DrawingComponent

          Dim vDrawChildCompArr As Variant

          Dim vDrawChildComp        As Variant

          Dim swDrawComp As SldWorks.DrawingComponent

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swDrawing = swModel

              Set swModelDocExt = swModel.Extension

              Set swSelmgr = swModel.SelectionManager

              ' Select and activate the view

              status = swModelDocExt.SelectByID2("Drawing View2", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)

              status = swDrawing.ActivateView("Drawing View2")

              Set swView = swSelmgr.GetSelectedObject6(1, -1)

              swModel.ClearSelection2 True

              Set swRootDrawComp = swView.RootDrawingComponent

              vDrawChildCompArr = swRootDrawComp.GetChildren

              status = swModelDocExt.SelectByID2("Drawing View2", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)

              For Each vDrawChildComp In vDrawChildCompArr

              Set swDrawComp = vDrawChildComp

              If swDrawComp.Name <> "handle-SectionAssembly-1-1/Marble Handle-1" Then

              swDrawComp.Select True, Nothing

              End If

              Next

              ' Insert the annotations marked for the drawing

              annotations = swDrawing.InsertModelAnnotations3(2, 32776, False, True, False, True)

          End Sub

           

           

          Manikandan