how to use tool like trim or lengthen in scripting

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
Kuma
Newbie Member
Posts: 7
Joined: Tue Sep 13, 2016 4:46 pm

how to use tool like trim or lengthen in scripting

Post by Kuma » Tue Sep 13, 2016 5:00 pm

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.

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

Re: how to use tool like trim or lengthen in scripting

Post by andrew » Fri Sep 16, 2016 2:50 pm

trim and lengthen have been added to the QCAD Simple API:
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

Kuma
Newbie Member
Posts: 7
Joined: Tue Sep 13, 2016 4:46 pm

Re: how to use tool like trim or lengthen in scripting

Post by Kuma » Sat Sep 17, 2016 11:14 am

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?

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

Re: how to use tool like trim or lengthen in scripting

Post by andrew » Sat Sep 17, 2016 5:25 pm

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:
// 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

Kuma
Newbie Member
Posts: 7
Joined: Tue Sep 13, 2016 4:46 pm

Re: how to use tool like trim or lengthen in scripting

Post by Kuma » Sun Sep 18, 2016 7:24 am

Thanks you very much for helping me out :) :)

Kuma
Newbie Member
Posts: 7
Joined: Tue Sep 13, 2016 4:46 pm

Re: how to use tool like trim or lengthen in scripting

Post by Kuma » Mon Sep 19, 2016 5:46 pm

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:
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."

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

Re: how to use tool like trim or lengthen in scripting

Post by andrew » Tue Sep 20, 2016 7:23 am

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.

Kuma
Newbie Member
Posts: 7
Joined: Tue Sep 13, 2016 4:46 pm

Re: how to use tool like trim or lengthen in scripting

Post by Kuma » Wed Sep 21, 2016 5:53 am

AddEntity() return undefined when use with offscreen document so I changed it to return entity now I can use trim and lengthen.

Post Reply

Return to “QCAD 'How Do I' Questions”