First time Python error unexpected token

Using Dynamo 2.0.0 I’m using Ben’s code from this post. This is the image of his code. I keep getting a Warning, operation failed unexpected token “”

Here is a link to an image of my code. I’m new to Python, and spent a hour last night staring at the code looking for typos or incorrect case sensitivity. Thank you, Steve

Line 2, 6 and 11 looks to be the wrong sign make sure to use " or redo all the three places you use quotes

You can delete line 14 :slight_smile:

there is a difference between the following ways of using quotation marks :slight_smile:

"

'

´´

¨

1 Like

Thanks, Jonathan, I made the single and double quote changes. It’s still throwing an error. Here is a linkto an image of the updated. And here is a link to the text file of the code.

And I just deleted line 14 and this didn’t correct the error. BTW Can you tell from the code what type of input this code is looking for? I was trying to feed it either an element ID or an element selected.

Please another time post your code using preformatted text :slight_smile: (the ‘’</>’’ sign in the editor)
Also you can add pictures to your posts much easier than links to Dropbox :wink:

Have a look in line 61, quotation again :slight_smile:

Deleting line 14 was not to fix anything, it is simply a redundant line of code :stuck_out_tongue:

I believe the script require view elements as inputs (not the id’s).

Adding the code below:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
elementz = UnwrapElement(IN[0])
viewtemplates = list()
views = list()
viewcollector = FilteredElementCollector(doc).OfClass(View)
sheetcollector = FilteredElementCollector(doc).OfClass(ViewSheet)
for view in viewcollector:
	if view.IsTemplate == True:
		viewtemplates.append(view)
	else:
		views.append(view)
viewmatches = list()
for elem in elementz:
	viewmatchez = list()
	viewmatches.append(viewmatchez)

for v in views:
		viewelemidz = []
		viewelems = list()
		viewelems = FilteredElementCollector(doc,v.Id)
		for viewelem in viewelems:
			viewelemidz.append(viewelem.Id)
		for i in range(0,len(elementz)):
			elem = elementz[i]
			elemid = elem.Id
			viewmatchez =viewmatches[i]
			if elemid in viewelemidz:
				viewmatchez.append(v)

sheetz = list()
for sheet in sheetcollector:
	sheetz.append(sheet)

elsheetmatches = list()
for i in range(0,len(elementz)):
	elviewmatches = viewmatches[i]
	elsheets = list()
	for viewmatch in elviewmatches:
		sheetnum = viewmatch.get_Parameter(BuiltInParameter.VIEWER_SHEET_NUMBER).AsString()
		if sheetnum != '---':
			for sheetel in sheetz:
				if sheetel.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString() == sheetnum:
					elsheets.append(sheetel)
	elsheetmatches.append(elsheets)

OUT = viewmatches, elsheetmatches

This part was the problem

This is your picture:
image

And the text you added link to:
image

1 Like

Thanks, Jonathan, now I’m getting a new error; Traceback (most recent call); File “”, line 27, in
TypeError: iteration over non-sequence of type Floor. Interestingly I was able to feed it a Select Element and I selected a floor. But for some reason, I couldn’t use the Select Elements Node.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
elementz = UnwrapElement(IN[0])
viewtemplates = list()
views = list()
viewcollector = FilteredElementCollector(doc).OfClass(View)
sheetcollector = FilteredElementCollector(doc).OfClass(ViewSheet)
for view in viewcollector:
	if view.IsTemplate == True:
		viewtemplates.append(view)
	else:
		views.append(view)
viewmatches = list()
for elem in elementz:
	viewmatchez = list()
	viewmatches.append(viewmatchez)

for v in views:
		viewelemidz = []
		viewelems = list()
		viewelems = FilteredElementCollector(doc,v.Id)
		for viewelem in viewelems:
			viewelemidz.append(viewelem.Id)
		for i in range(0,len(elementz)):
			elem = elementz[i]
			elemid = elem.Id
			viewmatchez =viewmatches[i]
			if elemid in viewelemidz:
				viewmatchez.append(v)

sheetz = list()
for sheet in sheetcollector:
	sheetz.append(sheet)

elsheetmatches = list()
for i in range(0,len(elementz)):
	elviewmatches = viewmatches[i]
	elsheets = list()
	for viewmatch in elviewmatches:
		sheetnum = viewmatch.get_Parameter(BuiltInParameter.VIEWER_SHEET_NUMBER).AsString()
		if sheetnum != '---':
			for sheetel in sheetz:
				if sheetel.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString() == sheetnum:
					elsheets.append(sheetel)
	elsheetmatches.append(elsheets)

OUT = viewmatches, elsheetmatches

This is most likely because you’re feeding the wrong element… Line 27 reads:

image

Meaning that it expects a list to iterate over, and I don’t think the code is created to operate on model elements like a “floor”.

1 Like

So if I Select two views and pass it a List to the Python, it runs but the output doesn’t make sense to me.

Your scripts only take a input in IN[0] … It’s a good idea to understand what you’re using :wink:
The output is defined in your script as viewmatches, elsemarches

1 Like