how to use ecmascript drawing tools within a script??

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
simon-2
Newbie Member
Posts: 9
Joined: Fri Jan 11, 2019 9:53 am

how to use ecmascript drawing tools within a script??

Post by simon-2 » Fri May 24, 2019 10:23 am

Hi,

i'm stuck trying to construct a "CircleTPR" in my script. Isn't it possible to use this class of drawing tools from scripts?
would like to use it like

Code: Select all

var Walze= new CircleTPR(this.curve, points[i],85.0);
,

but that does not seem to work.

what did i do wrong?

regards,
Simon

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

Re: how to use ecmascript drawing tools within a script??

Post by andrew » Fri May 24, 2019 10:05 pm

CircleTPR is an interactive tool that requires the user to enter a radius, click a shape (for the tangential requirement), click a point and then choose one of the two possible solutions. You cannot use such an interactive tool in a script that presumably runs fully automatically without any user interaction.

You can find the ArcTPR script with the relevant calculations to find the two candidate arcs / circles at:
https://github.com/qcad/qcad/blob/maste ... /ArcTPR.js

You'd still need a logic to choose one of the two possible solutions.

simon-2
Newbie Member
Posts: 9
Joined: Fri Jan 11, 2019 9:53 am

Re: how to use ecmascript drawing tools within a script??

Post by simon-2 » Wed May 29, 2019 7:38 am

hi Andrew,

thanks for your explanation; choosing one of the possible solutions is what i did not have in mind, but totally intelligible.

i tried to construct it in a different way now, using getAngleAt(), but still don't get it working.

Code: Select all

tangAng= this.curve.getAngleAt(i*spacing, from=0);
      EAction.handleUserWarning("Tangent Angle: "+tangAng.toFixed(2)); //for debugging only
but i get

Code: Select all

Tangent Angle: NaN
.
The curve is a polyline and does exist, as the following line works fine:

Code: Select all

points[i]=this.curve.getPointWithDistanceToStart(i*spacing);
, but the tangent line does not.

could you please point me to my error, once again?

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

Re: how to use ecmascript drawing tools within a script??

Post by andrew » Thu May 30, 2019 10:19 am

For polylines, you have to use the RS.AlongPolyline flag:

Code: Select all

this.curve.getAngleAt(distance, RS.AlongPolyline|RS.FromStart);

simon-2
Newbie Member
Posts: 9
Joined: Fri Jan 11, 2019 9:53 am

Re: how to use ecmascript drawing tools within a script??

Post by simon-2 » Wed Jun 05, 2019 1:02 pm

thanks alot, that's the missing piece.
I'm not too familiar with JS yet, so some things are not obvious to me. Next question is already evolving.. :oops:

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”