Hi,
I think you should forget about Phyton to collect data from a document with QCAD.
For that you need Phyton resources that handle the DXF, DWG or PDF content.
‘Scraping’ a document for relevant data is already more complex than you might think.
OD, BC, ID, hole size and number of holes are nothing that is stored readily available.
The first four are merely diameters, any Circle or Arc entity in a drawing has that property.
Circular shapes can be made up of arc segments, a full arc, a polyline or even an ellipse or approximated by line segments.
So, the source should be well organized to be able to retrieve data.
Taken it from the point that you have sets of valid data …
… And skipping the heuristic AI to read arbitrary customers files ![]()
Scripting under QCAD has several levels.
addLayer("OD");
addCircle(0, 0, 3);
Are instructions of the simple API (Hint: I placed them in a code display
)
The complete signatures can be found here:
Best practice is to include the base class at the top:
include("scripts/simple.js");
While the simple API is versatile and kept simple, there are a few to more limitations.
The next level would not use the simple API, a little harder but you have full control over what is done and how.
For example:
addLayer("OD");
addLayer("BC");
addLayer("ID");
addLayer("HOLES");
addCircle(0, 0, 3);
This will create 4 white layers, continuous lines, weight 0 and the last created will be the current active layer.
The circle will then be created on the layer ‘HOLES’, @(0, 0), with a radius of 3 drawing units.
Without the simple API we create a fundamental shape and turn that into a document entity and are able to set any relevant property.
The function ‘addCircle’ returns a reference to the created entity.
We could store that in a variable, best practice is to declare your variables with var … ![]()
var circle_od = addCircle(0, 0, 3);
To rotate an entity we also need a point to rotate around …
Remind that the simple API uses degrees while for the rest, radians is the common angle notation.
Is that really necessary? One could simply calculate the positions on a center circle … ![]()
… All depending on the number of holes.
The simple API has no method to save a drawing as far as I know.
I can only point you to something very simplistic:
Remark that this example acts on an off-screen document without the use of the GUI or file dialog.
And that it is ran from the OS command line.
A complete other route might be DrawFromCSV.
That would require the basic data in a spreadsheet, a list of some sort and a transformation matrix to drawing instructions for each part.
I use it to automate boring repetitive tasks like the generation of several hundreds of tag-plates in different size, with individual text.
The only downside is that I didn’t include methods to open/start or save a file … Bummer.
It was not intended to run without human interaction … ![]()
Regards,
CVH