Created
November 18, 2019 02:51
-
-
Save alvpickmans/f451c50b1954739d67875f126c18a647 to your computer and use it in GitHub Desktop.
Dynamo Python script to retrieve all elements from a linked model by category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enable Python support and load DesignScript library | |
import clr | |
clr.AddReference('ProtoGeometry') | |
from Autodesk.DesignScript.Geometry import * | |
# Import ToDSType(bool) extension method | |
clr.AddReference("RevitNodes") | |
import Revit | |
clr.ImportExtensions(Revit.Elements) | |
# Import DocumentManager and TransactionManager | |
clr.AddReference("RevitServices") | |
import RevitServices | |
from RevitServices.Persistence import DocumentManager | |
# Import RevitAPI | |
clr.AddReference("RevitAPI") | |
import Autodesk | |
from Autodesk.Revit.DB import * | |
# Importing .NET List colelction, required for ElementMulticategoryFilter | |
from System.Collections.Generic import List | |
doc = DocumentManager.Instance.CurrentDBDocument | |
# The inputs to this node will be stored as a list in the IN variables. | |
inLink = IN[0] | |
inCats = IN[1] | |
# Creating ElementIds from Id integers | |
catIds = [ElementId(category.Id) for category in inCats] | |
# Creating a .NET List collection of ElementIds | |
categoryIds = List[ElementId](catIds) | |
# Retrieving linked document | |
mLink = doc.GetElement(ElementId(inLink.Id)).GetLinkDocument() | |
sysFilter = ElementMulticategoryFilter(categoryIds) | |
mOut = FilteredElementCollector(mLink) \ | |
.WhereElementIsNotElementType() \ | |
.WherePasses(sysFilter) \ | |
.ToElements() | |
# Assign your output to the OUT variable. | |
OUT = mOut |
You can run it using a Python Script node
Could you please clarify what the input are? I'm feeding category id and link id and its not working.
Thanks.
From memory and looking at the code, inputs are category and link elements, using ootb dynamo nodes tio get them
Thank you
Link instance & category did it. Thanks man!
help guys.. i am a noob.. and trying to get this to work, i feed the link like this:
then i feed it into this Python Script node as IN[0] along with a Category in IN[1]
and i get this error.... which i really can't grasp..
the link is properly selected, i checked it's ID to make sure i didn't accidentally clicked something else...
help!!!
line 32 is a commented line, starting with #, right?...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, l am new in Dynamo. I would like to ask you how and where do you write this script in Dynamo ?