Page 1 of 1

Points on every intersection

Posted: Mon Nov 11, 2024 1:52 pm
by fruit 89
Hi it is possible do draw points (automatically) on every intersection of multiple lines? (normally more than 100 intersections

Windows 10
Q CAD Professional
3.26.4.5

Re: Points on every intersection

Posted: Mon Nov 11, 2024 2:23 pm
by andrew
You can paste this script into the script shell (Misc > Development > Script Shell) or safe it as a file and run it using Misc > Development > Run Script:

Code: Select all

var doc = getDocument();
var allXps = [];

// find all intersection points of all selected entities:
var ids = doc.querySelectedEntities();
for (var i1=0; i1<ids.length; i1++) {
    var e1 = doc.queryEntityDirect(ids[i1]);
    for (var i2=i1+1; i2<ids.length; i2++) {
        if (i1===i2) {
            continue;
        }
        var e2 = doc.queryEntityDirect(ids[i2]);
        var xps = e1.getIntersectionPoints(e2);
        allXps = allXps.concat(xps);
    }
}

// add intersection points as point entities to document:
startTransaction(doc);
for (c=0; c<allXps.length; c++) {
    addPoint(allXps[c]);
}
endTransaction();
Usage:
- Select entities to consider
- Run script
- Points are added to current layer at intersection points

Re: Points on every intersection

Posted: Mon Nov 11, 2024 2:35 pm
by fruit 89
hi didnt work

Error: :-1:-1: REntity: Argument 0 is not of type REntity*. <native>(RLineEntityPointer(0x6ac65ba0)) at -1 <eval>() at 8 <native>('js', 'for (var i1=0; i1<ids.length; i1++) { var e1 = doc.queryEntityDirect(ids[i1]); for (var i2=i1+1; i2<ids.length; i2++) { if (i1===i2) { continue; } var e2 = doc.queryEntityDirect(ids[i2]); var xps = e1.getIntersectionPoints(e2); allXps = allXps.concat(xps); } } ') at -1 <anonymous>(expression = 'for (var i1=0; i1<ids.length; i1++) { var e1 = doc.queryEntityDirect(ids[i1]); for (var i2=i1+1; i2<ids.length; i2++) { if (i1===i2) { continue; } var e2 = doc.queryEntityDirect(ids[i2]); var xps = e1.getIntersectionPoints(e2); allXps = allXps.concat(xps); } } ') at :scripts/Misc/MiscDevelopment/EcmaScriptShell/EcmaScriptShell.js:364 <anonymous>(command = '}') at :scripts/Misc/MiscDevelopment/EcmaScriptShell/EcmaScriptShell.js:271 <native>() at -1 main() at :scripts\autostart.js:839 <global>() at :scripts\autostart.js:852

what i make wrong?

Re: Points on every intersection

Posted: Mon Nov 11, 2024 2:43 pm
by andrew
Right. For your version of QCAD, try:

Code: Select all

var doc = getDocument();
var allXps = [];

// find all intersection points of all selected entities:
var ids = doc.querySelectedEntities();
for (var i1=0; i1<ids.length; i1++) {
    var e1 = doc.queryEntityDirect(ids[i1]);
    for (var i2=i1+1; i2<ids.length; i2++) {
        if (i1===i2) {
            continue;
        }
        var e2 = doc.queryEntityDirect(ids[i2]);
        var xps = e1.getIntersectionPoints(e2.data());
        allXps = allXps.concat(xps);
    }
}

// add intersection points as point entities to document:
startTransaction(doc);
for (c=0; c<allXps.length; c++) {
    addPoint(allXps[c]);
}
endTransaction();

Re: Points on every intersection

Posted: Mon Nov 11, 2024 2:46 pm
by fruit 89
thx :D

Re: Points on every intersection

Posted: Mon Nov 11, 2024 2:47 pm
by CVH
fruit 89 wrote:
Mon Nov 11, 2024 2:35 pm
what i make wrong?
Probably nothing.
It is a failure on QSharedPointers.

After querying e2
Add a line with e2 = getPtr(e2);

Don't understand:

Code: Select all

        if (i1===i2) {
            continue;
        }
i2 is at least i1 + 1

Regards,
CVH