Page 1 of 1
Help with making a script file
Posted: Wed Feb 03, 2021 1:56 am
by John Hyslop
Hi All
Years ago I used to make very basic lisp files to do very very basic tasks, can anyone help me with this
Attached is the lisp routine :- and before anyone says yes there is probably a better way to make the lsp file
and also return osnaps to previous settings
All i want to do is select and Arc or even better window select arcs and turn them into circles.
There is a problem when sometimes exploding blocks circles become 1 arc with a start point 0
and end point 360, Qcad displays these arcs and one can assume they are circles, but when loading
the dxf into CNC software it displays as a Dot, likewise in AutoCad a dot / zero length arc
Thanks for any help in advance
Cheers
John
PS I didn't know how to insert it as code

it kept saying Spam Detected , here is a screenshot
if you don't want to download the zip file..

- A2C..png (29.68 KiB) Viewed 4937 times
Re: Help with making a script file
Posted: Wed Feb 03, 2021 5:41 am
by CVH
Hi John,
Already a while QCAD doesn't explode circles to 1 full Arc but in two 2 semi full Arcs.
A Polyline that is.
Recently, explosion of circles is made optional in App.Prefs.
Below you'll find a script for full Arcs to Circles:
Regards.
CVH
Code: Select all
// Full Arcs to Circles script by CVH
var doc = getDocument();
var di = getDocumentInterface();
var arcsCollected = [];
// Retrieve the selection:
var ids = doc.querySelectedEntities();
// Terminate without selection:
if (ids.length === 0) {
EAction.handleUserWarning("Nothing Selected! Script terminated.");
return;
}
// Filter full Arcs from selection:
for (var i=0; i<ids.length; i++) {
// Get entity from the document:
var entity = doc.queryEntity(ids[i]);
// Collect when exist and is full Arc:
if (!isNull(entity)){
if (isArcEntity(entity)) {
var arcSweep = Math.abs(entity.getSweep());
if (RMath.fuzzyAngleCompare(arcSweep, Math.PI*2.0)) {
arcsCollected.push(ids[i]);
}
}
}
}
// Terminate without full Arcs in selection:
if (arcsCollected.length === 0) {
EAction.handleUserWarning("No full Arc entities selected! Script terminated.");
return;
}
// Setup an operation:
var operation = new RModifyObjectsOperation();
operation.setText("Full Arcs to circles");
// Process collected Arcs
for (var i=0; i<arcsCollected.length; i++) { //Cycle collected Arcs
// Get full Arc from the document:
var fullArc = doc.queryEntity(arcsCollected[i]);
// Create a new Circle entity:
var newCircle = new RCircleEntity(
doc,
new RCircleData(
fullArc.getCenter(),
fullArc.getRadius()
)
);
// Add the new Circle to the operation:
operation.addObject(newCircle, false, true); // NOTuseCurrentAttributes, DOforceNew
// Mark the full Arc to delete:
operation.deleteObject(fullArc);
} // Loop Arcs
// Apply all modifications:
di.applyOperation(operation);
// Finished:
var msg = "Created " + arcsCollected.length + " Circle entity/ies."
EAction.handleUserInfo(msg);
EAction.handleUserMessage("Script ended.");
return;
Re: Help with making a script file
Posted: Wed Feb 03, 2021 7:45 am
by John Hyslop
Thanks CVH
I'll try later, Yes i just tested explodes to 2 arcs that's fine for cnc, I must of seen this in a previous version of Qcad...
Cheers
John
Re: [ Solved ] Help with making a script file
Posted: Wed Feb 03, 2021 8:21 am
by John Hyslop
Hi CVH
As you know I don't know much about Java scripting
I copied your text and saved it in a file a2c.js
made a folder under Scripts/Misc/c2a
and placed it there but Qcad won't run unless I remove it
Could you explain how and where i put this file so I can use it in the Qcad UI ? is it a Java script file?
I don't know
Cheers
John
Re: Help with making a script file
Posted: Wed Feb 03, 2021 9:16 am
by CVH
John Hyslop wrote: ↑Wed Feb 03, 2021 8:21 am
Could you explain how
Sure,
It is not a GUI action ...
... with a button.
(If you want that ...

)
Make selection.
Open Script Shell (GE)
Copy all.
Paste.
Saved as a *.js file
Make selection.
Run Script (XC) ...
Regards,
CVH
PS:

Herrinbore seed for BHT ready

Re: Help with making a script file
Posted: Wed Feb 03, 2021 9:33 am
by John Hyslop

Herringbone.. I bet I won't understand the equation and not be able to add

Looking forward to the maths, I bet it's a beauty..
Cheers
John