Copy Grids From Linked Model

HI Guys,

I’m trying to copy the grids from a linked model (and rename them to match the name in the linked model ) using the following:

Curve Property
http://www.revitapidocs.com/2016/0fce3154-595f-62f5-65d7-e5065c1234a0.htm

Create Method (Document, Line)
http://www.revitapidocs.com/2016/462cb588-9811-e464-0fe9-13226a2fc8f7.htm

    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?

Apologies if this is too long.

Please help me out, I’m stuck!:disappointed:

Why wouldn’t you just use the Copy/Monitor tool in Revit?

It’s something related to Dynamo. I tried with a macro and a PythonShell script and it works.

I just want to copy the grids in python

What do you mean? Dynamo can’t do it? Why?

Well, I really don’t know. I tried with a single grid but i got the same error: ‘type’ object has no attribute ‘Create’

Macro and Revit PythonShell script:

1 Like

thanks @Organon

I posted the issue on github:

I got the following answer:

mjkkirschner commented 2 hours ago
you’ve imported both the revitapi and our wrappers which include a grid type:https://github.com/DynamoDS/DynamoRevit/blob/7270187e8688fbd8ec538b4617810dccdb9a695f/src/Libraries/RevitNodes/Elements/Grid.cs#L16

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:

Ideas :grin:?

Why don’t you extract only the geometry of the linked grids and use the native grid creation nodes?

2 Likes

Because this is part of a bigger workflow, I’d like to use Python only

Any ideas why it doesn’t accept the Lines the way I extracted them?

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?

okay thanks. I’ll try to convert…

Or could I get the revit lines directly> Without going through Dynamo lines?

Also I’d like to learn just to use python…It’s a good learning process.

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.

2 Likes

This code works:

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
1 Like

Thank you for pointing to the right direction :slight_smile:

Thank you :slight_smile:

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 :frowning:

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…:blush::thinking::wink:

Hi Rob,

It looks like we are exploring the same possibilities :wink:
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).

Copy Grids and Levels from Linked Model_beta.dyn (195.6 KB)
Maybe it can be of help for you.

Kind regards,
Mark

2 Likes

Will try and have a look at the above and see what I can make of it. something tells me im in way over my head though :stuck_out_tongue:

Thanks @MJB-online, exactly what I wanted