Get area of an entity in Script Shell

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
User avatar
dfriasb
Senior Member
Posts: 119
Joined: Thu Mar 10, 2016 1:08 pm
Location: Calafell, Tarragona, Spain

Get area of an entity in Script Shell

Post by dfriasb » Sun Sep 24, 2017 5:36 pm

Hello,
I started scripting and using Script Shell. I managed to get x&y coordinates of lines start&end points and other information, but I cannot get areas. I tried "entity.getArea()", but it looks like this function doesn't exist.
This is the code I'm using:

Code: Select all

var doc = EAction.getDocument();
var entityIds = doc.queryAllVisibleEntities();
entityIds = doc.getStorage().orderBackToFront(entityIds);
for (var i = 0; i < entityIds.length; ++i) {
    var entity = doc.queryEntity(entityIds[i]);
    var pline = "" + entity.getId() + " ";
    if (isPolylineEntity(entity)) {
        pline += entity.getArea() + ",";
       }
}
Any help will be very welcomed!
Regards,
David
David Frías Barranco | architect
[email protected] | davidfriasarquitecto.es

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

Re: Get area of an entity in Script Shell

Post by andrew » Sun Sep 24, 2017 10:42 pm

I've added getArea to the RPolylineEntity API for the next release. For now you can use getArea of the underlying RPoltyline shape instead:

Code: Select all

entity.castToShape().getArea();

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”