Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
How to do a simple rotation of cylinder around center point after a move?
jarrod_bellmore
Member Posts: 3 ✭✭
Hello!
I am pretty new to featurescript (though I am a software engineer in my day job). I have been able to do some of the basics like making a drawing plane, extruding the plane and moving bodies around but I can't seem to figure out how to do a basic rotation of a cylindrical body I have created. This seems like it should be a pretty simple thing to do so I am guessing I must be missing something!
The only example I can find seems to rotate the body around an axis relative to the world, not relative to itself. I basically just want to "spin" the object without having the object change position. Is there an example of this someone could point me towards?
Thank you!
I am pretty new to featurescript (though I am a software engineer in my day job). I have been able to do some of the basics like making a drawing plane, extruding the plane and moving bodies around but I can't seem to figure out how to do a basic rotation of a cylindrical body I have created. This seems like it should be a pretty simple thing to do so I am guessing I must be missing something!
The only example I can find seems to rotate the body around an axis relative to the world, not relative to itself. I basically just want to "spin" the object without having the object change position. Is there an example of this someone could point me towards?
Thank you!
0
Answers
-
Take a look at rotationAround which takes a line (the cylinder axis), then use opTransformSenior Director, Technical Services, EMEA0
-
Thanks for the response! I did take a look at that, particularly this forum post:
https://forum.onshape.com/discussion/3590/transform-rotate-around-axis
So I guess my question is, how do I get the center line of the object? I tried creating a plan on the top face of the cylinder using evPlane and using the origin/normal to create the line to pass into rotationAround but that does not seem to be doing what I want.
In the forum post I linked to they show creating the line to rotate around like this:const zAxis = line(vector(0, 0, 0) * meter, vector(0, 0, 1));
Is the line created by this set to 0,0,0 of the world or 0,0,0 of the plane? Using rotationAround I am able to rotate the object it just doesn't seem to be around the center line as the object moves as well as rotates.Thanks again!0 -
precondition { annotation { "Name" : "Cylinder", "Filter" : EntityType.FACE && GeometryType.CYLINDER, "MaxNumberOfPicks" : 1 } definition.cyl is Query; annotation { "Name" : "Angle" } isAngle(definition.angle, ANGLE_360_BOUNDS); } { var axis = evAxis(context, { "axis" : definition.cyl }); var angle = rotationAround(axis, definition.angle); opTransform(context, id + "rotate", { "bodies" : qOwnerBody(definition.cyl), "transform" : angle }); });
Senior Director, Technical Services, EMEA2 -
I leave here a complete test of:NeilCooke said:
precondition { annotation { "Name" : "Cylinder", "Filter" : EntityType.FACE && GeometryType.CYLINDER, "MaxNumberOfPicks" : 1 } definition.cyl is Query; annotation { "Name" : "Angle" } isAngle(definition.angle, ANGLE_360_BOUNDS); } { var axis = evAxis(context, { "axis" : definition.cyl }); var angle = rotationAround(axis, definition.angle); opTransform(context, id + "rotate", { "bodies" : qOwnerBody(definition.cyl), "transform" : angle }); });
https://cad.onshape.com/documents/c5698e768c34d23543bbe7aa/w/ee5ffbf19da0ae5ae19c4dd0/e/f8faa9dc058fc1731f57c070
0

