import clr
# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
# Import ToDSType(bool) extension method
clr.AddReference('RevitNodes')
import Revit
from Revit.Elements import *
clr.ImportExtensions(Revit.Elements)
collector = Autodesk.Revit.DB.FilteredElementCollector(doc)
RevitLink = collector.OfClass(Autodesk.Revit.DB.RevitLinkInstance)
RLink=list(RevitLink)[0]
Grids = UnwrapElement(IN[0])
LinkDoc =RLink.GetLinkDocument()
filter = FilteredElementCollector(LinkDoc).OfCategoryId(Grids.Id).WhereElementIsNotElementType()
LinkedGrids = [i.ToDSType(True) for i in filter]
ToCurves,LinkedGridsName,ToGrid=[],[],[]
#Get Curves from linked Grids
for i in LinkedGrids:
ToCurves.append(i.Curve)
#Get Name of linked Grids
for i in LinkedGrids:
LinkedGridsName.append(i.Name)
TransactionManager.Instance.EnsureInTransaction(doc)
for i in ToCurves:
Grid.Create(doc,i);
for i,j in zip(ToGrid,LinkedGridsName):
i.Name=j
TransactionManager.Instance.TransactionTaskDone()
OUT = ToCurves
I get the following error when I try creating the grids:
and the following error when I try renaming them (bypassing the first error using DS to create the grids:
for i in ToCurves:
ToGrid.append(Grid.ByLine(i))
Also the items in Tocurve are the following type:
is this correct? Or I’m still using DS to get the curves?
you need to be specific about what type you are referring to. You are probably referring to ours which does not have a Create method. Use the full module name.
To create the grid I changed to:
for i in ToCurves:
Autodesk.Revit.DB.Grid.Create(doc,i);
but still Dynamo is not happy and gives me this error:
Yes, because you’re mixing your namespaces. There’s a Dynamo Line class and a Revit.DB.Line class. You’ll need to convert your dynamo lines to revit lines first.
What’s the problem of integrating the native nodes in a bigger workflow?
Yes, you can totally do that. The problem arises in this line
With the ToDSType method you’re converting the grid from a revit grid to a dynamo grid and later when you call the Grid.Curve property, the result is the same as using the built-in “Grid.Curve” node and you get a dynamo line. If you remove the the whole line or at least the “.ToDSType(True)”, the grid creation should go through.
import clr
# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager
# Import RevitAPI
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
# Import ToDSType(bool) extension method
clr.AddReference('RevitNodes')
import Revit
from Revit.Elements import *
clr.ImportExtensions(Revit.Elements)
collector = Autodesk.Revit.DB.FilteredElementCollector(doc)
RevitLink = collector.OfClass(Autodesk.Revit.DB.RevitLinkInstance)
RLink=IN[0]
LinkDoc =RLink.GetLinkDocument()
grids=FilteredElementCollector(LinkDoc).WherePasses(ElementCategoryFilter(BuiltInCategory.OST_Grids)).WhereElementIsNotElementType().ToElements()
ToCurves,LinkedGridsName,ToGrid=[],[],[]
#Get Curves from linked Grids
for i in list:
ToCurves.append(i.Curve)
#Get Name of linked Grids
for i in list:
LinkedGridsName.append(i.Name)
TransactionManager.Instance.EnsureInTransaction(doc)
for i in ToCurves:
a = Autodesk.Revit.DB.Grid.Create(doc,i)
ToGrid.append(a)
#for i,j in zip(ToGrid,LinkedGridsName):
# i.Name=j
TransactionManager.Instance.TransactionTaskDone()
OUT = ToGrid
Any way that this full workspace and any custom nodes could be uploaded? Grid lines are currently a pain in the &%# when we get new projects. The ability to have dynamo create gridlines and rename them accordingly would be hugeeee!
Any help would be much appreciated as I dont even know where to start when it comes to custom nodes in python
Hi @RAllan
I am not on a pc to check the python code on top but as i can see its a straight forward copy and paste to a python script node and follow. They might eventually post the completed dyn who knows…
It looks like we are exploring the same possibilities
A few months ago i created the below (beta)workflow, witch copies grids and levels from a linked model.
Due to lack of time, i haven’t finished it (couldn’t get the part of setting the right Grid types to work).