draw ellipse using script

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
widow9098
Newbie Member
Posts: 4
Joined: Thu Apr 02, 2020 4:04 pm

draw ellipse using script

Post by widow9098 » Fri Apr 03, 2020 1:50 pm

can someone help me draw a ellipse with a java script?

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

Re: draw ellipse using script

Post by CVH » Fri Apr 03, 2020 4:13 pm

One method is to duplicate the functionality of the EllipseCPP.js or EllipseArcCPPA.js scripts.
Analog to this story:
https://qcad.org/rsforum/viewtopic.php?&t=6801

EllipseCPP.js ends up calling the EllipseArcCPPA.js script.
The major part of the script is data collection.
That data you have at hand.
Seems we need a REllipse
EllipseArcCPPA.prototype.getEllipse Line 487.
Adapted:

Code: Select all

var newEllipse = new REllipse(center, majorPoint, ratio, param1, param2, reversed)
The operation ('op' in this case) is prepared in:
EllipseArcCPPA.prototype.getOperation Line 258-287.
Adapted:

Code: Select all

var shape = Ellipse.postProcess(newEllipse);
var entity = shapeToEntity(this.getDocument(), shape);
var op = new RAddObjectOperation(entity, yourToolTitle);
As last this operation has to be casted:

Code: Select all

di.applyOperation(op);
Where 'di' is your document interface; 'op' the generated operation.
It occured to me in the recent past that this.getDocument() failed. Ifso replace it with your document.

The other method would be to preset all the data and parse it to the Ellipse script.
Analog to this story:
https://qcad.org/rsforum/viewtopic.php?&t=6649
But rather undocumented it can be harder to figure out how.
See:
https://qcad.org/rsforum/viewtopic.php?f=32&t=7106


Regards,
CVH

Post Reply

Return to “QCAD 'How Do I' Questions”