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)

the error is:

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

line 5, in rac, "C:\Users\Angela\AppData\Local\Temp\"
line 6, in , “C:\Users\Angela\AppData\Local\Temp\

Ciao Vittorio

(Steve Baer) #2

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