Skip to content

Commit

Permalink
Updated 2.x Python files
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Dieckmann committed Jan 14, 2020
1 parent 31c6b0f commit 609e7ff
Show file tree
Hide file tree
Showing 51 changed files with 597 additions and 144 deletions.
21 changes: 21 additions & 0 deletions nodes/2.x/python/All Elements Of Category+.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import System
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

def ElementsByCategory(bic, doc):
collector = FilteredElementCollector(doc).OfCategory(bic).WhereElementIsNotElementType()
return collector.ToElements()

inputdoc = UnwrapElement(IN[2])
if not inputdoc: doc = DocumentManager.Instance.CurrentDBDocument
elif inputdoc.GetType().ToString() == "Autodesk.Revit.DB.RevitLinkInstance": doc = inputdoc.GetLinkDocument()
elif inputdoc.GetType().ToString() == "Autodesk.Revit.DB.Document": doc = inputdoc
else: doc = DocumentManager.Instance.CurrentDBDocument

if isinstance(IN[0], list): OUT = [ElementsByCategory(x, doc) for x in IN[0]]
else: OUT = ElementsByCategory(IN[0], doc)
10 changes: 3 additions & 7 deletions nodes/2.x/python/All Families Of Category.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
import RevitServices
from RevitServices.Persistence import DocumentManager

def ElementTypesByCategory(cat, doc):
collector = FilteredElementCollector(doc).OfClass(Family)
return [x for x in collector.ToElements() if x.FamilyCategoryId.IntegerValue == cat.Id]

inputdoc = UnwrapElement(IN[2])
inputdoc = UnwrapElement(IN[0])
if not inputdoc: doc = DocumentManager.Instance.CurrentDBDocument
elif inputdoc.GetType().ToString() == "Autodesk.Revit.DB.RevitLinkInstance": doc = inputdoc.GetLinkDocument()
elif inputdoc.GetType().ToString() == "Autodesk.Revit.DB.Document": doc = inputdoc
else: doc = DocumentManager.Instance.CurrentDBDocument

if isinstance(IN[0], list): OUT = [ElementTypesByCategory(x, doc) for x in IN[0]]
else: OUT = ElementTypesByCategory(IN[0], doc)
collector = FilteredElementCollector(doc).OfClass(Family)
OUT = collector.ToElements()
3 changes: 1 addition & 2 deletions nodes/2.x/python/All Family Types Of Category.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import RevitServices
from RevitServices.Persistence import DocumentManager

def ElementTypesByCategory(cat, doc):
bic = System.Enum.ToObject(BuiltInCategory, cat.Id)
def ElementTypesByCategory(bic, doc):
collector = FilteredElementCollector(doc).OfCategory(bic).WhereElementIsElementType()
return collector.ToElements()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
cutters = UnwrapElement(IN[0])
view = UnwrapElement(IN[1])
tol = IN[2]
cats = UnwrapElement(IN[3])

catlist = []
for cat in cats:
catlist.append(cat.Id)
filtercats = List[ElementId](catlist)
filtercats = List[ElementId]([x.Id for x in IN[3]])
catfilter = ElementMulticategoryFilter(filtercats)

intersectorlist = list()
Expand Down
24 changes: 12 additions & 12 deletions nodes/2.x/python/All View-Dependent Family Instances Of Category.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
import RevitServices
from RevitServices.Persistence import DocumentManager

def CollectByView(bic, view):
collector = FilteredElementCollector(doc)
filter = ElementOwnerViewFilter(view.Id)
return collector.WherePasses(filter).OfCategory(bic).ToElements()

def GetViewDependentElements(cat, views):
if isinstance(views, list): return [CollectByView(cat, x) for x in UnwrapElement(views)]
else: return CollectByView(cat, UnwrapElement(views))

doc = DocumentManager.Instance.CurrentDBDocument
cats = IN[0]
views = UnwrapElement(IN[1])
views = IN[1]

elementlist = list()
# This could be more elegant if only I knew how to implement a Multicategory filter in Python....
for cat in cats:
catlist = list()
for view in views:
collector = FilteredElementCollector(doc)
filter = ElementOwnerViewFilter(view.Id)
bic = System.Enum.ToObject(BuiltInCategory, cat.Id)
catlist.append(collector.WherePasses(filter).OfCategory(bic).ToElements())
elementlist.append(catlist)
OUT = elementlist
if isinstance(IN[0], list): OUT = [GetViewDependentElements(x, views) for x in cats]
else: OUT = GetViewDependentElements(cats, views)
3 changes: 2 additions & 1 deletion nodes/2.x/python/Application.BasicFileInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
bfi = [BasicFileInfo.Extract(x) for x in paths]
username = [x.Username for x in bfi]
language = [x.LanguageWhenSaved for x in bfi]
version = [x.SavedInVersion for x in bfi]
if APIversion > 2019: version = [x.Format for x in bfi]
else: version = [x.SavedInVersion for x in bfi]
versioncurrent = [x.IsSavedInCurrentVersion for x in bfi]
if APIversion > 2016: versionlater = [x.IsSavedInLaterVersion for x in bfi]
else: versionlater = [None for x in bfi]
Expand Down
29 changes: 29 additions & 0 deletions nodes/2.x/python/BuiltInCategory.FromInput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import System
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

