By Adam Nagy
There is already a blog post on rotating inside a drawing, now we'll do the same with an assembly component / component occurrence.
Once you have the matrix of the rotation and the current transformation of the component, you just have to combine them and assign that to the component.
Just select the axis you want to use and the component you want to rotate by 90 degrees, then run the VBA code:
Sub RotateAroundAxis() Const PI = 3.14159265358979 Dim d As AssemblyDocument Set d = ThisApplication.ActiveDocument Dim a As WorkAxis Set a = d.SelectSet(1) Dim o As ComponentOccurrence Set o = d.SelectSet(2) Dim t As TransientGeometry Set t = ThisApplication.TransientGeometry Dim l As Line Set l = a.Line Dim mRot As Matrix Set mRot = t.CreateMatrix() ' PI / 2 => 90 deg Call mRot.SetToRotation(PI / 2, l.Direction.AsVector(), l.RootPoint) Dim m As Matrix Set m = o.Transformation Call m.PreMultiplyBy(mRot) o.Transformation = m End Sub