Example to rotate selected?

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
tkyler
Junior Member
Posts: 17
Joined: Thu Jan 26, 2023 2:54 pm

Example to rotate selected?

Post by tkyler » Sat Sep 16, 2023 1:18 pm

Hello all, first time poster here, and new user of QCAD, which really is a spectacular value / piece of software. I am a longtime Vectorworks user, but I don't use it enough to justify licensing it any more. I scripted in that program a lot and out of sheer muscle memory, I'm looking to script some of the more "convenient" tools I liked from that program. ...many of which required a 'handle to the selected object'

I've done due diligence for about 45 mins now, searching/browsing the API docs and simply can't figure out how (using QCAD simple API) to "get a handle to a selected object", i.e the "entity"....the 'e' argument... so that I can rotate it 90º with a keystroke. I've killed enough time now to execute the RO command manually about 500 times :P and rapidly approaching a negative return on investment time wise. Of course the learning is worth it.

Would anyhow happen to have, or know where I might find perhaps...and example of the correct ECMAScript syntax to acquire a handle to the selected object for modification with the simple API?

The goal here is to rotate selected entity[s] (bounding box if multiple selection) by 90º to the right or left (CCW/CW) using ALT-L and ALT-R (or some other modification key). In either case, I'd rotate around the bounding box center of the entity[s])

I'll keep searching, but a nudge in the right dirction would be appreciated. Thx!

TomK

User avatar
andrew
Site Admin
Posts: 9063
Joined: Fri Mar 30, 2007 6:07 am

Re: Example to rotate selected?

Post by andrew » Sat Sep 16, 2023 1:51 pm

You can use

Edit > Quick Modify > Rotate Counter-Clockwise [F5]

and

Edit > Quick Modify > Rotate Clockwise [F6]

You can configure the angle under

Edit > Application Preferences > Edit > Rotate

This also works for example while pasting.

tkyler
Junior Member
Posts: 17
Joined: Thu Jan 26, 2023 2:54 pm

Re: Example to rotate selected?

Post by tkyler » Sat Sep 16, 2023 2:12 pm

Thank you Andrew, that is handy for sure! Wonderful work with QCAD BTW.

I would be interested still in learning to script a bit more, and starting with selected items (vs created). Would you happen to have an example lying around still? The rotate left/right, while desired for practical use, was also intended to be a learning exercise.

Thx in advance.

TomK

User avatar
andrew
Site Admin
Posts: 9063
Joined: Fri Mar 30, 2007 6:07 am

Re: Example to rotate selected?

Post by andrew » Sat Sep 16, 2023 2:34 pm

Thank you for your kind feedback.

There are many script examples (essentially all tools of QCAD) available in our repository at:
https://github.com/qcad/qcad/tree/master/scripts

For example this script that converts all selected splines that are completely straight to lines:
https://github.com/qcad/qcad/blob/031b5 ... eToLine.js

You can also find some script tutorials to get started at:
https://www.qcad.org/en/tutorial-script-programming

CVH
Premier Member
Posts: 3480
Joined: Wed Sep 27, 2017 4:17 pm

Re: Example to rotate selected?

Post by CVH » Sat Sep 16, 2023 4:53 pm

TomK,

The Simple API is not really suited for scripting addons.
Addons are for example scripts that are triggered by a shortcut key sequence as do most QCAD tools, see:
https://www.ribbonsoft.com/archives/sho ... uts_en.pdf
Remark that there are not many free combinations left over.
tkyler wrote:
Sat Sep 16, 2023 1:18 pm
searching/browsing the API docs and simply can't figure out how (using QCAD simple API) to "get a handle to a selected object",
Not with the Simple API ... In general this works:

Code: Select all

var doc = this.getDocument();
var ids = doc.querySelectedEntities();
ids is now a list of ID's (if any) and you need to query these entities by their ID.
https://qcad.org/doc/qcad/3.0/developer ... 79a957c678

Any modification to these queried entities is not immediate, you need to cast them back to the drawing.
tkyler wrote:
Sat Sep 16, 2023 1:18 pm
I've killed enough time now to execute the RO command manually about 500 times
If all around the same point as explained later then you could rotated them as a multiple selection.
One doesn't have to rotate 500 entities one by one. :wink:
If each around an individual point then you need 'Alt-L or Alt-R (or some other modification key)' for each too.
Why inventing the wheel? The functions already exists ... F5 & F6.
Use a 30 degrees step and a shift multiplier x3 ... Shift F5 & Shift F6 is then 90 degrees CCW or CW. :wink:

The bounding box of an REntity type in variable 'entity' or 'e' or whatever the variable name is:

Code: Select all

entity.getBoundingBox();
Methods with bounding boxes, see:
https://qcad.org/doc/qcad/3.0/developer ... r_box.html

The learning curve of scripting under QCAD can be steep.
Do not expect to have an overview of the vast QCAD API in the first 45 mins. :wink:

Similar topic: https://www.qcad.org/rsforum/viewtopic. ... 273#p42035

Regards,
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”