How can I use "Clip to Rectangle" in a script

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

Moderator: andrew

Forum rules
Always indicate Operating system, QCAD version
Attach Drawing files, Screenshots
Post one question per topic.
Post Reply
machinekoder
Newbie Member
Posts: 4
Joined: Tue Oct 15, 2019 1:55 pm

How can I use "Clip to Rectangle" in a script

Post by machinekoder » Tue Oct 15, 2019 2:01 pm

How can I use the "Clip to Rectangle" feature (https://qcad.org/doc/qcad/latest/refere ... le_en.html) in a script?

Alternatively, the dwg2maptiles cli tool would be very close to what I want to implement. Is the source code available somewhere?

Thanks,
Alex

EDIT: QCAD Pro 3.23.0.0 (3.23.0)

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

Re: How can I use "Clip to Rectangle" in a script

Post by andrew » Wed Oct 16, 2019 1:56 pm

To use the clip tool from script, you'd have to create the tool action, set the variables that are usually set interactively and then get the operation and run it. You can try all this in the QCAD script shell (Misc > Development > Script Shell). Make sure that there are entities in that area and that they are selected.

Code: Select all

// include tool:
include("scripts/Pro/Modify/ClipToRectangle/ClipToRectangle.js");

var di = getDocumentInterface();

// create and initialize tool:
var a = new ClipToRectangle();
a.setDocumentInterface(di);
a.corner1 = new RVector(10,10);
a.corner2 = new RVector(100,20);
a.mode = ClipToRectangle.Mode.Clip;  // or Clear or Cut

// run operation on current document:
var op = a.getOperation(false);
di.applyOperation(op);

machinekoder
Newbie Member
Posts: 4
Joined: Tue Oct 15, 2019 1:55 pm

Re: How can I use "Clip to Rectangle" in a script

Post by machinekoder » Wed Oct 23, 2019 1:21 pm

Thanks. This works excellent.

Post Reply

Return to “QCAD 'How Do I' Questions”