Multi-Segment grids

Yes, so MultiSegmentGrids are not the same type of objects as regular Grids. Having said that I must respond to Nick’s comment:

Yes, and no. Not with the existing nodes. None of the ones that I saw in Dynamo do the trick unless you do something first - get the Grid objects out of the MultiSegmentGrid object. Basically a multi-segment grid is multiple grids stored inside of different object.

Anyways let’s say I have a file like so:

I put some fancy multi segment grids in there to demonstrate the workflow. First we need to collect the data:

You end up with an excel file like so:

Now we can jump into a different file and read that data in, and re-create our grids:

Here’s the result:

As you can see some grids have a different “direction”. That’s because when we were joining the curves, they probably got sorted into a different order. You might have to clean that up somehow. I don’t want to get too much into the weeds with this stuff. Obviously my grids have weird numbers in the bubbles, but that’s because I ran this definition couple times when testing, and deleted previous set of grids every time. Still, a better approach would be to set the grid number from excel, so don’t export just geometry, but also include the number etc. Your call.

Here’s the Python code for getting grid segments from MultiSegmentGrid:

# Copyright(c) 2018, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

import System
from System import Array
from System.Collections.Generic import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

def get_grids(g):
	grid = UnwrapElement(g)
	ids = grid.GetGridIds()
	grids = []
	for i in ids:
		grids.append(doc.GetElement(i))
	return grids

try:
    errorReport = None
	output = [get_grids(x) for x in IN[0]]
except:
    import traceback
    errorReport = traceback.format_exc()


if None == errorReport:
    OUT = output
else:
    OUT = errorReport

Here’s the Python code for creating a new MultiSegmentGrid:

# Copyright(c) 2018, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

import clr
clr.AddReference('ProtoGeometry')
import Autodesk.DesignScript.Geometry

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

import System
from System import Array
from System.Collections.Generic import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

def create_grid(type, curves, plane):
	typeId = UnwrapElement(type).Id
	plane = Plane.CreateByNormalAndOrigin(XYZ(0,0,1), XYZ(0,0,0))
	sketchPlane = SketchPlane.Create(doc, plane)
	curveLoop = CurveLoop()
	for i in curves:
		c = i.ToRevitType()
		curveLoop.Append(c)
	grid = MultiSegmentGrid.Create(doc, typeId, curveLoop, sketchPlane.Id)
	return grid

try:
    errorReport = None
    TransactionManager.Instance.EnsureInTransaction(doc)
    output = []
    for i in IN[1]:
    	output.append(create_grid(IN[0], i, IN[2]))
    TransactionManager.Instance.TransactionTaskDone()

except:
    import traceback
    errorReport = traceback.format_exc()

if None == errorReport:
    OUT = output
else:
    OUT = errorReport

You will need archi-lab.net and bumblebee packages for this:

image

Definition files can be found here:

2_Grids.dyn (63.0 KB)
2_GridsRead.dyn (73.2 KB)

This was built with Revit 2019 and Dynamo 2.0

17 Likes