QCAD Scripting

Rambler

Active Member
(Firstly, a paragraph of background info)
Last October the North London Group meeting featured a presentation on Laser Cutting and 3D printing by Tim and Terry of the Princes Risborough club. As a result I’ve downloaded the recommended software, Fusion360, to see how I get on with 3D modelling, and joined a maker space that has a laser cutter. Playing around with the “home” version of Fusion360 I was impressed by its capabilities - much easier to use than TurboCAD, and not restricted like OnShape. One particularly interesting aspect was the use of Dimensions to parameterise drawings, i.e. if you change a value in the dimensions table then the drawing gets re-drawn using that dimension. However, this can be a bit tricky as (a classic problem) the tool will only change things according to what you’ve told it, which may not be necessarily everything you want. And working out what the tool needs to know in order that all the things change in the way that you want isn’t always straightforward. As it happens, in 3D modelling I’m at a very early stage and can get by without being able to parameterise designs.

The ability to change designs by modifying parameters, as found in Fusion360, set me thinking about its application to artwork for etching (in brass or nickel silver). So I checked out whether any of the CAD packages that I use for 2D drawing (Autosketch, TurboCAD, QCAD) had a parameterisation scheme, but drew a blank. However, I discovered that QCAD has a scripting interface. This is a different concept but I think it can deliver something like the same capability.

This scripting interface is revealed via the menu : Misc/Developer/Script Shell.

So I started with some experiments, one of the early ones being this :

function draw_box(bottom_left_x, bottom_left_y, width, height) {
addLine(bottom_left_x, bottom_left_y, bottom_left_x, bottom_left_y + height)
addLine(bottom_left_x, bottom_left_y + height, bottom_left_x + width, bottom_left_y + height)
addLine(bottom_left_x + width, bottom_left_y + height, bottom_left_x + width, bottom_left_y)
addLine(bottom_left_x + width, bottom_left_y, bottom_left_x, bottom_left_y)
}

function three_boxes(centre_x, floor_y) {
// draws three boxes width 5 at centres : C - 8, C, C + 8
draw_box(centre_x -10.5, floor_y +10, 5, 10)
draw_box(centre_x - 2.5, floor_y + 11,5,9)
draw_box(centre_x + 5.5, floor_y + 10,5,10)
}

three_boxes(20,20)
three_boxes(50, 20)
three_boxes(80,20)
three_boxes(115,20)

If you have QCAD and want to try this, just cut and paste this text into the script command line.

This produces the design shown below

Screenshot 2020-02-15 at 19.32.58.png
 
Last edited:

BrushType4

Western Thunderer
This is a powerful feature of QCad and I’ve been meaning to make my own scripts to save time but haven’t had the time!

The great thing too, the best scripts get added in to annual QCad updates
 

Rambler

Active Member
In the first post I showed an arrangement of rectangles typical of a carriage side. Having established that scripting worked I then found an example of a prototype carriage to see whether this worked for real vehicles. I cheated in selecting an NER vehicle with square cornered panelling, a Diagram 132 brake third (or Van Third in NER parlance). I had previously photographed the GA (Darlington C&W drawing 6128) at the NRM so I was able pick off the measurements.

I worked up a set of functions that would each draw a section of the carriage side. I wanted each function to draw complete sections and complete panels; this is why compartments are drawn as window pairs and doors - under each window pair there is a single long waist panel that I didn’t want broken into parts.

The sequence of function calls was as follows:

// Start by drawing the outline of the side,
// plus the lowest edge of the waist beading, which runs continuously (except where there is a ducket)
draw_box_a(datum_h, bottom_of_side, datum_h + overall_length, top_of_side)
// Draw a line along the bottom of the waist beading
addLine(datum_h, waist_lower_bottom, datum_h + overall_length, waist_lower_bottom)

//
draw_panels(0, 1.3, 2, 8.90)
draw_guards_doors(21, 28.4, 2, 0)
draw_panels(49.4, 0.9, 2, 8.90)
// Gap here for the ducket.
draw_panel_and_window(86.15, 0.9, 1.4, 10.2)
draw_door(100.45, 14.70) //Compartment 1
draw_window_pair(115.15,10.2, 3.8, 10.2)
draw_door(142.85, 14.70) //Compartment 2
draw_window_pair(157.55,10.2, 3.8, 10.2)
draw_door(185.25, 14.70) //Compartment 3
draw_window_pair(199.95,10.2, 3.8, 10.2)
draw_door(227.65, 14.70) //Compartment 4
draw_window_pair(242.35,10.2, 3.8, 10.2)
draw_door(270.05, 14.70) //Compartment 5
draw_window_pair(284.75,10.2, 3.8, 10.2)
draw_door(312.45, 14.70) //Compartment 6
draw_window_and_panel(327.15, 10.2, 2.55)

and the drawing produced is shown below.
Screenshot 2020-02-19 at 11.46.41.png
Please note that this drawing isn’t finished, its just produced to show what can be achieved. To complete the artwork (e.g. for etching) I might need to adjust dimensions to account for etch undercut, and would add door handle pads, hinge slots, etc. The really neat thing is that any modifications, e.g. to add hinge slots to the doors or to adjust the depth of the waist panel, will get automatically included the next time the drawing is generated.
 

BrushType4

Western Thunderer
That’s good, in fact awesome as it shows what is possible but it seems like overkill Have you looked at blocks? That will do the same and a lot quicker to do?
 
Top