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.

Rotating a sketch rectangle

graham_lockgraham_lock Member Posts: 227 PRO

Hi,

I'm drawing a rectangle which I want to rotate:

I have a rotation transform matrix where the angle is user driven:

var rotationMatrixStart = [[cos(definition.freeXYStartRotation), -sin(definition.freeXYStartRotation)], [sin(definition.freeXYStartRotation), cos(definition.freeXYStartRotation)]] as Matrix;

And a sketch:

skPolyline(sketchStartFormer, "profileStartFormer", {
"points" : [
startProfileCorner1,
startProfileCorner2,
startProfileCorner3,
startProfileCorner4,
startProfileCorner1
]
});

How should I go about rotating the rectangle about its centre point to achieve the equivalent of:

Rotate Rectangle.png

If I apply the rotation to the points before sketching them then the rectangle rotates about the centre of the sketch plane.

Any help appreciated.

Thank you.

Answers

  • glen_dewsburyglen_dewsbury Member Posts: 1,021 ✭✭✭✭
    edited 1:03AM

    removed

  • graham_lockgraham_lock Member Posts: 227 PRO

    Thank you but I need to do this in Feature Script.

  • Matt_ShieldsMatt_Shields Member, Onshape Employees Posts: 623

    Does this help?
    https://cad.onshape.com/documents/164c09de99073544524150c2/w/95e2fe023391a43f159891ac/e/af7550ab2e2d704f6e3c7c38

    image.png
  • graham_lockgraham_lock Member Posts: 227 PRO

    Thank you.

    So if I'm understanding this correctly, when using Sketcher it's possible to transform around the centre of a sketched area, but in Feature Script there is no such transform available so the sketch plane centre needs to be at the centre of rotation of the area to rotate?

  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 154 PRO

    There isn't anything like a skTransform function (at least not one that's publically documented). When making sketches in FS, it's more important that you get your initial coordinate system correct, instead of creating a sketch somewhere and then moving it. That's part of the reason that the sketch documentation says constraints are mostly unnecessary when sketching in FS, you can usually pinpoint exactly where you want it with some good vector math. Another approach could be to sketch and extrude, then do the opTransform function (this depends on the use case of course).

    If you want my advice though, I would recommend staying away from sketching in FS. What I do almost every time I need sketches generated by a custom feature is I make a part studio with that sketch in it, set it up with configuration parameters, then I just derive the sketch in using the custom feature and from there it's much easier to place/rotate the sketch entity. It's also way easier to edit that sketch since you can just edit it in a part studio instead of redoing your logic for constraints in FS.

    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
  • graham_lockgraham_lock Member Posts: 227 PRO

    Thank you.

    How do you derive the sketch into a custom feature and then set the configuration parameters?

    in my use case the final part is a loft between two sketch profiles. The user selects the profiles shapes / sizes, x/y offsets and rotation in the feature UI.

    Would that be possible with your recommendation?

    Thanks again.

  • Matt_ShieldsMatt_Shields Member, Onshape Employees Posts: 623

    It's been a while since I've taken linear algebra, but I think you can rotate about an arbitrary point. Translate → Rotate → Translate back.

    image.png image.png
  • graham_lockgraham_lock Member Posts: 227 PRO

    Interesting thank you.

  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 154 PRO
    edited May 13

    Here's a really simple example. It was made for a different post on this forum but I commented the code you'd be using to import sketches. You're pretty much just using the instantiate function, there's plenty of documentation on that here.

    https://cad.onshape.com/documents/cec79d6de564717d83526a2b/w/6552169cf2769c6c4135d9f1/e/3a971c226d00e7eb7c24e3bd

    This is a pretty widely applicable technique. Pretty much any time you need a sketch you can do this instead. This also works just fine with imported parts as well, so there are times where I don't want to make complex geometry in a custom feature so I'll do the same thing and just configure a part and import that in using the same technique.

    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
  • graham_lockgraham_lock Member Posts: 227 PRO

    Thank you.

    I've tried to recreate this document since it is read only but I get:

    IMPORT_DERIVED_NO_PARTS

    My test document is here:

    https://cad.onshape.com/documents/4dea6a14a5bba4a6744c3fe9/w/5d36b22c3c19762fd239743b/e/ba32108e071585a347d97118

  • Alex_KempenAlex_Kempen Member Posts: 251 EDU

    Your "partQuery" is for solid parts (qBodyType with BodyType.SOLID), which you won't have in your part studio. qEverything(EntityType.BODY) should be sufficient for deriving a sketch.

    Software Developer at Epic Systems
    FRC Design Mentor - Team 1306 BadgerBots


  • graham_lockgraham_lock Member Posts: 227 PRO

    Thank you, this gets past the derived parts error but then the boolean fails with:

    BOOLEAN_INPUTS_NOT_SOLID

  • Matt_ShieldsMatt_Shields Member, Onshape Employees Posts: 623

    I don't think you can boolean a sketch and a solid.

  • graham_lockgraham_lock Member Posts: 227 PRO

    Thank you. Yes, I'm confused as the document which @chadstoltzfus linked to above appears to work.

  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 154 PRO

    Sorry, forgot that I extruded something in the Sketch Config part studio, so pretty much the instantiator is bringing in the extrude part and booleaning it. But you can more or less use the same technique to import a sketch. If you comment out the opBoolean() in your document you should see that the sketch has been brought over successfully.

    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
  • graham_lockgraham_lock Member Posts: 227 PRO

    Ok thank you- I’ll have a play.

Sign In or Register to comment.