Printing layer names automatically?

Hi!

I’m making CNC-programs with Rhino.

Is there a way to print layer names on drawings automatically?

Couple pictures attached. For example this picture has 24 different objects with different layers (layers are named 30.2, 30.2, 30.4 etc…)

I’m currently done couple by printing the paper and looking the layer name from properties and writing it down by hand.

I have over 600 pieces coming and I need to write number for every piece after machining… It would be quicker just to print the picture automatically. So is there a some way to automatically show layer names on Rhino’s drawing and printing the drawing?

This can be done very effieciently in Grasshopper with the Elefront plugin.

2 Likes
import rhinoscriptsyntax as rs
curves = rs.GetObjects("Select closed planar curves", 4)
for curve in curves:
    layer = rs.ObjectLayer(curve)
    centroid = rs.CurveAreaCentroid(curve)[0]
    rs.AddText(layer, centroid, justification = 131074)
2 Likes

Thanks!

Tried to use this as a Rhino Python and I get following message. I get to choose the layers and after that it gives following error. Any ideas (some error on my part?)

Message: ‘NoneType’ object is not subscriptable

Traceback:
line 5, in , “C:\Users\Mika\AppData\Local\Temp\TempScript.py”

It will depend on what your curves are like - the script above does not have any error checking and will fail if you pick open or non-planar curves - because it will not find the centroid in those cases - so it returns None.

You can try the following modification which should work for open and non planar curves and see if it works:

import rhinoscriptsyntax as rs
curves = rs.GetObjects("Select curves", 4, preselect=True)
for curve in curves:
    layer = rs.ObjectLayer(curve)
    bb=rs.BoundingBox(curve)
    center=(bb[0]+bb[6])/2
    rs.AddText(layer, center, justification = 131074)
1 Like

Hi!

Now it works. Thank you all for help!

One more question:

How to modify the code so it doesn’t print parent layer’s name? Just the final sublayer’s name should be printed.

Didn’t see this additional question… sorry. The script modification below might be what you want.

import rhinoscriptsyntax as rs

def GetLowestSublayerName(layer_name):
    split_result=layer_name.split("::")
    if len(split_result)>1:
        layer_name=split_result[-1]
    return layer_name

curves = rs.GetObjects("Select curves", 4, preselect=True)
if curves:
    for curve in curves:
        layer = rs.ObjectLayer(curve)
        bb=rs.BoundingBox(curve)
        center=(bb[0]+bb[6])/2
        print_name=GetLowestSublayerName(layer)
        rs.AddText(print_name, center, justification = 131074)