Dear Support
I'm trying to create a script that cleans DXF files automatically, for our internal process.
Part of our cleaning operations require to delete duplicate entities, I would like to do this automatically on a jvscript but I cannot find any reference of "Detect Duplicates" on https://www.ribbonsoft.com/doc/qcad/3.0/developer/ or in https://github.com/qcad/qcad/tree/v3.23.0.9/scripts
Can you point me out to the right documentation or if this is possible to do in JS?
Best Regards
Daniel Hung
System Information:
OS: Windows 10 Pro 64bit
QCAD Version: QCAD Professional 3.23.0.0 (3.23.0)
How do I run "Detect Duplicates MD" programatically?
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
-
- Junior Member
- Posts: 10
- Joined: Thu Nov 14, 2019 4:15 pm
Re: How do I run "Detect Duplicates MD" programatically?
It's part of QCAD Professional.
You can invoke it like this:
The function signature is:
You can invoke it like this:
Code: Select all
var cadFileName = "in.dxf";
var outFileName = "out.dxf";
var tolerance = 0.0001;
var doc = new RDocument(new RMemoryStorage(), createSpatialIndex());
var di = new RDocumentInterface(doc);
if (di.importFile(cadFileName) !== RDocumentInterface.IoErrorNoError) {
print("Cannot import file:", cadFileName);
return;
}
Duplicates.findDuplicates(di, true, tolerance, 0.0, true);
// delete duplicates:
var counter = doc.countSelectedEntities();
var op = new RDeleteSelectionOperation();
di.applyOperation(op);
if (!di.exportFile(outFileName, "DXF R27")) {
qWarning("Export to file failed: ", outFileName);
}
else {
print("Deleted: " + counter);
}
di.destroy();
Code: Select all
/**
* Find duplicate entities.
*
* \param di RDocumentInterface
* \param allLayers True: compare entities across different layers
* \param distanceTolerance Tolerance (maximum distance between two points to be regarded as identical)
* \param angleTolerance Angle tolerance (maximum angle between two lines to be regarded as identical)
* \param reversedIsSame True: ignore direction of entities when comparing
*/
Duplicates.findDuplicates = function(di, allLayers, distanceTolerance, angleTolerance, reversedIsSame) { ... }
-
- Junior Member
- Posts: 10
- Joined: Thu Nov 14, 2019 4:15 pm
Re: How do I run "Detect Duplicates MD" programatically?
Which module library Duplicates is?
in my script I have
include("scripts/library.js");
include("scripts/simple.js");
and I get an error when running:
Duplicates.findDuplicates(di, true, 0.001, 0.001, true);
Warning: RScriptHandlerEcma::eval: script engine exception: "ReferenceError: Can't find variable: Duplicates"
Warning: "main() at C:\\qcadModules\\main.js:51\n<global>() at C:\\qcadModules\\main.js:63"
Warning: At least one uncaught exception:
Warning: "main() at C:\\qcadModules\\main.js:51\n<global>() at C:\\qcadModules\\main.js:63"
13:58:09: Debug: "<global>() at 51"
in my script I have
include("scripts/library.js");
include("scripts/simple.js");
and I get an error when running:
Duplicates.findDuplicates(di, true, 0.001, 0.001, true);
Warning: RScriptHandlerEcma::eval: script engine exception: "ReferenceError: Can't find variable: Duplicates"
Warning: "main() at C:\\qcadModules\\main.js:51\n<global>() at C:\\qcadModules\\main.js:63"
Warning: At least one uncaught exception:
Warning: "main() at C:\\qcadModules\\main.js:51\n<global>() at C:\\qcadModules\\main.js:63"
13:58:09: Debug: "<global>() at 51"
Re: How do I run "Detect Duplicates MD" programatically?
You can find a list of all scripts and their location under Help > About > Scripts.
You may want to copy that list and paste it into a text editor to make it searchable.
Duplicates scripts/Pro/Modify/Detection/Duplicates
This entry means that you you have to include scripts/Pro/Modify/Detection/Duplicates/Duplicates.js
You may want to copy that list and paste it into a text editor to make it searchable.
Duplicates scripts/Pro/Modify/Detection/Duplicates
This entry means that you you have to include scripts/Pro/Modify/Detection/Duplicates/Duplicates.js