def GetBicFromInput(var):
bic = None
if var:
cattype = var.GetType().ToString()
if cattype == "Revit.Elements.Category": bic = System.Enum.ToObject(BuiltInCategory, var.Id)
elif cattype == "Autodesk.Revit.DB.BuiltInCategory": bic = var
elif cattype == "System.String":
found = [x for x in bics if x.ToString() == var]
if len(found) > 0: bic = found[0]
return bic

doc = DocumentManager.Instance.CurrentDBDocument
bics = System.Enum.GetValues(BuiltInCategory)

if isinstance(IN[0], list): OUT = [GetBicFromInput(x) for x in IN[0]]
else: OUT = GetBicFromInput(IN[0])
30 changes: 30 additions & 0 deletions nodes/2.x/python/Category.FromInput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import System
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

def GetCatFromInput(var):
cat = None
if var:
cattype = var.GetType().ToString()
if cattype == "Autodesk.Revit.DB.Category": cat = var
elif cattype == "Autodesk.Revit.DB.BuiltInCategory": cat = Category.GetCategory(doc, var)
elif cattype == "System.String":
found = [x for x in bics if x.ToString() == var]
if len(found) > 0: cat = Category.GetCategory(doc, found[0])
return cat

doc = DocumentManager.Instance.CurrentDBDocument
bics = System.Enum.GetValues(BuiltInCategory)
cats = UnwrapElement(IN[0])

if isinstance(IN[0], list): OUT = [GetCatFromInput(x) for x in cats]
else: OUT = GetCatFromInput(cats)
15 changes: 8 additions & 7 deletions nodes/2.x/python/Category.Material.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
clr.ImportExtensions(Revit.Elements)

cats = UnwrapElement(IN[0])
elementlist = list()

for cat in cats:
try:
elementlist.append(cat.Material.ToDSType(True))
except:
elementlist.append(None)
OUT = elementlist
def GetCatMat(cat):
if hasattr(cat, "Material"):
try: return cat.Material.ToDSType(True)
except: return None
else: return None

if isinstance(IN[0], list): OUT = [GetCatMat(x) for x in cats]
else: OUT = GetCatMat(cats)
13 changes: 7 additions & 6 deletions nodes/2.x/python/Category.Type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import System
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
Expand All @@ -6,12 +7,12 @@
import Revit
clr.ImportExtensions(Revit.Elements)

def GetCategoryType(cat):
if hasattr(cat, "CategoryType"): return cat.CategoryType.ToString()
else: return None

cats = UnwrapElement(IN[0])
elementlist = list()

for cat in cats:
try:
elementlist.append(cat.CategoryType.ToString())
except:
elementlist.append(None)
OUT = elementlist
if isinstance(IN[0], list): OUT = [GetCategoryType(x) for x in cats]
else: OUT = GetCategoryType(cats)
11 changes: 11 additions & 0 deletions nodes/2.x/python/Color.ByName.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import clr
clr.AddReference('System.Drawing')
import System.Drawing

def ColorByName(str):
syscol = System.Drawing.Color.FromName(str)
return syscol.R,syscol.G,syscol.B


if isinstance(IN[0], list): OUT = map(list, zip(*[ColorByName(x) for x in IN[0]]))
else: OUT = ColorByName(IN[0])
16 changes: 16 additions & 0 deletions nodes/2.x/python/Color.Name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import clr
clr.AddReference('System.Drawing')
import System.Drawing

def GetColorName(color):
if hasattr(color, "Red"):
if color.Red == 0 and color.Green == 0 and color.Blue == 0: return "Black"
else:
lookup = [x for x in knowncols if x.R == color.Red and x.G == color.Green and x.B == color.Blue]
if len(lookup) > 0: return lookup[0].Name
else: return None
else: return None

