Struggling with 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
Kalera
Registered Member
Posts: 2
Joined: Fri Jul 31, 2020 5:38 pm

Struggling with scripting

Post by Kalera » Fri Jul 31, 2020 5:46 pm

Hi everyone,

I've been trying to write a script for the past few days but can't seem to get it done. Here's what I have right now:

Code: Select all

include("simple.js");
openFiles(['C:/Users/K/Documents/plate.dxf'])
var doc = getDocument();
var selection = doc.selectAllEntities()
What I'm looking to create is a script that does the following steps:
- open a file (preferably as an argument when calling it from the terminal)
- Select all the entities from the drawing
- Check for duplicates
- Delete the duplicates
- Return the total length of the remaining entities.

I've been able to do this using the command box at the bottom of QCad, but can't seem to get it done with a script.

Scowering the documentation and this forum has gotten me a bit further but I'm stuck.

Could anyone point me in the right direction?

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

Re: Struggling with scripting

Post by andrew » Sat Aug 01, 2020 10:45 am

Documents are unaware of the attached graphics views. Operations on documents will not update the views. So things do happen but you won't see it.

Try:

Code: Select all

include("simple.js");
openFiles(['C:/Users/K/Documents/plate.dxf']);
var di = getDocumentInterface();
var selection = di.selectAll();
See also:
https://www.qcad.org/doc/qcad/latest/de ... asses.html

Kalera
Registered Member
Posts: 2
Joined: Fri Jul 31, 2020 5:38 pm

Re: Struggling with scripting

Post by Kalera » Mon Aug 03, 2020 8:29 am

Thanks for your reply @andrew .

This indeed updates the view, thanks!

I can't find the two remaining functions that I want to use in the documentation.

I'd like to call the "detect duplicates" function. See: https://www.qcad.org/doc/qcad/3.4.6/ref ... es_en.html

And also call the "Total lenght of selection" function. See:https://www.qcad.org/doc/qcad/3.1.0/ref ... th_en.html

I can't seem to find either of these in the developer documentation.. Is it possible to call these from a script?

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

Re: Struggling with scripting

Post by andrew » Mon Aug 10, 2020 8:44 am

Total length:

- find / query all entities
- call getLength for each entity
- sum up all lengths


Find duplicates:

Code: Select all

var ids = Duplicates.findDuplicates(di, allLayers, distanceTolerance, angleTolerance, reversedIsSame);
Parameters:
di RDocumentInterface
allLayers True: compare entities across different layers
distanceTolerance Tolerance (maximum distance between two points to be regarded as identical)
angleTolerance Angle tolerance (maximum angle between two lines to be regarded as identical)
reversedIsSame True: ignore direction of entities when comparing

Returns:
IDs of duplicate entities found

Post Reply

Return to “QCAD 'How Do I' Questions”