Laying out contours for laser cutting with Python

So I’m still fairly new to this all so pardon if I’m asking bad questions. I’m using Rhino Python Editor and I’m trying to create a script (while also learning to script a bit) that will essentially contour any closed polysurface model at an interval of choice, Orient the curves to the C plane or some other plane so they are all together (as if I ran Make2D) and then arrange them so that they are in a line, in order, with a small gap between them.

It gets really messy with the whole organizing of object IDs in the big for loop… I gave it a shot tho.

I can already see there are some sloppy workarounds not to mention just some stuff that just isn’t working… but I just dont know the alternatives. Please provide any ideas you have for bridging the gaps and/or cleaning it up

Thanks so much!

edited with updated script
Contour Model Updated 1.py (1.2 KB)

Thi @lmboyer04,

This from the Rhino.Python help:

import rhinoscriptsyntax as rs
obj = rs.GetObject("Select object", rs.filter.surface + rs.filter.polysurface)
startpoint = rs.GetPoint("Base point of center line")
endpoint = rs.GetPoint("Endpoint of center line", startpoint)
distance = rs.Distance(startpoint, endpoint) / 10.0
rs.AddSrfContourCrvs( obj, (startpoint, endpoint), distance)

Just another option…

– Dale

Thanks, helps with the contour part. Any ideas for how to pull off the moving of the contour curves/projecting and arranging them?

From the script I can tell that you have literally no clue what you are doing, so I think a better start is to go through the RhinoPython 101 / python primer:

https://www.rhino3d.com/download/ironpython/5.0/rhinopython101

Also this:

Well yes, I am new to this, but its not like I haven’t tried. We start from somewhere no? Was hoping for some more concrete feedback other than just pasting basic links… I would have nothing right now if I hadn’t searched on my own and tried/changed/failed at things. That’s why I’m here asking for help. But I dont blame you, I’ll ask some more specific questions then…

Super basic version I was working on before the version you saw: Its only a copy and move command (that I plan to use as a part in the larger script for my project), but obviously I’m not understanding something because it’s not working. What I think I’ve told it to do it copy an object, and then start moving it by one unit until it is no longer within the bounding box of the first object. I’ve tried a bunch of variations of this using both while and for loops and changing the rest of the script. Always returns one of two results: keeps moving it infinitely, or only moves it once (so it is the copied 5 units + moved 1 units away from the original object)

Any specific insight on what I am missing?

import rhinoscriptsyntax as rs

BaseObject = rs.GetObject("Select object for contour", rs.filter.polysurface)
BaseCopy = rs.CopyObject(BaseObject, (5,0,0))

while True:
    test = rs.IsObjectInBox(BaseCopy, rs.BoundingBox(BaseObject))
    rs.MoveObject(BaseCopy, (1,0,0))
    if test==False:
        break

Haven’t looked at the script, but I have done this type of thing in the past. One of the things that helps is to lay out the logic diagram of the script before starting. I found that if in the loop you do one contour at a time then move the results to the correct position flat on the layout, it’s easier to work with than doing all the contours at once. So the logic looks something like this:

  1. Get all the objects involved
  2. Get the bounding box and the Z minimum / total height
  3. Establish a view direction and contour (slice) the objects at the lowest level
  4. Get the resulting contours and move them to the layout initial base point (remap if necessary)
  5. Get the bounding box of the contours on the layout and the X max coordinate
  6. Add the spacing between layouts to the X coordinate above, make it your new layout base point
  7. Loop, increment the slice level in the contouring operation each time until the max height is reached.

Note that if you wish to contour both mesh and surface objects, you will need to differentiate between them and send each to a different operation depending on object type.

–Mitch

it makes no sense to help you this way, that’s why posting these links is the only option: start learning python first… The things you were posting were mixes of python and RhinoScript and things copied from the web. That’s why I said: you have no idea what you are doing, so you really need to start from the beginning which is the thing I and @AndersDeleuran have posted. The only way I could help you now is by pointing you at the right starting point (the links we posted) or completely write the script for you. Based on what you posted it makes no sense to correct it because it’s a mixed soup. :slight_smile:

I think probably what you want in the second script is this:

import rhinoscriptsyntax as rs

BaseObject = rs.GetObject("Select object for contour", rs.filter.polysurface)
bb = rs.BoundingBox(BaseObject)
vect = rs.VectorCreate(bb[1], bb[0])
BaseCopy = rs.CopyObject(BaseObject, vect)