Hello,
I have a peace of code to make a view filter, also a big thanks for Jonathan Olesen for bringing me so far. But is seems everything is working but the Filter doesn’t show up in the VG menu?
Anybody know what is going wrong…
Thanks
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
def GetBuiltInParam(paramName):
builtInParams = System.Enum.GetValues(BuiltInParameter)
test = []
for i in builtInParams:
if i == paramName:
test.append(i)
else:
pass
return test
cats = IN[0]
paramName = IN[1]
pValue = IN[2]
view = UnwrapElement(IN[3])
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
castlst = []
for i in cats:
castlst.append(ElementId(i.Id))
typedCatlist = castlst
rules = []
bip = GetBuiltInParam(paramName)
for el in bip:
rules.append(ParameterFilterRuleFactory.CreateLessRule(ElementId(el), pValue, 0.001))
try:
filter = ParameterFilterElement.Create(doc, 'Test', typedCatList, rules)
view.AddFilter(filter.Id)
except:
pass
TransactionManager.Instance.TransactionTaskDone()
OUT = view
I don’t think you can filter by Base Offset. Try creating your filter manually. If you can’t do it with Revit, Dynamo won’t be able to do it either.
2 Likes
Ow base offset was a test. Tested a lot parameters but no result. It must work of you take a look at the Archi lab nodes
That’s very much a truth.
It’s just that Dynamo can process data a whole lot faster than our own weak mortal forms.
2 Likes
My wish is to create a structural plan with the view range applied and some filters created with dynamo.
Structural plan creation and View range is already working with dynamo/ python also the top level, bottom level range en Lookup/ down.
But the last thing, Filters as you can see in my topic is not working so you can’t apply a view template.
if it’s not possible i will use Archi Lab but i Always like to know how things are working to better understand what i’m doning
That’s achieved by understanding how Revit thinks, once you get it, you will feel energy vibes throughout your body! keep learning, never stop!
1 Like
This part of your script was checking i
(an Autodesk.Revit.DB.Parameter element) against paramName (a string) so you were returning an empty list for bip. In my revision below you’ll see I create a dictionary of the BuiltInParameters names as the keys and the BuiltInParameter elements as the values, then search the dictionary with the paramName input.
There was also a typo where you assigned typedCatlist
, but reference typedCatList
so the script would have failed there - you didn’t get a warning because of try/except. I usually do not add that to a script until I’ve gotten it working properly.
But even without the typo, typedCatList would not have worked as one of the arguments for ParameterFilterElement.Create method because it is expecting an iCollection. In my revision below the line typedCatList = List[ElementId](castlst)
is creating the iCollection
Here is my revised version of your code that appears to be functioning as expected:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
from System.Collections.Generic import List
doc = DocumentManager.Instance.CurrentDBDocument
cats = IN[0]
paramName = IN[1]
pValue = IN[2]
view = UnwrapElement(IN[3])
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
castlst = []
for i in cats:
castlst.append(ElementId(i.Id))
typedCatList = List[ElementId](castlst)
rules = []
builtInParams = System.Enum.GetValues(BuiltInParameter)
bipNames = []
for i in builtInParams:
bipNames.append(str(i))
bipDict = dict(zip(bipNames,builtInParams))
bips = [bipDict.get(p, "none") for p in paramName]
TransactionManager.Instance.EnsureInTransaction(doc)
for bip in bips:
rules.append(ParameterFilterRuleFactory.CreateLessRule(ElementId(bip), pValue, 0.001))
filter = ParameterFilterElement.Create(doc, 'Test', typedCatList, rules)
view.AddFilter(filter.Id)
TransactionManager.Instance.TransactionTaskDone()
OUT = view
4 Likes
Thanks for the help,
I had a really short time to test is. But i get the following error:
And when it is working the filter will be automatic added to the VG Filters:
Thanks again
The error is saying that the code is trying to iterate over a list but is only receiving a singleton for paramName. You either need to modify the code to only use a single parameter name or wrap your single parameter in a list before sending it into the python node.
3 Likes
Thanks!
I feel we are so close but the adding of a list gives me the following error:
That might be from"none"
in like 36. You could try changing it to None
.
Otherwise I’d suggest outputting some of your variables to make sure they’re return what you expect.
2 Likes
This is the set up I tested with that works with the code provided above
1 Like
I see whats wrong - you are inputting a BuiltInParameter element output by your Python script beforehand, so yes for the dictionary it is returning none because it is expecting a search string. Input the BuiltInParameter as a string
2 Likes
Thanks!!
This is helping me a lot to understand python. I’m now on holiday. So i Will test it when i’m back and will let you know if it’s finally working on my pc
Now I see why you were using "none"
1 Like
@Nick_Boyts that was a bit my fault for not looking closely enough at the screen capture and only looking at the script; this part in the original script lead me to think it was meant to be input with strings:
1 Like
Some question to learn dynamo in combination with phyton: are there some good sites/ guides to learn it better?
I understand some of the basics but not if you need some more complex coding
This class is quite nice to get started:
1 Like
Nice
Nice to have a forum with such good help!
1 Like
Hi,
The code is working good. I want to make a modification so you can add the filter to more than one view:
Would this be possible?