Create Phasefilters with a list Python

Hi everyone,

The create method in RevitAPI say that I need “the document” and “a string” to create a new phasefilter.
So I made this python script : (IN[0] = string)

doc = DocumentManager.Instance.CurrentDBDocument

Arch = IN[0]

TransactionManager.Instance.EnsureInTransaction(doc)

NewPhaseFilter = PhaseFilter.Create(doc, Arch)

TransactionManager.Instance.TransactionTaskDone()

OUT = NewPhaseFilter

It’s working perfectly for one new phasefilter but I would like to push a little bit further (if it’s possible).

Is there a way to create multiple phasefilter with a list of strings?

Thank you in advance!

hi @BenBimlogic , try this way;

# document
doc = DocumentManager.Instance.CurrentDBDocument

# if input is not a list , make a list
names = IN[0] if isinstance(IN[0],list) else [IN[0]]
# for output result
result = []

# transaction open
TransactionManager.Instance.EnsureInTransaction(doc)

# loop each name
for name in names:
	result.append(PhaseFilter.Create(doc, name))

# transaction close
TransactionManager.Instance.TransactionTaskDone()
OUT = result
1 Like

Awesome,it’s working! Thank you very much!

So basically you use an “if else statement” for the instances inside the list? right? ( the idea isn’t really clear in my head ahah)

hi @BenBimlogic, it means, If IN[0] is a list, you just take it. Else(if not a list) make/convert IN[0] a list.
And there are so many different ways of writing. What matters is logic.

1 Like

Ok, now I get it! Thank you again!