Third party cookies may be stored when visiting this site. Please see the cookie information.

PenguinTutor YouTube Channel

Creating Laser Cut buildings in Python Code

I'm working on a project to design model buildings using code. The idea is that you can create template files which describe the building using JSON. Those can then be loaded into the application, tweaked for the particular design, scaled to the appropriate model railway scale and then saved as and SVG file ready for further tweaking in InkScape, or that can be sent straight to a laser cutter.

Laser cut sheds for a model railway, one in G-Scale, one in OO, both created using software code

Designing a model shed in 2000 lines of code

This video explains the first steps of my program to reach the point where it could generate the files needed for laser cutting the two sheds. These are created using the same template file, but one is outputted for OO scale (1:76.2) for a typical indoor model railway, the other is outputted for G scale (1:22.5) for a garden railway.

I explain about some of the decisions that I had made and how I've actually written much more code, which due to the agile style of programming was subsequently discarded when I refactored the code.

I also researched various techniques including how to add interlocking tabs, understanding the point-in-polygon and intersecting line principles needed to determine where I should exclude elements of the etching. One thing that I also looked into was creating a simple tokenizer. In my case this enabled the use of variables within an otherwise static JSON file.

Tokenisers are often used in compiler design (which is where I based the idea on), but are also used in the large language model (LLM) AI systems used the Chat GPT etc. Whilst this is a long way off using any form of artificial intelligence it's useful to learn some of the basic elements used.

I also looked at some of the different software design patterns and made use of the factory design pattern for generating classes for the different features of the laser cutter output.

Source code

The source code is available from github on the link below. Please note that this is an early phase in the development of the code, so there are likely to be significant changes in the future.

More 3D printing related guides and tutorials

There are more guides to creating 3D models and use of a 3D printer at Penguintutor 3D design and 3D print projects

To find out about the updates please:
Subscribe to the PenguinTutor YouTube Channel
Follow @penguintutor on Twitter

Previous Model railway departure sign (RPi)
Model railway departure sign (RPi)
Next Model Railway Lighting
Model Railway Lighting