Linked Model Grid Creation

Hello,

I found this post below that creates grids from a linked model but I am receiving an error with the Python Script. I am very new to Python and was wondering if anyone can help me determine the cause of the error. The script is below.

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

Hi @PhillipA

The code has a couple of instances where it uses a for loop over list, but it is not defined so that causes the error. I assume list should instead be grids. I also unwrapped the link. Revised code below.

The code does nothing with the names of the grids from the link, so Revit will just name the new grids sequentially. So I have altered the end so that it uses the name of the linked grid as the new grid.

By the way, it’s helpful to use the preformatted text tool when posting code, that way it copies nicely
image

Hope this helps,
Thomas

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=UnwrapElement(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 grids:
	ToCurves.append(i.Curve)

#Get Name of linked Grids
for i in grids:
	LinkedGridsName.append(i.Name)

TransactionManager.Instance.EnsureInTransaction(doc)

for i, n in zip(ToCurves,LinkedGridsName):
	a = Autodesk.Revit.DB.Grid.Create(doc,i)
	a.Name = n;
	ToGrid.append(a)

TransactionManager.Instance.TransactionTaskDone()

OUT = ToGrid

Thank you for your reply. The grids appear at elevation 0’-0" and do not show up in my plan views unless i drag the extents of the grid lines in elevation up to where the model is located. I acquired the coordinates from the architects model and there model is located 301’ above 0’-0". Can you add to the python script above a way to obtain the first level elevation from the architect’s model and translate the z coordinate of the grids to match the elevation of the architects model? Thank you

There is a method SetVerticalExtents that can be used to do this. I’ve taken the opportunity to simplify the end of the code:

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=UnwrapElement(IN[0])
LinkDoc =RLink.GetLinkDocument()
grids=FilteredElementCollector(LinkDoc).WherePasses(ElementCategoryFilter(BuiltInCategory.OST_Grids)).WhereElementIsNotElementType().ToElements()

ToGrid = []

TransactionManager.Instance.EnsureInTransaction(doc)

for grid in grids:
	newGrid = Autodesk.Revit.DB.Grid.Create(doc,grid.Curve)
	newGrid.Name = grid.Name
	newGrid.SetVerticalExtents(grid.GetExtents().MinimumPoint.Z,grid.GetExtents().MaximumPoint.Z)
	ToGrid.append(newGrid)

TransactionManager.Instance.TransactionTaskDone()

OUT = ToGrid