SCRIPT ON RhinoPython¹º¹ Primer not working Page 47

I have tried to run the script bellow and had this error
SCRIPT ON RhinoPython¹º¹ Primer not working Page 47

File “C:\Documents and Settings\Admin\Local Settings\Temp\TempScript.py”, line 3
source = “By Layer”, “By Object”, "By Parent"
SyntaxError: expected an indented block

import rhinoscriptsyntax as rs
def displayobjectattributes(object_id):
source = “By Layer”, “By Object”, "By Parent"
data = []
data.append( “Object attributes for :”+str(object_id) )
data.append( "Description: " + rs.ObjectDescription(object_id))
data.append( "Layer: " + rs.ObjectLayer(object_id))
#data.append( “LineType: " + rs.ObjectLineType(object_id))
#data.append( “LineTypeSource: " + rs.ObjectLineTypeSource(object_id))
data.append( “MaterialSource: " + str(rs.ObjectMaterialSource(object_id)))
name = rs.ObjectName(object_id)
if not name: data.append(””)
else: data.append(“Name: " + name)
groups = rs.ObjectGroups(object_id)
if groups:
for i,group in enumerate(groups):
data.append( “Group(%d): %s” % i+1, group )
else:
data.append(””)
s = ""
for line in data: s += line + "\n"
rs.EditBox(s, “Object attributes”, “RhinoPython”)
if name==“main”:
id = rs.GetObject()
displayobjectattributes(id)

If you want to post formatted code here do the following:

Type 3 “backticks” (`) plus python in the line before the code
Paste in all the the code
Type 3 more backticks after the code.

This will preserve your code formatting.

To guess at your question - as there is no indentation - after
def displayobjectattributes(object_id):
all the blocks should be indented (usually 4 spaces). So maybe where you copied the code out of lost some of the formatting. Correct indentation is essential for Python to work.

–Mitch

1 Like

Thank you it is working