Hello everyone,!
My question is how to create a program in VBA to move components within an assembly. I would like to move the parts, without using the solidworks program.
Thanks in advance.
Denis
distance
absolute coordinates
Hello everyone,!
My question is how to create a program in VBA to move components within an assembly. I would like to move the parts, without using the solidworks program.
Thanks in advance.
Denis
distance
absolute coordinates
Thank you for your kind reply.
I'm happy to know you, MR Gupta, I've been following you for a few years. Let's go back to the macro, I recovered a macro on the Forum, which rotates the objects that I think the logic or the commands are there. I do not know the comnado to be change wheel with move
'***********************************************************************
Option Explicit
Const PI As Double = 3.14159
Const RadPerDeg As Double = PI / 180#
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swMath As SldWorks.MathUtility
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Dim swComp As SldWorks.Component2
Set swComp = swSelMgr.GetSelectedObjectsComponent2(1)
Set swMath = swApp.GetMathUtility
Dim compTransform As SldWorks.MathTransform
Set compTransform = swComp.Transform2
Dim swVect As MathVector
Dim I As Long
'possibility of entering the degrees of rotation asse "X"
I = InputBox("INSERISCI L'ANGOLO")
Dim dirArr(2) As Double
dirArr(0) = 0#
dirArr(1) = 0#
dirArr(2) = 1
'''''I think that from here it is necessary to replace the wheel function, with another that you move''''''
'Rotate about z axis {0,0,1}
Set swVect = swMath.CreateVector((dirArr))
Set swVect = swVect.MultiplyTransform(compTransform)
'rotate the z axis into the component's reference frame
Dim vData As Variant
dirArr(0) = 0#
dirArr(1) = 0#
dirArr(2) = 0#
'rotate about origin
vData = dirArr
Dim swPoint As SldWorks.MathPoint
Set swPoint = swMath.CreatePoint(vData)
Set swPoint = swPoint.MultiplyTransform(compTransform)
Dim swXform As SldWorks.MathTransform
' Set swXform = swMath.CreateTransformRotateAxis(swPoint, swVect, 90# * RadPerDeg)
Set swXform = swMath.CreateTransformRotateAxis(swPoint, swVect, I * RadPerDeg)
swComp.Transform2 = compTransform.Multiply(swXform)
swModel.EditRebuild3
End Sub
I'm not very much sure on how to do this but you would have to use IComponent2::Transform2 to set the position of the component.