0 Replies Latest reply on Jun 5, 2017 12:15 AM by Yong Ning

    GetSelectedObject5 dimension→why create point in view?

    Yong Ning

      Follow code, don't select dimension ,result is true

               tmp = SwModel.Extension.SelectByID2(Str, "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

               Set SwDispDim = SwSelMgr.GetSelectedObject5(

      but selection dimension, result is False.

               Set SwDispDim = SwSelMgr.GetSelectedObject5(1)

       

       

      transform1.jpg

       

       

       

      ''

      ''

      Private Sub l4()

           Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

               Set SwApp = Application.SldWorks

               Set SwModel = SwApp.ActiveDoc

           Dim SwMathUtil As MathUtility

               Set SwMathUtil = SwApp.GetMathUtility

           Dim SwSelMgr As SelectionMgr

               Set SwSelMgr = SwModel.SelectionManager

           Dim SwDraw As DrawingDoc

               Set SwDraw = SwModel

           Dim SwView As View

           Dim SwDispDim As DisplayDimension, SwDim As Dimension

           Dim SwViewXForm As MathTransform

             

           Dim MathPt As MathPoint, SkPt As SketchPoint

               Set SwView = SwDraw.GetFirstView

               Set SwView = SwView.GetNextView

             

           Dim Pp(2) As Double

               Pp(0) = 0.1

               Pp(1) = 0.1

               SwView.Position = Pp

           Dim oScale, Ss, Str

               oScale = 1 / SwView.ScaleDecimal

               Str = "H@Sketch@封头.Part"

               Str = Str & "@" & SwView.Name

               ''

               tmp = SwModel.Extension.SelectByID2(Str, "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

               Set SwDispDim = SwSelMgr.GetSelectedObject5(1)

               Set SwDim = SwDispDim.GetDimension

               Debug.Print SwDim.FullName

               Ss = SwDim.ReferencePoints

               Set SwViewXForm = SwView.ModelToViewTransform

               For jj = 0 To 2

                     Set MathPt = Ss(jj)

                     Set MathPt = MathPt.MultiplyTransform(SwViewXForm)

                     With MathPt

                               Debug.Print .ArrayData(0) * oScale, .ArrayData(1) * oScale, 0

                               'Set SkPt = SwModel.CreatePoint2(.ArrayData(0) * oScale, .ArrayData(1) * oScale, 0)

                     End With

               Next jj

               Debug.Print "**********"

           Dim SwAnn As Annotation

               Set SwAnn = SwDispDim.GetAnnotation

               Ss = SwAnn.GetAttachedEntities

         

               For jj = 0 To 1

                  Set SkPt = Ss(jj)

                  With SkPt

                      Pp(0) = .X

                      Pp(1) = .Y

                      Debug.Print "----", .X, .Y

                  End With

                  Set MathPt = SwMathUtil.CreatePoint(Pp)

                  Set MathPt = MathPt.MultiplyTransform(SwViewXForm)

                  ''

                  With MathPt

                       Debug.Print .ArrayData(0) * oScale, .ArrayData(1) * oScale, 0

                       Set SkPt = SwModel.CreatePoint2(.ArrayData(0) * oScale, .ArrayData(1) * oScale, 0)

                  End With

               Next jj

               Debug.Print "///////"

               ''

             

             

      End Sub