Try this code:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swComp As SldWorks.Component2
Dim swMathUtils As SldWorks.MathUtility
Dim swMathVec As SldWorks.MathVector
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swComp = swSelMgr.GetSelectedObject6(1, -1)
Set swMathUtils = swApp.GetMathUtility
Dim dVec(2) As Double
dVec(0) = 0: dVec(1) = 0: dVec(2) = 1
Set swMathVec = swMathUtils.CreateVector(dVec)
Set swMathVec = swMathVec.MultiplyTransform(swComp.Transform2)
Dim vVecData As Variant
vVecData = swMathVec.ArrayData
Debug.Print vVecData(0) & "; " & vVecData(1) & "; " & vVecData(2)
Thank you Artem.
I made mistake on vector creation. I choosed wrong axis. X instead of Z.
Thank you for the code; I want to get the orientation of a part within its assembly too, and this seems to be working, but I was wondering what format the output is in? I would ideally like the angles between the axes, but I'm not sure what this output is giving me. Any clarification would be greatly appreciated.
Those are vector coordinates in this order (x,y,z).
First you define vector in part. In this case Z axis. Then after transformation you can see this vector coordinates but in assembly environment/coordinate system.
If you need angles then you need to do math on vectors.
You should be also able to get angles from transformation matrix (swComp.Transform2). If I remember correctly. This should be explained it help, or in math book
Thank you very much, Stefan! That really helped me understand what was going on with the code.