Rs.Command(" ") bug in Python

Hi Steve
I draw two line l1, l2 and the script make a blend.
the below VBscript is OK:

Call Main()
Sub Main()
	l1 = Rhino.GetObject("seleziona curva 1")
	l2 = Rhino.GetObject("seleziona curva 2")
	Rhino.Command("-blend selid " + l1 + " selid " + l2)

End Sub

The below Python Script return error:

import rhinoscriptsyntax as rs
def rac():
    l1=rs.GetObject("seleziona curva 1")
    l2=rs.GetObject("seleziona curva 2")
    rs.Command("-blend selid "+l1+" selid "+l2)
rac()

the error is:

Message: unsupported operand type(s) for +: ‘str’ and ‘Guid’

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

Ciao Vittorio

l1 and l2 are actual Guid types in python. Python is just telling you it doesn’t know how to use the + operator between strings and Guids. You easily convert these to strings using the str function.

# using the str function should work.
rs.Command("-blend selid "+str(l1)+" selid "+str(l2))
# another option that I like to use is the format function on strings
# format will automatically convert the guids (any data types) to strings
rs.Command("-blend selid {0} selid {1}".format(l1, l2))

Here’s some info on the format function
http://docs.python.org/2/library/stdtypes.html#str.format

2 Likes

Can I just say that I love this forum!