how to use tool like trim or lengthen in scripting
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
how to use tool like trim or lengthen in scripting
Hi I am newbie here, I wonder how can I use tool like trim or lengthen in scripting, for example I have created a line in my script and I want to extend it in my script, how do I do that? thanks.
Re: how to use tool like trim or lengthen in scripting
trim and lengthen have been added to the QCAD Simple API:
http://www.qcad.org/doc/qcad/latest/dev ... imple.html
Example:
https://github.com/qcad/qcad/tree/master/scripts
http://www.qcad.org/doc/qcad/latest/dev ... imple.html
Example:
var e1 = addLine(10,10,50,10) lengthen(e1, false, 10) var e2= addLine(30,30,40,20) trim(e1, 40,10, e2, 40,20, true)You can find the latest files of the QCAD Simple API at:
https://github.com/qcad/qcad/tree/master/scripts
Re: how to use tool like trim or lengthen in scripting
Thank Andrew for very helpful answer very appreciate it, I have another question How can I translate my drawing to any coordinate rather than (0,0) because I have two drawing one starting at (0,0) and another I want to offset to other coordination. Should I start both at (0,0) and then select and move another one to my specific coordination?
Re: how to use tool like trim or lengthen in scripting
I'd probably create one or multiple off-screen documents (createOffScreenDocument) and paste them into the drawing at various locations / scales / rotations.
I've updated the simple API to make this as easy as possible:
https://github.com/qcad/qcad/tree/master/scripts
I've updated the simple API to make this as easy as possible:
// create an off-screen document: var doc = createOffScreenDocument(); // add entities to off-screen document: startTransaction(doc); addLine(...); addArc(...); endTransaction(); // paste off-screen document into current drawing document at 100,0, scale 1, no rotation: paste(doc, getDocumentInterface(), new RVector(100,0), 1.0, 0.0, false, false, false, false, false);You can find the updated simple scripts at:
https://github.com/qcad/qcad/tree/master/scripts
Re: how to use tool like trim or lengthen in scripting
Thanks you very much for helping me out
Re: how to use tool like trim or lengthen in scripting
Hi Andrew,
When I create offscreen document and addLine to it, It works fine but when I try to use lengthen or trim like this:
When I create offscreen document and addLine to it, It works fine but when I try to use lengthen or trim like this:
var doc = createOffScreenDocument(); startTransaction(doc); var e1 = addLine(10,10,50,10); lengthen(e1, false, 10); endTransaction(); paste(doc, getDocumentInterface(), new RVector(100,0), 1.0, 0.0, false, false, false, false, false);I got error :
"TypeError: Result of expression 'entity' [undefined] is not an object."
Re: how to use tool like trim or lengthen in scripting
Please update simple_modify.js
As you can see, the simple API is evolving ad-hoc. You are strongly encouraged to also suggest your own changes and additions and submit them through this forum or through github.com.
As you can see, the simple API is evolving ad-hoc. You are strongly encouraged to also suggest your own changes and additions and submit them through this forum or through github.com.
Re: how to use tool like trim or lengthen in scripting
AddEntity() return undefined when use with offscreen document so I changed it to return entity now I can use trim and lengthen.