knowncols = [System.Drawing.Color.FromKnownColor(x) for x in System.Enum.GetValues(System.Drawing.KnownColor)]
if isinstance(IN[0], list): OUT = [GetColorName(x) for x in IN[0]]
else: OUT = GetColorName(IN[0])
2 changes: 1 addition & 1 deletion nodes/2.x/python/CustomNode.Properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def ByJSON(self, str):
for line in outputdef[:-1]: outputdef2 += line[2:].strip() + " "
self.OutputDescriptions.append(outputdef2)
elif node['NodeType'] == 'PythonScriptNode': self.PythonScripts.append(node['Code'])
elif node['NodeType'] == 'FunctionNode' and node['ConcreteType'] == 'Dynamo.Graph.Nodes.CustomNodes.Function, DynamoCore':
elif node['NodeType'] == 'FunctionNode' and node['Concrete'+'Type'] == 'Dynamo.Graph.Nodes.CustomNodes.Function, DynamoCore':
customnodename = data['View']['NodeViews'][data['Nodes'].index(node)]['Name']
if customnodename not in self.NestedCustomNodes:
self.NestedCustomNodes.append(data['View']['NodeViews'][data['Nodes'].index(node)]['Name'])
Expand Down
2 changes: 1 addition & 1 deletion nodes/2.x/python/DirectShape.FromRevitGeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
newDStype.SetShape(geom)
dsLib.AddDefinitionType(names[counter], newDStype.Id)
# create new DS instance
newDS = DirectShape.CreateElementInstance(doc, newDStype.Id, cat.Id, names[counter], Transform.Identity, "Dynamo","Clockwork")
newDS = DirectShape.CreateElementInstance(doc, newDStype.Id, cat.Id, names[counter], Transform.Identity)
newDS.SetTypeId(newDStype.Id)
elementlist.append(newDS)
except: elementlist.append(None)
Expand Down
14 changes: 7 additions & 7 deletions nodes/2.x/python/Document.BuiltInCategories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
clr.AddReference("RevitNodes")
import Revit

bics = System.Enum.GetValues(BuiltInCategory)
cdata = list()
for bic in bics:
try:
cdata.append((bic,ElementId(bic),Revit.Elements.Category.ById(ElementId(bic).IntegerValue)))
dynamoCatsOnly = IN[0]
biclist = System.Enum.GetValues(BuiltInCategory)
cdata = []
for bic in biclist:
try: cdata.append((bic, ElementId(bic), Revit.Elements.Category.ById(ElementId(bic).IntegerValue)))
except:
pass
OUT = cdata
if not dynamoCatsOnly: cdata.append((bic, ElementId(bic), None))
OUT = map(list, zip(*cdata))
9 changes: 9 additions & 0 deletions nodes/2.x/python/Document.Enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import clr
import System
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
import Autodesk

rAssembly = [x for x in System.AppDomain.CurrentDomain.GetAssemblies() if x.GetName().Name == 'RevitAPI'][0]
OUT = [x.Name for x in rAssembly.GetTypes() if x.Namespace is not None and x.Namespace.startswith("Autodesk.Revit.") and x.BaseType == System.Enum]
OUT = sorted(OUT, key=str.lower)
7 changes: 6 additions & 1 deletion nodes/2.x/python/Document.ProjectParameters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import System
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
Expand Down Expand Up @@ -30,6 +31,7 @@
elems = []
guids = []
isinst = []
bics = []
iterator = doc.ParameterBindings.ForwardIterator()
while iterator.MoveNext():
vag.append(iterator.Key.VariesAcrossGroups)
Expand All @@ -48,12 +50,15 @@
else:
isinst.append(False)
thesecats = []
builtincats = []
for cat in iterator.Current.Categories:
try:
thesecats.append(Revit.Elements.Category.ById(cat.Id.IntegerValue))
except:
# Return null if category is not supported by Dynamo
# This way the user knows there are unsupported categories assigned
thesecats.append(None)
builtincats.append(System.Enum.ToObject(BuiltInCategory, cat.Id.IntegerValue))
cats.append(thesecats)
OUT = (names,cats,vag, pgs, pts, uts, isvis, elems, guids, isinst)
bics.append(builtincats)
OUT = (names,cats,vag, pgs, pts, uts, isvis, elems, guids, isinst, bics)
28 changes: 10 additions & 18 deletions nodes/2.x/python/Element.AllInstances.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
elements = UnwrapElement(IN[0])

elementlist = list()
for e in elements:
collector = FilteredElementCollector(doc)
bic = System.Enum.ToObject(BuiltInCategory, e.Category.Id.IntegerValue)
def GetAllInstances(item):
collector = FilteredElementCollector(item.Document)
bic = System.Enum.ToObject(BuiltInCategory, item.Category.Id.IntegerValue)
collector.OfCategory(bic)
# This is a workaround
# because I was to lazy to learn
# because I was too lazy to learn
# how to implement LINQ in Python
elist = list()
for item in collector.ToElements():
if item.GetTypeId().IntegerValue == e.GetTypeId().IntegerValue:
elist.append(item)
elementlist.append(elist)
OUT = elementlist
return [x for x in collector.ToElements() if x.GetTypeId().IntegerValue == item.GetTypeId().IntegerValue]

elements = UnwrapElement(IN[0])

if isinstance(IN[0], list): OUT = [GetAllInstances(x) for x in elements]
else: OUT = GetAllInstances(elements)
Loading

0 comments on commit 609e7ff

Please sign in to comment.