2 Replies Latest reply on Oct 8, 2013 6:12 AM by Yong Ning

    Vertical Ordinate Dimensions → with API

    Yong Ning
      1. With a drawing or sketch active, click Vertical Ordinate Dimension on the Dimensions/Relations toolbar, or click Tools, Dimensions, Vertical Ordinate.
        • Re: Vertical Ordinate Dimensions → with API
          Deepak Gupta

          swModel.InsertVerticalOrdinate

            • Re: Vertical Ordinate Dimensions → with API
              Yong Ning

              Thanks your tips 

              swModel.InsertVerticalOrdinate → result is

               

               

              1.jpg

               

              The code is

               

              ' ******************************************************************************
              ' C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\swx392\Macro1.swb - macro recorded on 10/03/13 by Administrator
              ' ******************************************************************************
              Dim swApp As Object
              Dim Part As Object
              Dim SelMgr As Object
              Dim boolstatus As Boolean
              Dim longstatus As Long, longwarnings As Long
              Dim Feature As Object
              Sub main()

              Set swApp = Application.SldWorks

              Set Part = swApp.ActiveDoc
              Set SelMgr = Part.SelectionManager
              Part.InsertVerticalOrdinate
              Part.ClearSelection2 True
              boolstatus = Part.ActivateView("工程视图3")
              boolstatus = Part.Extension.SelectByID2("Line17", "SKETCHSEGMENT", 0.1601071431138, 0.1349123990804, 0, False, 0, Nothing, 0)
              Set Annotation = Part.AddDimension2(0.140856, 0.135329, -7.45171E-16)
              Part.ClearSelection2 True
              boolstatus = Part.Extension.SelectByID2("Point30", "SKETCHPOINT", -0.08812260999259, -0.1020879148938, 0, False, 0, Nothing, 0)
              Set Annotation = Part.AddDimension2(0.161885, 0.14615, -7.45171E-16)
              Part.ClearSelection2 True
              boolstatus = Part.Extension.SelectByID2("Point35", "SKETCHPOINT", -0.07145594819719, -0.08197982673322, 0, False, 0, Nothing, 0)
              Set Annotation = Part.AddDimension2(0.165254, 0.15105, -7.45171E-16)
              Part.ClearSelection2 True
              boolstatus = Part.Extension.SelectByID2("Point36", "SKETCHPOINT", -0.05478928640178, -0.06493782135757, 0, False, 0, Nothing, 0)
              Set Annotation = Part.AddDimension2(0.168623, 0.154113, -7.45171E-16)
              Part.ClearSelection2 True
              boolstatus = Part.Extension.SelectByID2("Point37", "SKETCHPOINT", -0.03812262460637, -0.05204405868885, 0, False, 0, Nothing, 0)
              Set Annotation = Part.AddDimension2(0.171889, 0.15646, -7.45171E-16)
              Part.ClearSelection2 True
              boolstatus = Part.Extension.SelectByID2("Point38", "SKETCHPOINT", -0.02145596281096, -0.04345182913557, 0, False, 0, Nothing, 0)
              Set Annotation = Part.AddDimension2(0.175156, 0.1584, -7.45171E-16)
              Part.ClearSelection2 True
              boolstatus = Part.Extension.SelectByID2("Point39", "SKETCHPOINT", -0.004789301015546, -0.04033917396553, 0, False, 0, Nothing, 0)
              Set Annotation = Part.AddDimension2(0.178525, 0.159013, -7.45171E-16)
              Part.ClearSelection2 True
              Part.Save2 False
              boolstatus = Part.Extension.SelectByID2("图纸1", "SHEET", 0.2215858012411, 0.1787850418991, 0, False, 0, Nothing, 0)
              End Sub

              ****************************

              'Add Ordinate Dimension Example (VB)
              'This example shows how to add an ordinate dimension.

              '------------------------------------------
              '
              ' Preconditions:
              '          1) Drawing document is open.
              '          2) Two horizontal parallel edges are selected.
              '
              ' Postconditions: Ordinate dimension added.
              '
              '-------------------------------------------
              Option Explicit
              Public Enum swAddOrdinateDims_e
                  swOrdinate = 1
                  swVerticalOrdinate = 2
                  swHorizontalOrdinate = 3
              End Enum
              Public Enum swCreateOrdDimError_e
                  swCreateOrdDimErr_Undefined = -1            '  If encountered, report as SPR.
                  swCreateOrdDimErr_Success = 0
                  swCreateOrdDimErr_GenFailure = 1            '  MSG_SDIM_BAD_DIM
                  swCreateOrdDimErr_GenNoInternalDims = 2     '  MSG_NO_INTERNAL_DIMS_IN_DSKETCH
                  swCreateOrdDimErr_GenBadSel = 3             '  MSG_DIM_REF_NOCREATE
                  swCreateOrdDimErr_GenNeedModelLoaded = 4    '  MSG_CANNOT_DIM_GHOST_IN3D
                  swCreateOrdDimErr_GenSamePartOnly = 5       '  MSG_DIM_EDIT_PART
                  swCreateOrdDimErr_GenExtraSelection = 6     '  MSG_DIM_TOO_MANY_SELECT
                  swCreateOrdDimErr_OrdFailure = 7            '  MSG_BAD_ORDINATE_DIM0
                  swCreateOrdDimErr_OrdDupInGroup = 8         '  MSG_BAD_ORDINATE_DIM1
                  swCreateOrdDimErr_OrdBadDir = 9             '  MSG_BAD_ORDINATE_DIM2
              End Enum
              Sub main()
                  Dim swApp                   As SldWorks.SldWorks
                  Dim swModel                 As SldWorks.ModelDoc
                  Dim swDraw                  As SldWorks.DrawingDoc
                  Dim nRetval                 As Long
                 
                  Set swApp = Application.SldWorks
                  Set swModel = swApp.ActiveDoc
                  Set swDraw = swModel
                 
                  ' Horizontal ordinate ignores X placement
                  nRetval = swDraw.AddOrdinateDimension2(swHorizontalOrdinate, -0.1, 0.02, 0#)
                 
              End Sub
              '------------------------------------------


              3.jpg

              *****************************

              See attatch