2 Replies Latest reply on Apr 6, 2014 4:16 PM by Milan K

    position of the root component in assembly

    Milan K



      I need to put a root component in assembly on the same location relative to origin coordinate in which it has been built. Using the method AddComponent the root part is always centered into the origin. Is there i simple solution or do I need to somehow calculate the relative distances X,Y,Z of the bounding box centroid to the origin coordinate and then use these dimensions in AddComponent method?



      Milan, 2-day-newbie in solidworks api

        • Re: position of the root component in assembly
          Keith Rice



          After you insert the component you need to relocate it using transforms. In your case I think all you need to do is set the component's transform equal to the assembly transform. The following example will do that for a selected component:



          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim swSelMgr As SldWorks.SelectionMgr
          Dim swComp As SldWorks.Component2
          Dim swMathUtil As SldWorks.MathUtility
          Dim swTransform As SldWorks.MathTransform
          Sub main()
               Set swApp = Application.SldWorks
               Set swModel = swApp.ActiveDoc
               Set swSelMgr = swModel.SelectionManager
               Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, 0)
               Set swMathUtil = swApp.GetMathUtility
               'Return transform of the assembly
               Set swTransform = swMathUtil.CreateTransform(Nothing)
               'Set component transform equal to assembly transform
               swComp.Transform2 = swTransform
               'Rebuild to see results
          End Sub




          If you want to learn about transforms in depth, I would recommend Lesson 5.3 at our web site. It is not free but it will save you many hours of having to teach yourself from the API Help Examples, which are hard to understand if you're new to transforms.



          SolidWorks API Tutorials