CNC script for Datron M8 - under development
I posted a couple of threads here to help me along the way, but since I today got a working script done, I decided to post a new thread to keep everything gathered. Please check "Point3D to coordinates" and "Add a Command" for previous bits and pieces.
I am trying to make a simple script that will take a selected curve and based on that generate a MCR script that can be used to control Datron CNC Mills. Of course anyone familiar with their own CNC scripting, such as G-code, can easily adapt the script.
This is because sometimes I need something that will run those idiotically simple milling operations that are near impossible to program on the CNC or with traditional CAM software, which are easier to use but harder to control. I don't see this script becoming a tool for everyone, but another tool in the box for some of us.
Please note that I am a complete novice in Python, so the code is very messy and not very optimized. I am sure I have made every programmers heart weep by making the code unreadable, but I have tried my best to comment. Also note that quite a bit of the code is adapted from Steves code posted on this forum, a big thank you.
Right now, you can select a curve, define how many sections the curve is divided into and output a list of valid Axyz commands to the Command History Window, with the origo defining the zero point. The script also solves the highest Z of the curve, adds 15mm and uses this as the safe height for both engage and retract.
- No start block, meaning no controls over Feeds, toolnumbers, RPM or anything else. Ideally this would be decided by the user by either tool data or by manually entering the info, but a simple hardcoded block should be easy.
- Currently only works with mm, i think. And the Datron needs to be set to mm as well.
- No saving the MCR script, except from the Command History dialogue
- No multiple curves
- The Command Histroy window only shows 80 lines or so, perhaps not enough for the whole machine code.
- The coordinates should always have 3 decimals, as some machines require this, but rounding 0.000000000001 and using str() results in 0.0, dont know what to do.
- Messy, Messy code. Should write everything into neat little functions that return the required values.
Anyway, I am including this here and I will try to update it as I get the time. If someone wishes to participate, I welcome all help, and if someone (except me) learns something from this, all the better. I take no responsibility if someone runs their mill into their toolbox, If you cant read MCR or G-code and check the output, don't use it.
All the best,
Last edited by aalto; 05-09-2010 at 07:43 PM.
Thanks for posting this. I modified your script to write values to 3 decimal places and optionally write to a text file. I can't really test the script properly since I don't have one of these machines, but it should be enough to get you a little further along on writing these files.
Originally Posted by Steve Baer
I think I get the new code pretty well, and I just noticed a problem with writing the output to the command history, as saving it from there and compiling it in a text editor will usually result in extra steps since windows wants to save everything as RTF from Textpad or Wordpad, another thing to rememeber, so no good.
I also changed the rs.OpenFileName() to rs.SaveFileName() as I usually don't have a rewritable script file handy =)
I will try to add the start block next and get that working, but I already tried milling out a some simple curves with the script, 3dm file and a picture of the test is included.
I noticed that it would be very nice to get the tolerance values from the script after a while to see how much corners you are cutting, perhaps generate a line between all the points, but I will get to that eventually.
This python stuff is getting way interesting =)
All the best,
Oops, yes it should have been SaveFileName. Here's a new version that doesn't perform the rounding until right before the point is being sent to the output. Doesn't make any real difference, but it does seem to clean the script up a bit to make it more readable.
Yes, that was a lot easier on the eyes.
I included a ComboListBox to select between Datron MCR script and G-code output. Seems to work fine, but the coding is a bit messy for now. I will look at moving this to an external post-processors file later so it can be more easily updated. Also if someone wants to try Gcode output, check the code as it has no feed parameter or startblock, i.e. you have to add your own.
Also, since you are on the development side, please tell the team that the ListComboBox is very ugly on OS X =)
And a request also: a MessageBox() that uses the Rhino UI, not the OS UI where you could simply ask a yes or no question (i.e. Do you wish to generate a startblock for this machine code?) or a Rhino checkbox type of UI box, where you could tick for different options. Ideally you could set a lot of parameters like feed, rpm and such from one slick window, instead of answering an "endless" line of dialogboxes (i.e. please enter the RPM, please enter the Feed, etc).
Thanks for all the help.
The one I think I am after is a slick RhinoUI PropertListBox(). You could set all the values needed for the startblock there.
I'm new to Rhino and installed MakeToolPath_cmd.py the way you described it. How can I now execute the "MakeToolPath" command? I went to Tools --> Commands but didn't find it. When I did a Search for it, it wasn't found...
Also, for verification purposes which freeware 3D g-code viewer for Mac would you recommend? I'm looking for a tool that gives a little animation or so.
The command will only be installed to the command prompt so you have to type it in, it is not available through menus or icons. Just type "maket" and it should be on the list.
In regards to the G-code viewer, I use MCR on the machine I use and I just read the code to check things are peachy, so I have no idea what G-code viewer you should use, nor have ever seen one for mac. So tough luck there. The code outputs absolute values, so you could just try it out on a small soft piece (foam or something) and just read the code to check the values seem reasonable before milling, you should be ok. Remember it doesnt make a start block with feeds and such yet, so you have cut'n'paste those from somewhere. I will get around to that during the weekend. Please do post about how it all turns out.
Is there any possibility to use standard modules like cPickle in Rhino, trying to look at storing the post-processor data and toll-data into separate files.
Sure. You can use cPickle and regular old file objects in python
Tags for this Thread