ModelToViewTransform+MultiplyTransform

MultiplyTransform + ModelToViewTransform,

result is error .

''

Private Sub ll3()

   Dim swApp As SldWorks.SldWorks, swModel As ModelDoc2

       Set swApp = Application.SldWorks

       Set swModel = swApp.ActiveDoc

   Dim swDraw As DrawingDoc

       Set swDraw = swModel

   Dim SwView As View

       Set SwView = swDraw.GetFirstView

       Set SwView = SwView.GetNextView

   Dim SwViewXForm

       Set SwViewXForm = SwView.ModelToViewTransform

   Dim swSelMgr As SelectionMgr

       Set swSelMgr = swModel.SelectionManager

   Dim swDispDim As DisplayDimension, SwDim As Dimension

       Set swDispDim = swSelMgr.GetSelectedObject5(1)

       Set SwDim = swDispDim.GetDimension

   Dim SwAnn As Annotation

       Set SwAnn = swDispDim.GetAnnotation

       Ss = SwDim.ReferencePoints

   

   Dim SwPt As SketchPoint, Pp

   Dim SwPt1 As MathPoint, SwPt2 As MathPoint

       Pp = SwAnn.GetPosition

       Set SwPt1 = Ss(1)

       Set SwPt1 = SwPt1.MultiplyTransform(SwViewXForm)

       Set SwPt2 = Ss(2)

       Set SwPt2 = SwPt2.MultiplyTransform(SwViewXForm)

   

   

   Dim Xx, Yy, Xx1, Yy1, Xx2, Yy2

       ''

       Xx = Pp(0)

       Yy = Pp(1)

       ''

       Xx1 = SwPt1.ArrayData(0)

       Yy1 = SwPt1.ArrayData(1)

       ''

       Xx2 = SwPt2.ArrayData(0)

       Yy2 = SwPt2.ArrayData(1)

       Debug.Print Xx * 1000, Yy * 1000

       Debug.Print Xx1 * 1000, Yy1 * 1000

       Debug.Print Xx2 * 1000, Yy2 * 1000

       swModel.CreateLine2 Xx1, Yy1, 0, Xx2, Yy2, 0

   

       swModel.CreateLine2 Xx, Yy, 0, Xx2, Yy2, 0

       swModel.CreateLine2 Xx1, Yy1, 0, Xx, Yy, 0

       Stop

End Sub

SolidworksApi macros
Answers 2
JA
JA 2017-01-04 Best Answer

I think the problem is that CreateLine2 is using the drawing coordinates and you are giving it the view coordinates (or vice versa).

When I attempted this a while back, I ended up just building a transform from view sketch to drawing sketch coordinates because I couldn't figure out which API-provided transforms to use.

YN
YN 2017-01-04

Thanks your tips.

Question is using the drawing coordinates and you are giving it the view coordinates?

<p style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;">Just follow these steps and you shall get the correct results: -</p><ol style="font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; color: #333333;"><li>Get Point from vertex (as you are currently doing).</li><li>Use ModelToViewTransform to transform this point to the view space. (Multiple vertex point with ModelToViewTransform)</li><li>Get the Sketch of the view (using view::GetSketch()).</li><li>Get ModelToSketchTransform for this Sketch.</li><li>Use ModelToSketchTransform to transform point (generated in step 2) to the sketch space. (Multiply point generated in step 2 with ModelToSketchTransform).</li><li>Activate the sheet.</li><li>Activate the view.</li><li>create your spline.</li></ol>