Help with python code

Can anyone help that understands Python? We have the below code for moving objects from one list of their current coordinates to a new coordinate location based on another list already generated. We have no knowledge of Python programming and are having a lot of trouble working out where the errors are in the code. Dynamo comes up with an error for line 24.

 

Any help would be much appreciated.

 

Capture

Can you post the code as text (or the definition) as well as the exception message? (shows when you hover over the python component.

newloc is a list of values, you need a loop to process its items

what did the error say?

I have the same problem. The code works with single elements but when its lists I get the following error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. Traceback (most recent call last): File “”, line 20, in AttributeError: ‘list’ object has no attribute ‘ToRevitType’

Any help would be great!

if your input is a list of elements then you have to iterate over it to apply ToDSType() method as it only works on a single element and not on a list. just write a for loop and call ToDSType() on each element.

output = []

for i in someList:

output.append(i.ToDSType())

you could also use map or a lambda but loop is just fine here.

Hi Konrad, thank you for your advice.
I have attempted to create some basic loops to output the data.

I have been unable to apply ToDSType() and ToRevitType() to elements from the within the loop. What variable type should the element be before I can apply one of these methods to the element?

The following code gives me data output, but not exactly what I need as it does not apply itself to the revit model ?

Chris,

Please clarify what you mean by “does not apply itself to Revit model”. I am not exactly sure what you wanted to do. Can you just type up a brief description and maybe a few screenshots of what you expected to happen in revit after this code was executed.

Konrad,

Once I execute the code nothing happens in the revit model. I was hoping to move families onto walls. Using the code at the top of this discussion I was able to move one family at a time, but not the list of families with the list of vector coordinates I was hoping for. Appreciate your help with this!

Hi Chris,

Don’t get this the wrong way, but have you tried using the search bar at the top of the forum?

http://dynamobim.org/forums/search/python+for+loop/

The results are not always relevant because the built-in search kind of sucks… Still, your question has been asked and answered multiple times already. In fact, I answered a similar question just last week. Even better, consider using a filtered google search. That will yield many relevant existing forum topics:

http://lmgtfy.com/?q=site%3A+http%3A%2F%2Fdynamobim.org%2Fforums%2Ftopic%2F+for+loop+python

1 Like