Hello,
i am currently looking for a way to export the lenghts of every contour in a .dxf file.
While using the GUI i can use the function "(De)-Select Contour" to manually select a single contour.
The length is then shown in the property window.
Is there a way to simulate that behaviour that function in a script? Just iterating through every contour would be fine.
I intend to use the .csv export sample to export the contour lengths.
Thanks for your support.
[Solved] Get all contour lengths
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
[Solved] Get all contour lengths
Last edited by SM_MaGa on Mon Aug 02, 2021 2:11 pm, edited 1 time in total.
Re: Get all contour lengths
Are you using QCAD Professional of the QCAD Community Edtion?
Re: Get all contour lengths
I am using QCAD/CAM.
Re: Get all contour lengths
Hi,
Your question is rather ambiguous.
(De)-Select Contour (TC) doesn't select contours in the meaning of closed CNC contours.
In selection mode the tool selects all entities somehow connected to the entity reffered to.
Test it for yourself:
The answer would be easier if your individual closed contours would be polylines.
One can select all connected entities to a given entity ID with the same result as TC by:
What returns a list of ID's that can be set selected as in the above.
Details:
https://github.com/qcad/qcad/blob/maste ... Contour.js
https://qcad.org/doc/qcad/3.0/developer ... c737669802
https://qcad.org/doc/qcad/3.0/developer ... a1be59fbe4
The idea is then to query all entities of your drawing.
Cycle the ID's one by one
Exclude some like Points .. Texts .. Dims ....
Retrieve the connected ID's.
Sum the individual lengths of the connected ID's for CSV export. (Here selections isn't required)
Exclude connected ID's from further cycling.
Regards,
CVH
Your question is rather ambiguous.
(De)-Select Contour (TC) doesn't select contours in the meaning of closed CNC contours.
In selection mode the tool selects all entities somehow connected to the entity reffered to.
Test it for yourself:
The answer would be easier if your individual closed contours would be polylines.
One can select all connected entities to a given entity ID with the same result as TC by:
Code: Select all
var doc = this.getDocument();
var di = this.getDocumentInterface();
// var entityId = given entity ID
// var tolerance = specific value or nothing for RS.PointTolerance
// var layerId = restricted to be on the given layer ID or nothing for any layer
var connectedEntities = doc.queryConnectedEntities(entityId, tolerance, layerId);
di.selectEntities(connectedEntities, false)
Details:
https://github.com/qcad/qcad/blob/maste ... Contour.js
https://qcad.org/doc/qcad/3.0/developer ... c737669802
https://qcad.org/doc/qcad/3.0/developer ... a1be59fbe4
The idea is then to query all entities of your drawing.
Cycle the ID's one by one
Exclude some like Points .. Texts .. Dims ....
Retrieve the connected ID's.
Sum the individual lengths of the connected ID's for CSV export. (Here selections isn't required)
Exclude connected ID's from further cycling.
Regards,
CVH
Re: Get all contour lengths
Hi @CVH,
thanks for your detailed reply.
A script that gives the same output as the UI function is totally sufficient.
I tried to create a script using your sample and guide.
Now i am able to iterate through every entity and for each entity get the
connect entities. For each connected entity i write the id and draworder in a text file.
Here i noticed that the parameter of the function "queryConnectedEntities" are completely ignored.
I just outputs every entity. Do you have a working sample that uses this function?
Besides that i am missing a way to get the length of an entity. Using entity.length just writes "undefined" in the text file.
Thanks for you help.
greetings
Max
thanks for your detailed reply.
A script that gives the same output as the UI function is totally sufficient.
I tried to create a script using your sample and guide.
Now i am able to iterate through every entity and for each entity get the
connect entities. For each connected entity i write the id and draworder in a text file.
Here i noticed that the parameter of the function "queryConnectedEntities" are completely ignored.
I just outputs every entity. Do you have a working sample that uses this function?
Besides that i am missing a way to get the length of an entity. Using entity.length just writes "undefined" in the text file.
Thanks for you help.
greetings
Max
Re: Get all contour lengths
Draw order serves for ... ?
I think you have more specific info with handle than with order.
The order of things may change after file close revert.
(Also ... id's may change between queries)
tolerance can be ignored and then RS.PointTolerance (=1e-9) is used OR provide in a more suited tolerance ... A value.
layerId can be ignored for allowing all layers OR should be a valid layer id to restrick.
e.g. the entity layer itself:
Code: Select all
var doc // a reference to the document in question
var e_id // the entity id by any means
var entity = doc.queryEntity(e_id); // query the entity by id
var l_id = entity.getLayerId(); // returns the layer id of the entity
Nope, surely Andrew has a working method, presumed a recursive one.
I only gave my idea on how one could implement it ... Rather coarse ... All depends on what the expected contours are.
... How many and what shapes there are involved ....
Besides that, I provided the related sources for documentation.
.length is something assosiated with strings ... arrays ... the lenght of an array.
https://www.w3schools.com/jsref/jsref_length_string.asp
https://www.w3schools.com/jsref/jsref_length_array.asp
.getLength() is in general the actual length of an entity, shape, ....
Enter 'getLength' in the search here: https://qcad.org/doc/qcad/3.0/developer/index.html
'length' would not return many hits
Regards,
CVH
Last edited by CVH on Fri Aug 27, 2021 12:16 pm, edited 1 time in total.
Re: Get all contour lengths
Hello,
thanks for the information. I finally got it running.
thanks for the information. I finally got it running.