我希望每个人都很好。
我正在使用一个solidworks 宏,它相对于装配轴旋转装配组件作为其旋转点。我在下面有这段代码:
Sub RotateX()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swMath As SldWorks.MathUtility
Dim swComp As SldWorks.Component2
Dim compTransform As SldWorks.MathTransform
Dim swVect As MathVector
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swComp = swSelMgr.GetSelectedObjectsComponent2(1)
Set swMath = swApp.GetMathUtility
'==============================
On Error Resume Next
'==============================
Set compTransform = swComp.Transform2
Dim dirArr(2) As Double
dirArr(0) = 1
dirArr(1) = 0#
dirArr(2) = 0#
'Rotate about x axis {1,0,0}
Set swVect = swMath.CreateVector((dirArr))
Set swVect = swVect.MultiplyTransform(compTransform)
'rotate the x 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)
swComp.Transform2 = compTransform.Multiply(swXform)
swModel.EditRebuild3
End Sub
但是此代码使用零件轴作为旋转点进行旋转。我想制作一个使用装配轴旋转零件的宏,但零件位置仍然不会移动它的位置,只是旋转。我希望有人可以帮助我回答如何使该零件在装配轴上旋转。