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 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
Example to rotate selected?
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Re: Example to rotate selected?
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.
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.
Re: Example to rotate selected?
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
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
Re: Example to rotate selected?
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
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
Re: Example to rotate selected?
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.
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.
One doesn't have to rotate 500 entities one by one.
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.
The bounding box of an REntity type in variable 'entity' or 'e' or whatever the variable name is:
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.
Similar topic: https://www.qcad.org/rsforum/viewtopic. ... 273#p42035
Regards,
CVH
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.
Not with the Simple API ... In general this works:
Code: Select all
var doc = this.getDocument();
var ids = doc.querySelectedEntities();
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.
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.
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.
The bounding box of an REntity type in variable 'entity' or 'e' or whatever the variable name is:
Code: Select all
entity.getBoundingBox();
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.
Similar topic: https://www.qcad.org/rsforum/viewtopic. ... 273#p42035
Regards,
CVH