Divide parts using curves or Revit Area Boundary Lines

Hi There,
I am a begineer in Pyhton and was trying to make it work using Konrad’s custom node as a base that I found at this post:

https://forum.dynamobim.com/t/dividing-parts-with-dynamo/5388/7

while trying to solve a problem where I was trying to explore the possibility of using an area plan and/or placed area boundaries to automatically divide Revit Parts.

It seems that I can get to convert elements to Parts, and even there was a node to automatically slice those parts using reference plances. But the intention here is to avoid rework and use Area Plans in revit that already contain the “sketch” of area boundary lines.
Exploring the revit API for methods available to play with the Spatial Elements I was not able to build a custom script from scratch but was somewhat able to tweak Konrad’s legacy code mentioned above.

It also abviously select the right boundary lines and displays the blue bounding curves in Revit after the Run however, it does not divide the Parts for some reason.

The modified code from Konrad “archi-labs” is below: if someone could help me undestand wehter what I am trying to do is doable and what I am doing wrong, that would be awsome

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

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

# 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 *
from Autodesk.Revit.DB.Analysis import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

#Handle Lists by Proces List function below
def ProcessList(_func, _list):
    return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )
    
def ProcessParallelLists(_func, *lists):
	return map( lambda *xs: ProcessParallelLists(_func, *xs) if all(type(x) is list for x in xs) else _func(*xs), *lists )

#The inputs to this node will be stored as a list in the IN variable.
def Unwrap(item):
	return UnwrapElement(item)
	
def ToRevit(item):
	return item.ToRevitType(True)

if isinstance(IN[0], list):
	myParts = ProcessList(Unwrap, IN[0])
else:
	myParts = list(Unwrap(IN[0]))
	
if isinstance(IN[1], list):
	divisionLines = ProcessList(ToRevit, IN[1])
else:
	divisionLines = list(ToRevit(IN[1]))

if isinstance(IN[2], list):
	sketchPlane = ProcessList(Unwrap, IN[2])
else:
	sketchPlane = list(Unwrap(IN[2]))

#Define the division function to process

def dividePart(myParts,divisionLines,sketchPlane):
	partsList = List[ElementId]()
	partsList.Add(wall.Id)
	intersectionElementsIds = List[ElementId]()
	curveArray = List[Curve](divisionLines)
	
	if PartUtils.AreElementsValidForCreateParts(doc, partsList):
		createParts = PartUtils.CreateParts(doc, partsList)
		doc.Regenerate()
		
	parts = PartUtils.GetAssociatedParts(doc, parts.Id, 0, 0)
	
	return PartUtils.DivideParts(doc, parts, intersectionElementsIds, curveArray, sketchPlane.Id)
#Assign your output to the OUT variable
TransactionManager.Instance.EnsureInTransaction(doc)

partDivide = ProcessParallelLists(dividePart, myPars, divisionLines, sketchPlane)

TransactionManager.Instance.TransactionTaskDone()

OUT = partDivide

Just fixed a few typos in the code above :slight_smile: )
Also attaching the dyn file…Divide Parts by Area Plan.dyn (9.0 KB)

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

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

# 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 *
from Autodesk.Revit.DB.Analysis import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

#Handle Lists by Proces List function below
def ProcessList(_func, _list):
    return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )
    
def ProcessParallelLists(_func, *lists):
	return map( lambda *xs: ProcessParallelLists(_func, *xs) if all(type(x) is list for x in xs) else _func(*xs), *lists )

#The inputs to this node will be stored as a list in the IN variable.
def Unwrap(item):
	return UnwrapElement(item)
	
def ToRevit(item):
	return item.ToRevitType(True)

if isinstance(IN[0], list):
	myParts = ProcessList(Unwrap, IN[0])
else:
	myParts = list(Unwrap(IN[0]))
	
if isinstance(IN[1], list):
	divisionLines = ProcessList(ToRevit, IN[1])
else:
	divisionLines = list(ToRevit(IN[1]))

if isinstance(IN[2], list):
	sketchPlane = ProcessList(Unwrap, IN[2])
else:
	sketchPlane = list(Unwrap(IN[2]))

#Define the division function to process

def dividePart(myParts,divisionLines,sketchPlane):
	partsList = List[ElementId]()
	partsList.Add(myParts.Id)
	intersectionElementsIds = List[ElementId]()
	curveArray = List[Curve](divisionLines)
	
	if PartUtils.AreElementsValidForCreateParts(doc, partsList):
		createParts = PartUtils.CreateParts(doc, partsList)
		doc.Regenerate()
		
	parts = PartUtils.GetAssociatedParts(doc, myParts.Id, 0, 0)
	
	return PartUtils.DivideParts(doc, myParts, intersectionElementsIds, curveArray, sketchPlane.Id)
#Assign your output to the OUT variable
TransactionManager.Instance.EnsureInTransaction(doc)

partDivide = ProcessParallelLists(dividePart, myParts, divisionLines, sketchPlane)

TransactionManager.Instance.TransactionTaskDone()

OUT = partDivide

I was trying your .dyn but get this error:


Error: Custom node definition not loaded.

What I need to make it work?
I also tried replacing that node with the python script but it’s not working for me.
Can you please help me?

It’s part of a pack you’re missing, I don’t know which.

The ‘what the node’ node in rhythm should work for the most common ones.