2 Replies Latest reply on Jun 2, 2017 5:51 AM by Yong Ning


    Yong Ning

      follow code, create sketchpoint is x=50,y=20


      Help me, point coordinate is   x=25,y = 10






      Private Sub del20170601()

          Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

              Set SwApp = Application.SldWorks

              Set SwModel = SwApp.ActiveDoc

          Dim SwDraw As DrawingDoc

              Set SwDraw = SwModel

          Dim Xx, Yy


          Dim SwSelMgr As SelectionMgr

              Set SwSelMgr = SwModel.SelectionManager


          Dim SwDim As Dimension

          Dim SwDispDim As DisplayDimension, SwAnn As Annotation

          Dim vEntArr, vEntTypeArr

          Dim SkPt As SketchPoint


              Set SwDispDim = SwSelMgr.GetSelectedObject5(1)

              If Not SwDispDim Is Nothing Then

                   Set SwAnn = SwDispDim.GetAnnotation

                   vEntArr = SwAnn.GetAttachedEntities

                   vEntTypeArr = SwAnn.GetAttachedEntityTypes


                      For jj = 0 To UBound(vEntTypeArr)

                              Set SwPt = vEntArr(jj)

                              With SwPt

                                  Xx = .X

                                  Yy = .Y

                                  Set SkPt = SwModel.CreatePoint2(Xx, Yy, 0)'????????

                              End With

                      Next jj

               End If


      End Sub

        • Re: GetAttachedEntities
          Scott Stuart

          Just a guess, but do you have to factor in the view scale?

          • Re: GetAttachedEntities
            Yong Ning

            Dim SwApp                   As SldWorks.SldWorks

            Dim SwModel                 As SldWorks.ModelDoc2

            Dim SwDraw                  As SldWorks.DrawingDoc

            Dim SwView                  As SldWorks.View

            Dim SwDispDim               As SldWorks.DisplayDimension

            Dim SwDim                   As SldWorks.Dimension

            Dim SwAnn                   As SldWorks.Annotation

            Dim swDisplayDimension      As SldWorks.DisplayDimension


            Sub main()

                Set SwApp = Application.SldWorks

                Set SwModel = SwApp.ActiveDoc

                Set SwDraw = SwModel

                Set SwView = SwDraw.GetFirstView

                While Not SwView Is Nothing

                    Set SwAnn = SwView.GetFirstAnnotation3

                    While Not SwAnn Is Nothing

                        Debug.Print " "

                        Debug.Print "Annotation name = " & SwAnn.GetName

                        If SwAnn.GetType = swAnnotationType_e.swDisplayDimension Then

                            Debug.Print "  Is a display dimension? True"

                            Set swDisplayDimension = SwAnn.GetSpecificAnnotation

                            Select Case (swDisplayDimension.Type2)

                               Case swDimensionType_e.swOrdinateDimension

            Debug.Print "  Display dimension type = " & GetOrientation(swDisplayDimension) & " ordinate and its subordinates"

                               Case swDimensionType_e.swLinearDimension

            Debug.Print "  Display dimension type = " & GetOrientation(swDisplayDimension) & " linear"

                               Case swDimensionType_e.swAngularDimension

            Debug.Print "  Display dimension type  = angular"

                               Case swDimensionType_e.swArcLengthDimension

            Debug.Print "  Display dimension type = arc length"

                               Case swDimensionType_e.swRadialDimension

            Debug.Print "  Display dimension type = radial"

                               Case swDimensionType_e.swDiameterDimension

            Debug.Print "  Display dimension type = diameter"

                               Case swDimensionType_e.swHorOrdinateDimension

            Debug.Print "  Display dimension type = horizontal ordinate"

                               Case swDimensionType_e.swVertOrdinateDimension

            Debug.Print "  Display dimension type = vertical ordinate"

                               Case swDimensionType_e.swZAxisDimension

            Debug.Print "  Display dimension type = z-axis"

                               Case swDimensionType_e.swChamferDimension

            Debug.Print "  Display dimension type = chamfer dimension"

                               Case swDimensionType_e.swHorLinearDimension

            Debug.Print "  Display dimension type = horizontal linear"

                               Case swDimensionType_e.swVertLinearDimension

            Debug.Print "  Display dimension type = vertical linear"

                               Case swDimensionType_e.swScalarDimension

            Debug.Print "  Display dimension type = scalar"

                               Case Else

            Debug.Print "  Display dimension type = unknown"

                            End Select

                        End If

                        Set SwAnn = SwAnn.GetNext3


                    Set SwView = SwView.GetNextView


            End Sub


            Function GetOrientation(swDisplayDimension As DisplayDimension) As String

                Dim SwDim As SldWorks.Dimension

                Set SwDim = swDisplayDimension.GetDimension '2(0)

                Dim swMathVec As SldWorks.MathVector

                Dim vDir As Variant


                GetOrientation = ""


                Set swMathVec = SwDim.DimensionLineDirection

                vDir = swMathVec.ArrayData


                If IsCollinear(vDir(0), 1) And IsCollinear(vDir(1), 0) Then

                    GetOrientation = "horizontal"

                ElseIf IsCollinear(vDir(1), 1) And IsCollinear(vDir(0), 0) Then

                    GetOrientation = "vertical"

                End If

            End Function


            Function IsCollinear(val As Variant, vector As Double) As Boolean

                Const TOL = 0.00000001

                IsCollinear = Abs(Abs(val) - Abs(vector)) < TOL

            End Function



            How to determine the vertical size, or horizont... | SOLIDWORKS Forums  https://forum.solidworks.com/message/721529