Help with Rhino Scripting


#1

Really new to Rhino, was trying to figure out if there was a way for me to select all objects and then rename them all to “Test” with a script. Thanks!


#2

@Abhi_Kondagunta,

you might test below example using the python editor ( _EditPythonScript ):

import rhinoscriptsyntax as rs

def DoSomething():
    
    # select all selectable objects, exclude lights and grips
    ids = rs.AllObjects(select=True, include_lights=False, include_grips=False)
    if not ids: return
    
    # change the object name
    rs.ObjectName(ids, name="Test")
    
# run the function defined above
if __name__=="__main__":
    DoSomething()

c.


#3

@clement
Thanks for the help, I got it to work, but I have a follow-up question. This may seem silly but, if I was to use the line
Call Rhino.Command("_-Import ")
How would I get it to import a specific file as opposed to me having to choose which file to open manually?


#4

@Abhi_Kondagunta,

i am not sure what importing a file has to do with above example and your initial post. Are you using RhinoScript (vb) or PythonScript ? To import a file using just a file path, you can try below python script:

import rhinoscriptsyntax as rs

def DoSomething():
    
    # set up a file path
    file = r"D:\Temp\Box.3dm"
    
    # run the import command
    rs.Command("_-Import {} _Enter".format(chr(34) + file + chr(34)))
    
# run the function defined above
if __name__=="__main__":
    DoSomething()

c.


#5

Basically I am trying to change an stl file to and nrb file, with specific layering, which is why I had to rename everything.I need to be able to import my stl, rename all of the objects, then distribute each to their own layer, and then output it as an nrb file. I am using RhinoScript, and calling upon the python script you sent earlier with Call Rhino.Command("_RunPythonScript "). The problem with this is that I have to manually select the python script, but my process needs to be automated.


#6

@Abhi_Kondagunta,

below is an example how to import the stl file using RhinoScript and name the imported (selected) objects to “Test”. To put things on seperate layers you might want to check out the methods Rhino.AddLayer() and Rhino.ObjectLayer():

Option Explicit

Call Main()
Sub Main()

    Dim strFile, blnResult, arrObjects
    
        Call Rhino.UnselectAllObjects()
    
        strFile = chr(34) & "D:\Temp\Box.stl" & chr(34)
    
        blnResult = Rhino.Command("_-Import " & strFile & " _Enter", True)
        If IsNull(blnResult) Then Exit Sub
        
        arrObjects = Rhino.SelectedObjects(False)
        If Not IsArray(arrObjects) Then Exit Sub
    
        Call Rhino.ObjectName(arrObjects, "Test")

    
End Sub

c.


#7

I already figured out the layer part, the only trouble I was having was file paths. Thanks so much!! One last question, would it be possible for me to run this entire process from command prompt? As in, I want to be able to run Rhino without the GUI.


#8

Yes, here is a tread which contains some useful links.

c.


#9

Thanks so much for all the help!!!