Read from list

python

#1

On line 35 how to i ask python to read elements inside the list “ids” and “newlocs”

i tried “ids[i]” and “newlocs[a]” but no luck…!

and here is the error message…

image


#2

The issue isn’t iterating, it’s that the method you’re using requires an ICollection, not a normal list.

Here’s how you create an ICollection:

elements = UnwrapElement(IN[0])   
ids_collection = List[ElementId](e.Id for e in elements)

#3

@Nick_Boyts , thanks for reply,

adding this line to code gives a cast object error…! can you help me understand this error and what exactly I collection command do…!

Is it like wrapping the element again so the Revit could take it…?

the error message:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 36, in
TypeError: Unable to cast object of type ‘System.Int32’ to type ‘Autodesk.Revit.DB.ElementId’.

do I have to import and module to solve this??


#4

A Collection is just a Revit set of elements. Certain methods require Collections instead of simple lists. Someone else might have a better understanding of the reasoning behind it.

We specified that your Collection would contain Element Ids, but your new error is saying that you’re trying to cast Integers. I think the issue is coming from your For Loops, specifically Line 31 for Ids. You’re getting the Id of i and THEN Unwrapping it. Try Unwrapping i before getting the Id.


#5

tried it solved the error but another error raised saying
"SystemError: MakeGenericType on non-generic type"
on line 33


#6

You’ll have to show what your inputs are so we have a better idea of what’s going on.


#7

@saju_autodesk To help others understand better it would help to try explaining with complete graph with preview of all the node values if you want others to help you.


#8

here is the full screenshot

and the error message:

image

and here is the code:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
clr.AddReference('RevitNodes')
clr.AddReference('RevitServices')
clr.AddReference('RevitAPIUI')
clr.AddReference('DSCoreNodes') 
import DSCore
from DSCore import *
import Autodesk
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
from Autodesk.Revit.DB import *
from Autodesk.DesignScript.Geometry import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc= DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)

text=UnwrapElement(IN[0])
locs=UnwrapElement(IN[1])

ids=[]
newlocs=[]



for i,j in enumerate(text):
	ids.append(j.Id)
	idsc=List[ElementId](ids)
for a,b in enumerate(locs):
	newlocs.append(b.ToXyz)
	newlocsc=List[ElementId](newlocs)


	
Move=ElementTransformUtils.MoveElements(doc,idsc,newlocsc)


#The inputs to this node will be stored as a list in the IN variables.


TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = IN[0],ids,newlocs

#9

@saju_autodesk Please re-post your graph we can’t read. Use camera button (top-right) built into Dynamo - it screenshots the entire canvas.


#10

edited on the same post…! plz have a look