Need a macro to rotate part in assembly about it's origin by user selected axis and angle

I realize you can use the Triad to rotate parts, but when you have hundreds of them in an assembly you have to rotate by different amounts it gets quite slow.

I need a macro that will rotate a selected part (or parts) about their own origins. It should ask for user input for the axis to rotate around and rotation angle. It would be cool if you could have many parts selected but even if it does it a single part at a time a macro would be a time saver.

Thanks

SolidworksAssemblies
Answers 14
DG
DG 2014-10-11 Best Answer

Sorry not in front of SW but can you try recording one and check if that works for you?

DN
DN 2014-10-11

I tried that, but It didn't work or I did some wrong. When I hit play it just sits there.

DN
DN 2014-10-11

I tried running that and it gave me a compile error. Weird.

DG
DG 2014-10-12

Dan, the macro worked fine for me. The attachment option is not working at the moment so will add a video later.

DN
DN 2014-10-12

I'll try it again. Does it let you select an axis to rotate about?

Thanks for your help!

DG
DG 2014-10-13

The macro rotates the selected component by 90° in X axis.

Make sure you've selected a component before running the macro.

DN
DN 2014-10-13

I don't think I'm loading the macro the correct way. I tried copying the example you linked into a new .swp file but it wouldn't load. I also tried tool>macro>new and doing it that way but it gave me a compile syntax error on this line when I tried to run it:

Set swXform = swMathUtil.CreateTransformRotateAxis( _

                    swOriginPt, swX_Axis, 1# * RadPerDeg)

If I was able to get it working though would I be able to change the axis the component rotates about? At a minimum I think I would need to rotate about the z axis in 45d increments.

Thanks!

DG
DG 2014-10-13

The error is because of the gap after underscore.. Change the line to

<p>Set swXform = swMathUtil.CreateTransformRotateAxis( swOriginPt, swX_Axis, 1# * RadPerDeg) </p>
DN
DN 2014-10-13

That worked for getting the macro running. It didn't perform as I expected though.

It rotated the part about the assembly origin 90 degrees instead of the part origin. My part ended up free floating in space.

DG
DG 2014-10-13

Yes that is how macro is supposed to work. The macro will have to tweaked to rotate the part about it's origin by user selected axis and angle

SF
SF 2015-02-04

One question, how do I change the macro to be able to rotate the object in the Y or the Z axis.

DN
DN 2016-06-27

I'm still hoping someone could help me with a macro to do this function. What I normally do now is select a part in the assembly view and go through the triad to rotate it by 90 around the parts origin. What I'd like to be able to do it select a part and hit a hotkey to rotate it by 90. If anyone knows of a macro like this please let me know.

Thanks!

DN
DN 2016-07-10

Still no takers. Could really be a useful macro!