Can I return a value to command line(Rhino Python)

Hello guys,

Im writing some macros in python, and i want to return a message to rhino command line, how can i do it?, I dont want to use messageBox because its a bit annoying all the time to close the pop up window.

Thanks.

Hi @Octav1an,

just use the print statement followed by the message within quotes. Example:

print "Hello Rhino"

c.

Thanks for the answer, but it wont work as i want, i want the “hello Rhino” to be printed in the rhino command line after i execute the macro.

Is your macro in python or made up of regular rhino commands ? Can you show what you have ?

c.

So here is the macro

-_RunPythonScript (

import rhinoscriptsyntax as rs

def lockPoints():
    points = rs.ObjectsByType(1)
    if not points: 
        return False
    intCount = 0
    print(len(points))
    for i in range(0, len(points), 1):
        if not rs.IsObjectLocked(points[i]): intCount+=1
    rs.MessageBox("Points Locked: " + str(intCount), 0)
    rs.LockObjects(points)
    return True

lockPoints()
)

I want to have a return message with the number of points locked. In this example im using messageBox, however i dont like it, its annoying to close the window all the time, i want something more passive in background or on rhino command line

Try this:

_RunPythonScript (
    
import rhinoscriptsyntax as rs
    
def lockPoints():
    points = rs.ObjectsByType(1)
    if not points: return False
    
    intCount = rs.LockObjects(points)
    print("Locked {} points").format(intCount)
    
lockPoints()
)

The method rs.LockObjects(points) counts objects which have been locked. So no need to count :wink:

c.

1 Like

thanks, exactly what i wanted