STEP import script: Object Name from filename

Hi everybody,

~Long time rhino user, first time scripter~

I am trying to find a python script to assign object names based on the filename of the .step file to be imported. Looks like there are plenty of folks doing something similar with .stl and .obj files, but in my work I import a lot of components from the McMaster-Carr website, always as .step files. The filenames list the McMaster SKU, but when it comes time to place an order, I have to manually “reverse lookup” the specific parts that I downloaded by scrolling through and comparing my model to the long list of available hardware.

When I import 10 versions of a screw to use in an assembly, eliminate 9 of them, and have only one left, I can’t differentiate it from the other step files unless I import them all again and compare.

Surely there must be a way to name things during import!

Thank you in advance for the help.


I don’t know python.
This is a really rough and not-serious rhinoscript:

-runscript (
arr=Split(str ,"Successfully read file ")
path = Split(arr(Ubound(arr)-1) ,Chr(34))
chunks = Split(path(1),"\")
name = chunks(Ubound(chunks))
Rhino.Command("-_SelNone ")
Rhino.Command("_SelLast ")
arrObjects = Rhino.SelectedObjects
If IsArray(arrObjects) Then
For Each obj in arrObjects 
Rhino.ObjectName obj, name
End If

You have to launch it exactly after importing a file (drag-n-drop or whatever), if you don’t, it might name random stuff with random names!

It select the last created objects and set the name equal to the string after the string "Successfully read file "… not really a wonderful solution :crazy_face:

You can do this with python, probably in a better way, cleaner, using rhinocommon methods…
I would do it via c# script, but it’s a Beta feature…

You can try this one - quick mod from one of my other format batch importers. It will import all STEP files in a selected folder and name all the objects found in each file with the file name as object name. Let me know if it works the way you want or if it needs modifications. (1.7 KB)

1 Like

This is great. Thank you! It does exactly what I need it to.