A Python script to create a Camotics CNC Simulator machines from X3D .xhtml files.
Camotics is an awesome open source CNC simulator/gcode cut viewer capable of displaying a small variety of consumer machines while simulating machine operations. Unfortunately, Camotics lacks native tools/interfaces to import your own machine designs. (See:CauldronDevelopmentLLC/CAMotics#403)
I wanted to create a model of a wooden CNC machine at my local makerspace Workshop 88 for use in Camotics but there is no built into the program to make additional machines so I hacked this Python script together to read X3D .xhtml files I create in FreeCAD and write the necessary files for Camotics.
The machine files have the same filenames as their names in Camotics making them easy to find in the file system. In Windows I found mine in C:\Program Files (x86)\CAMotics\machines, which requires Administrator privelege to access. Machines are defined by two files, a .json file describing the machine and its parts, and a corresponding proprietary .tco file containing geometry for all the parts (points, lines, triangles). Both files are text and were straight forward to reverse engineer.
I chose X3D .xhtml as the input format because it contains triangles and edges (unlike STL), it is XML based, and it is visible in a browser to verify correct output from FreeCAD. I think any .xhtml file should work from any source so long as the parts of the machines are separate Shapes (though too many Shapes may be unwieldly to configure). Unfortunately X3D .xhtml is an extremely flexible format with deeply nested groups of elements and some referencing resulting in a script that may "work on my machine" or "work on my file" and maybe not yours, though I did my best to make it general purpose and document the code should you try to extend/repair it.
python camotics_machine_maker.py filespec.xhtml
This will parse filespec.xhtml then generate filespec.json, and filespec.tco in the same location as filespec.xhtml. The script will silently overwrite preexisting files.
Note: filespec.json will require additional manual editing to tell Camotics which components move with X, Y, and Z movement of the tool in the simulated gcode. See /example/data/Camotics for detailed instructions.
python src\camotics_machine_maker.py "example\data\Wooden CNC.xhtml"
This will run the included script on the included example data to recreate the .json and .tco files in the example\data folder. This can be used to validate the script works on your machine and generates output that agrees with the files in source control.
To install a machine in Camotics:
- Copy your
.jsonand.tcofiles to the directory containing the other Camotics machines. On my Windows machine that isC:\Program Files (x86)\CAMotics\machines which will require Administrator privileges. - Start (or restart) Camotics.
- Be sure to enable
Toggle Machine Display
- Go to
Settingsfrom thetoolsmenu
- Select your machine from the dropdown list and click
Save
- Test your machine by running the default or your own gcode to verify the parts are moving correctly and iterate if necessary.
- Workshop 88 Wooden CNC FreeCAD source files

- Workshop 88 Wooden CNC exported at .xhtml with the output of the script

- Output files modified for correct motion

I can't wait to see machines like MPCNC, and silly stuff like Hello Kitty, and NutterButter CNC machines crazy internet people make for Camotics!