2 Replies Latest reply on Mar 3, 2015 10:10 AM by Andy Braham

    AddDimension2 text location

    Andy Braham

      Hello everyone,

         I have a simple question about how to enter the position of the text in a Model Sketch. When using the ModelDoc2::Extensions::AddDimension2 the position of the text is defined by the xyz values, the problem that I am running into is the coordinates are based on the Model not the 2D sketch. So for example if I sketch on the Right plane the coordinates for 1,2,0 are actually 0,2,1 because the plane is on YZ. Am I using the wrong method to create the dimensions? I looked under the SketchManager and did not see any methods for creating dimensions.  Or is there a easy way to convert the Model Coordinates to the Sketch Coordinates?

       

      Thanks for the help!

      Andy

        • Re: AddDimension2 text location
          Keith Rice

          Andy,

           

          If the coordinates you want to use are relative to the model, you need to transform them relative to the sketch, which is accomplished via ISketch::ModelToSketchTransform. Check out the API Help example "Transform Coordinates from Sketch to Model Space Example (VBA)". Note that this transforms from sketch to model, if you want to do the opposite then you would simply remove this line so as not to invert the transform:

           

          Set swMathTrans = swMathTrans.Inverse

           

          Keith

          SolidWorks API Tutorials

            • Re: AddDimension2 text location
              Andy Braham

              Thank you Kieth, that is exactly what I was looking for.

               

              In case anyone else is trying to figure this out here is a quick snippet

               

              Dim swApp As SldWorks.SldWorks

              Dim swPart As SldWorks.ModelDoc2

              Dim swSketch As SldWorks.Sketch

              Dim swMathUtil As SldWorks.MathUtility

              Dim swMathTrans As SldWorks.MathTransform

              Dim swMathPt As SldWorks.MathPoint

              Dim pntSketch(2) As Double

              Dim pntModel() As Double

               

              Set swApp = Application.SldWorks

              Set swPart = swApp.ActiveDoc

              Set swMathUtil = swApp.GetMathUtility

              Set swSketch = swPart.GetActiveSketch2

              Set swMathTrans = swSketch.ModelToSketchTransform

               

              pntSketch(0) = 1.5

              pntSketch(1) = 3.25

              pntSketch(2) = 0

               

              Set swMathPt = swMathUtil.CreatePoint(pntSketch)

              Set swMathPt = swMathPt.MultiplyTransform(swMathTrans)

               

              pntModel = swMathPt.ArrayData

               

              Debug.Print "Sketch point: " & pntSketch(0) & ", " & pntSketch(1) & ", " & pntSketch(2) & ", "

              Debug.Print "Model point: " & pntModel(0) & ", " & pntModel(1) & ", " & pntModel(2) & ", "