Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:

  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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_bellmorejarrod_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!

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 2,599
    Take a look at rotationAround which takes a line (the cylinder axis), then use opTransform
  • jarrod_bellmorejarrod_bellmore Member Posts: 3
    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!
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 2,599
        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 });
        });

  • FdaFda Member Posts: 21 ✭✭
    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

Sign In or Register to comment.