rotatae in ecma

Post to this forum to introduce yourself to this forum if you are new here. You might want to include some information about the work you are doing or planning to do with QCAD.

Moderator: andrew

Post Reply
rolfk
Registered Member
Posts: 2
Joined: Mon Feb 19, 2024 11:08 am

rotatae in ecma

Post by rolfk » Thu Apr 25, 2024 2:02 am

hi to all


I am new to qcad and need some help

in the ecma script shell
(right hand side)

i can draw a line with
addLine(0,0, 100,100)

but how do I rotate it inside the ecma script shell?

i am running on
QCAD Professional Trial

Version: 3.29.4.0 (3.29.4)
Internet: QCAD.org
Build Date: Feb 7 2024
Revision: 36a6423
Qt Version: 5.14.2
Architecture: x86_64
Compiler: gcc 5.4.0



kind regards
rolf kudelka

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

Re: rotatae in ecma

Post by CVH » Thu Apr 25, 2024 6:47 am

Hi, and welcome to the QCAD forum.

addLine(0,0, 100,100)
Is a method of the QCAD Simple API, that draws a line piece and done.

The Simple API is mentioned halfway https://www.ribbonsoft.com/en/tutorial- ... pt-actions
"This is slightly more complex than what we have seen in the simple API above." >> But there is nothing over it 'above' ... :roll:
More can be found here:
https://www.qcad.org/doc/qcad/latest/de ... imple.html

You could do:

Code: Select all

include("scripts/simple.js");
var newEntity = addLine(0,0, 100,100);
move(newEntity, 40, 10);
That will draw a line piece and return a reference to the newly created object what is stored in a variable.
Then the new entity is moved over a certain distance in X and in Y.
The first line is not really required, not always ... But it doesn't hurt. :wink:

Both addLine(...) and move(...) have several alternative signatures.

Remind that this are two separate transactions, it requires 2 steps to fully undo for example.
After each transaction the displayed view is regenerated, the document in memory changes ...
... Together with several other time consuming processes.
In the end you will want to group actions (See: startTransaction(), endTransaction()) or use the more elaborated standard API.

Regards,
CVH

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

Re: rotatae in ecma

Post by andrew » Thu Apr 25, 2024 8:09 am

rolfk wrote:
Thu Apr 25, 2024 2:02 am
but how do I rotate it inside the ecma script shell?
I'd recommend to create a line shape in memory only, then transform it as desired and only then add it:

Code: Select all

// create a new line shape in memory, this adds nothing to the drawing yet:
var line = new RLine(0,0, 100,100);

// rotate the line around point 50/50 by 30 degrees counter-clockwise (deg2rad converts degrees to radians): 
line.rotate(deg2rad(30.0), new RVector(50,50));

// add the transformed shape to the drawing:
addShape(line);

rolfk
Registered Member
Posts: 2
Joined: Mon Feb 19, 2024 11:08 am

Re: rotatae in ecma

Post by rolfk » Fri Apr 26, 2024 1:20 am

hi to all on the qcad forum

thank you very much for the quick response
i really do appreciate this
i have got 2 replies in less than 24 hours
which is great and better than most
i am thankfull

oh, this all over my head atm

to CVH
the most detailed response
yeap i wish i was 1/2 as smart as you
all over my head brother
but thanks

to andrew
yeah sort of getting it
will have to play around with it
till it starts to sink in
thanks brother

thank you very much brothers and sisters


kind regards
rolfk

Post Reply

Return to “Introduce Yourself”