Hello,
Something I find myself doing fairly often is drawing boxes around objects. I've been doing this by placing vertical and horizontal lines at the four minimum/maximum points, then connecting them. However, it's not always easy to tell exactly where the minimum X, maximum X, minimum Y, and maximum Y points are. I thought a script that draws a bounding box around a selected entity would be a useful addition. But I don't see any way to access the necessary information. Even if I have to cycle through the coordinates of all the selected points, that would be fine. I just don't see a way to get any information about anything that's already selected. Is there a way to do that?
Regards,
Denver
Script to create bounding boxes
Moderator: andrew
Scripting in QCAD 2 is limited to constructing simple entities without querying existing entities.
In the new ECMAScript interface of QCAD 3 (currently beta), this is easily possible.
More or less like this (from the top of my head, not tested):
In the new ECMAScript interface of QCAD 3 (currently beta), this is easily possible.
More or less like this (from the top of my head, not tested):
Code: Select all
MyAction.beginEvent = function() {
// get current document and document interface:
var doc = this.getDocument();
var di = this.getDocumentInterface();
// get bounding box of current selection:
var box = doc.getSelectionBox();
// grow box if desired:
box.grow(1.0);
// convert box to lines:
var lines = box.getLines2d();
// add lines to document:
var op = new RAddObjectsOperation();
for (var i=0; i<lines.length; i++) {
var entity = new RLineEntity(doc, new RLineData(lines[i]));
op.addObject(entity);
}
di.applyOperation(op);
}
denverh: QCAD 3 RC1 has an example script for that under scripts/Examples/DrawExamples/DrawBoundingBox
It's also available in the menu Examples - Drawing - Draw Bounding Box.
Usage:
1. Select entity(ies)
2. Start tool
A bounding box is drawn around each of the selected entities.
The script is thought as a starting point for more advanced, similar scripts.
It's also available in the menu Examples - Drawing - Draw Bounding Box.
Usage:
1. Select entity(ies)
2. Start tool
A bounding box is drawn around each of the selected entities.
The script is thought as a starting point for more advanced, similar scripts.