algorithmic modeling for Rhino
Tags:
I have a project that needs this too, did find this today:
https://gist.github.com/j0hnm4r5/b834d6a845a822257818/revisions
Cheers
DK
So - did some work on this last night - my version attached.
The original code changes the model units to inches which I've commented out.
I've also made it output in Absolute units in the PLT file - it which sorted out some strangeness in how the printer was moving.
To actually get it to the printer I'm using a freeware spooling software called PrintFile - which is running in the background on my machine - as soon as it sees a PLT file in the folder C:/spool it dumps the txt file onto the USB printer port my vinyl cutter sits on.
Next thing I want to look at is get Python to send the file directly to the printer port and avoid the spooling software. ### ANY TIPS ON THAT??### I'm really new to this Python code thing.
I do have a bit of issue with cutting fonts too - the curves all get out of order so it cuts 'pieces' of each letter in a random sequence rather than the complete each curve in one cut. Sure I'll find a way to fix that too.
VERY stoked I got this working.
The idea is to have a 'send to cutter' icon on my Rhino tool bar and not have to deal with any 'cutting' or 'signwriting' software.
Cheers
DK
OK - just to make sure everything I've done is in the right thread and updated.
Latest Python Script attached.
A couple of mod to my system to get it to dump the file to the printer:
import os
os.system('copy /b c:\spool\spool.plt LPT1')
Printer is actually on a USB port but all I needed to do was share the printer on the network and use this command line:
C:\spool>net use lpt1: \\DECAY\DGIP /persistent:yes
To make it use LPT1 port.
Cheers
DK
Hey David, not been here for a while! And I haven't had chance to look into your py yet. But I have some code that may be of interest> if any use? Its .PLT (HPGL) coding for a specific plotter and a RVB post processor.
I wanted to Update to work better on Rhino 5 and with a ZUND L-1200 + CVE12 Or a Bulmer cutter. Using the right tool addresses and go through the correct ports? Using Generic Printer for the Windows Driver base.
Let me know what you think and if your script might be the right way for me to go... i.e. To send direct from GH to the Plotter/Cutter... I would have to isolate two tools as noted in the scripts attached.
Your thoughts welcome.
I've also got an RVB that does the process - almost.
J
Hi John,
Great to hear from you - I actually think I found your Python code on Github:
https://gist.github.com/j0hnm4r5/b834d6a845a822257818
Really all I've done is cleaned your code up a bit for my own use and added the command line port LPT1 port dump.
I found a couple of strange things in your code:
# Changes the model units to inches, but does not scale model.
rs.UnitSystem(unit_system=8, scale=False)
Why did you change the model units here? HPGL units are 40 per mm (which is also 1016 per inch) staying in mm units in your model will be fine if your step scaling in right.
And doing this seems strange for a cutting program:
allCurves = rs.ObjectsByType(4)
for curve in allCurves:
if (rs.CurveDegree(curve) == 2 or rs.CurveDegree(curve) == 3) and rs.IsPolyCurve(curve):
rs.ExplodeCurves(curve, True)
allCurves = rs.ObjectsByType(4)
Cutting usually needs a closed curve to produce a nice clean removable piece from the material. Your approach results in a bunch of line/curve segments instead of closed polycurves/polylines. As this simulation shows the 'O's and 'R' are cut as a collection of curve segments - not closed polycurves:
I just removed this step from the code.
As this simulation shows every part of the font is cut in one cut action - exactly what I needed:
I saw your RVB code on the RhinoScript site too - was way more detailed than I needed - my vinyl cutter only has one 'pen' - the cutting blade. I just needed a really basic way of getting polycurves into HPGL format and firing it out to a printer port.
Thanks for your help on this little project - I'm very stoked at the result! Let me know if I can help with your cutter project.
Cheers
DK
Its in a phase of works Ive coming up and you might be able to help yes.
get in touch:
designpartners(a)gmail-dot-com
Looking at your RVB code - could you not do all of that in your Python script? I'm even thinking selection of the curves by colour or layer then firing them out to each 'pen' in turn?
I'll drop you an email.
Cheers
DK
The only problems I am facing are tool selection and sending form a generic text printer. How did you send and are these scripts sophisticated enough for large scale cutters doing multiple nested items?
Hi John,
I found the Wikipedia site for the HPGL format very handy in getting this project done:
https://en.wikipedia.org/wiki/HP-GL
In the bigger picture all an HPGL file is just a text file that describes a set of machine movements in X, Y and Z (Z being Pen Up and Pen Down) directions. It very closely related to G-code in this way - just slightly more simple than G-code overall.
For tool selection you use the Select Pen - SPx - command, x is the number of the pen you are using. As I'm using a vinyl cutter without a pen/tool changer I just use SP1 in the file header/ini of the cutter.
Without knowing the full spec of your machine it is hard to say for certain BUT all of my experience with CNC machines - of all sizes and spec levels - the actual control files are pretty much the same. Very simple text based HPGL or G-code text files run all motion control - even on things like 7 axis robot arms etc. For plotting I'd expect you'd be able to get a usable HPGL/PLT file without a lot of work - its just a matter of matching the file to what the machine is expecting.
To answer your question about getting the file to the printer its maybe best to explain it this way: there are two parts to this project
1/ Create the correctly formatted text/hpgl/plt file ready to send to the printer
2/ Send the file to printer
For part 1/ the procedure is:
Select the curves you want to print
Convert the curves into a set of points
Format these points into HPGL
Save this HPGL as a text file
For 2/ we need a way to stream the text file to a printer port
To do this I've used an old dos command line technique that allows allow you to 'copy' a text file to a printer LPT or COM port:
copy /b c:\spool\ini.plt LPT1
Type the above into a DOS command line and it will send a text file called ini.plt to the printer on LPT1 port. As you'll see in my attached code I use os.system calls in my python code to send files when needed.
So your original code was doing some strange things with the conversion from curves to points. Lines/Polylines were OK - with the code just using the line end points. For curves and polycurves the code code was exploding these into segments and then dividing into set of points. However this led to two issues:
- curves that started off as closed polycurves would end up being plotted as open curve segments - which is not very good for a cut file and not very smooth for a plot file.
- the division of the curves to points was by distance - and if this wasn't an exact division of the length of the curve the end point would not match up with the next line - again not ideal for a cutting file which needs to be a closed curve.
To solve the above I changed to using rs.ConvertCurveToPolyline - with the tolerance set to match the HPGL resolution of 0.025mm - this converts all curves needed to plot to polylines, leaves everything closed and ends points line up perfectly.
I had one other problem with my setup - I ran into a file size/curve number/plotting points upper limit. A small number of curves would cut/plot fine, however at a certain number in one file the print driver would throw an error and the plotter would not even start plotting the file. I could not work out where is the system this limit was being imposed. The current working version of my code is attached - it gets around this file size limit by creating a separate print file for each curve required and sending them to the plotter in sequence. Not as completely tidy as I'd like as it flashes up a cmd window on every loop - but plots/cuts are perfect.
The final 'nice touch' for the project is I've created a custom tool bar button to run the script - all I have to do to cut a file is hit the button on the tool bar, select the curves and hit enter = SO EASY!
I've attached my latest code, a sample HPGL file to plot a rectangle, and a screen shot of setting up the custom toolbar button.
Cheers
DK
I want to add another tool, am I right in thinking that both the HPGL coding and the converter need to be co-ordinated to assign these? And all that is required is the tool number on that specific Plotter / Cutter?
Wont windows generic text printer spool the HPGL files without doing each individually? How does that handle many multiple geometries?
p.s. Do you see an easy fix for the cmd flash? Or will this take hard coding?
J
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by