Stuck with a python logic

dynamo
python
#1

hi guys

im trying to select in a doors_collector only the doors with the Mark value i’ve chosen.

i tried this, but im stuck.

is there a way to select the same index value from one list to another?

"
import clr

Import RevitAPI

clr.AddReference(‘RevitAPI’)
import Autodesk
from Autodesk.Revit.DB import *

Import DocumentManager and TransactionManager

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

Import ToDSType(bool) extension method

clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.Elements)

doc = DocumentManager.Instance.CurrentDBDocument

#preselected value of door’s mark
liste = IN[0]
#final output
liste2 = []

door_id = []
door_item = []

door_collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType()

for i in door_collector :
identifiant = i.LookupParameter(‘Identifiant’).AsString()
door_id.append(Mark)
door_item.append(i)

for j in liste:
if j in door_id:
liste2.append(door_item.index(j))

OUT = liste2
";

0 Likes

#2

Hi @Yien, Rather than appending the parameter values you are looking for to their own list (in your case you were getting all doors and all the “identifiant” parameter values and adding them to the lists door_id = [] and door_item = []) and running an if statement over those items, you can filter the collected doors by an if statement while looping through the collected doors:

import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import System

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

mark = IN[0]
markdoors = []


doors = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType()

for i in doors:
	doormark = (i.get_Parameter(BuiltInParameter.DOOR_NUMBER).AsString())
	if doormark == mark:
		markdoors.append(i)

OUT = markdoors

This exact script might not do what you’re looking for because what I posted is searching the door’s parameter value “Mark” as its built in parameter DOOR_NUMBER, but this is comparing the parameter value of mark to the input IN[0] value, and returning elements for which those values are equal.

3 Likes

#3

As an FYI, you should paste your Python code using the Preformatted Text option. Just highlight your pasted text and click </> in the toolbar above.

Yes, but I don’t think that’s what you need here. As @awilliams said, you can wrap your if statement within your for loop.

However, if you wanted to iterate through both lists simultaneously you would use:
for i, j in zip(list1, list2):
This would essentially get you paired values list1[0]/list2[0], list1[1]/list2[1], etc.

1 Like

Python Nodes Basics
#4

Better and cleaner way!
That is exactly what i was looking for.

Thanks

0 Likes

#5

Ok i’ll try next time.

Y

0 Likes

#6

No problem - it seems you were approaching your Python script following a similar structure of filtering elements by parameter value as you would with Dynamo nodes :slight_smile:

0 Likes

#7

yes indeed. I’m pretty comfortable with Dynamo, but i start a few weeks ago with Python.

0 Likes

#8

i change this to this :
if doormark in mark :

0 Likes

#9

That seems like a much more useful script now since doors shouldn’t have duplicate marks; the code using in rather than == will work more like a search tool

0 Likes

#10

it works but something strange happened. no matter how i reorder the input list, the python script sorted the doors item by mark value when it output.

0 Likes

#11

@Yien Not sure if this was intentional but I realized at first I thought you meant you changed the code to be if mark in doormark as to search the door’s marks by your input values… but I guess you are searching the other way around. (see the differences in image below)


In any case, can you share a screen grab of the workflow with your inputs and outputs showing?

I think they are being ordered by their mark value because of the way that the “in” search is occurring so I’m not understanding how “reordering the input list” would change this; it is returning elements based on filtering their parameter values, so it makes sense to me that it would be running through them in order of their parameter values and thus outputting them in that order. Is that problematic for your workflow?

1 Like

#12

here my screen shot

but i think you were right with" == " instead of “in” , cause the string must be equal.

0 Likes

#13

i did another version of the python from your tips, because it could not take a list of input.
but, still, the order of the element is reorder by mark value, not input value.

0 Likes

#14

i think i find a solution that works!
i nested a loop in another loop.

thank you again Amy!

mark = IN[0]
markdoors = []

doors = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType()

for i in mark:
	for j in doors :
		if i == j.get_Parameter(BuiltInParameter.DOOR_NUMBER).AsString():
			markdoors.append(j)


OUT = markdoors

2 Likes

#15

Ah I hadn’t realized you were trying to input multiple marks :slight_smile: Glad you got it working! :+1:

0 Likes