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
Points on every intersection
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.
- andrew
- Site Admin
- Posts: 8766
- Joined: Fri Mar 30, 2007 6:07 am
Re: Points on every intersection
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:
Usage:
- Select entities to consider
- Run script
- Points are added to current layer at intersection points
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();
- Select entities to consider
- Run script
- Points are added to current layer at intersection points
-
- Newbie Member
- Posts: 7
- Joined: Sat Jul 13, 2024 6:46 am
Re: Points on every intersection
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?
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?
- andrew
- Site Admin
- Posts: 8766
- Joined: Fri Mar 30, 2007 6:07 am
Re: Points on every intersection
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();
-
- Newbie Member
- Posts: 7
- Joined: Sat Jul 13, 2024 6:46 am
-
- Premier Member
- Posts: 4872
- Joined: Wed Sep 27, 2017 4:17 pm
Re: Points on every intersection
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;
}
Regards,
CVH