12 Replies Latest reply on May 6, 2018 3:34 AM by Mandar Parkhi

    Have difficulty understanding math transform.

    Fivezdw Fivezdw

      I have a program which needs using math transform.

      But I have some difficulties understanding the math transformation matrix.

      Below are some questions that i would like to ask


      1. For a existing component in an assembly, I used Transform2 Method to get the array data of the transform property of this component.

          However, I don't understand what's this transform matrix for. Why there is a transformation matrix in an existing component as I never transformed the component?

      2. If I want to transform an existing component or a temporary body along a specified direction for some specified distance(pure translation), how should I assign the values to the       

          transformation matrix?


      I have been playing around with math transform for a few days and it has really given me a headache.


      Hope anybody can help me with it. Your help will really be appreciated.

        • Re: Have difficulty understanding math transform.
          Keith Rice

          1. The transformation matrix contains data for a component's specific position and rotation, relative to the model origin. When you move or rotate a component, you apply a transform with data that corresponds to that new location or rotation.


          The only time you multiply transforms is when you need to convert from the coordinates of one context to another. For example, from a component's coordinates to assembly coordinates or vice versa. There's several examples in the API Help like this. Check out the IMathTransform help page.


          2. The values of the matrix are explained on the IMathTransform API help page. Get a component's current transform and try changing the values so you understand how it works. For example, here I am taking the existing transform data of a component and then adding 100mm to the X translation element, thereby moving it 100mm in the +X direction each time I run the macro:


          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim swSelMgr As SldWorks.SelectionMgr
          Dim swComp As SldWorks.Component2
          Dim swTransform As SldWorks.MathTransform
          Dim vTransformData As Variant
          Sub main()
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swSelMgr = swModel.SelectionManager
              Set swComp = swSelMgr.GetSelectedObject6(1, -1)
              'Get the current transform object
              Set swTransform = swComp.Transform2
              'Extract the matrix data from the transform object
              vTransformData = swTransform.ArrayData
              'Add 100mm to the +X element
              vTransformData(9) = vTransformData(9) + 0.1
              'Modify matrix
              swTransform.ArrayData = vTransformData
              'Apply new transform
              swComp.Transform2 = swTransform
          End Sub


          Notes on macro:

          1. The component needs to be selected in the FeatureManager tree.

          2. If mates are constraining the component, then the component will move back to its original location as soon as the mate solves. So best to suppress or delete mates before using this.



          SolidWorks API Training