Bind Area Boundaries to Closest Wall Centerlines

I’m working in Revit 2024.

I’ve created a graph that places Area boundaries at Room.Center Boundary curves. Then it creates Areas within those boundaries and names/numbers the Areas according to their corresponding Rooms. (Special thanks to @GavinCrump for the python code from his Crumple nodes.)

Everything works flawlessly, however, when Area Boundaries are created in this manner they are not bound to the walls. My Architect wants the Area Boundaries to be bound to the walls so if the walls move they don’t have to move the boundaries manually.

When Area Boundaries are created manually there’s an option called “Apply Area Rules”.
image
This option seems to bind the created Area Boundaries to the walls, but only if you use PickLines to create the boundary and then select the wall.

I dove into the API docs and could not find anything about “Apply Area Rules” or binding Area Boundaries.

I’ve been learning Python and the calls, classes, & methods in the Revit API docs. I have not found a way to bind Area Boundaries to the closest wall centerlines.

Is this even possible?

A handful of similar discussions out there, and deafening silence from the developers:

If the API did support this it would typically be in one of two ways:

  • The new area boundary line would have a bool argument for this
  • The " " would have a related options class and argument for this (more likely)

Given neither exist in the API that I can see I suspect it is unsupported. Ideally the API created lines would just remember the setting given it’s an ini thing, but it looks like they don’t.

1 Like

I believe this is doable, but you have to think about the problem differently.

The constraint isn’t between the wall and the area, but between the wall and the area separation line.

Since you’re drawing an area separation line from each wall, take the wall, the the curve, generate the area separation line, get a reference to the wall’s curve, get a reference to the area separation line, and create a new alignment using the method here: NewAlignment Method

3 Likes

Ohhh! That makes sense. Haha, It’s funny because I’ve made hundreds of families, so align and lock is not a foreign concept. Thanks for the fresh perspective. :+1:t2: I’ll try it tomorrow.

1 Like

I agree. My next graph is basically going to be the same thing but for Spaces. Then I’ll have to teach our MEP people how to use Spaces :sweat_smile:.

1 Like

What am I doing wrong? Code is below.

I tried “Dimension” and received an error that said dimension doesn’t have the NewAlignment method. Which is confusing because we see it in the API docs.
So I tried doc.Create and received this error:

image

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

area_plan_view = IN[0]
area_separation_refs = UnwrapElement(IN[1])
wall_refs = UnwrapElement(IN[2])

doc = DocumentManager.Instance.CurrentDBDocument

area_plan = doc.GetElement(area_plan_view.UniqueId)

TransactionManager.Instance.EnsureInTransaction(doc)

for i in range(len(area_separation_refs)):
    area_ref = area_separation_refs[i]
    wall_ref = wall_refs[i]
    doc.Create.NewAlignment(area_plan, area_ref, wall_ref)

TransactionManager.Instance.TransactionTaskDone()

OUT = "Alignments created successfully"

Not at a PC that can check, but what does the documentation in Python say for the method?

OUT = doc.Create.NewAlignment.__doc__

I’m not sure what you are asking.
The text from the error message is:
TypeError : No method matches given arguments for NewAlignment: (<class’Autodesk.Revit.DB.ViewPlan’>, <class’Revit.GeometryReferences.ElementCurveReference’>, <class’Revit.GeometryReferences.ElementCurveReference’>)

Comment out everything after the imports (wrap it in triple quotes), and then append the line I posted above so we can confirm what the pythonic version is expecting for inputs.

Okay cool! This is what it shows.

Autodesk.Revit.DB.Dimension NewAlignment(Autodesk.Revit.DB.View, Autodesk.Revit.DB.Reference, Autodesk.Revit.DB.Reference)

I gather that I have some rewriting and converting of inputs to do, correct?
Because Revit.GeometryReferences.ElementCurveReference is not the same as Autodesk.Revit.DB.Reference.

No, sadly those classes should inherit the parent class (view plan inherits view, element curve reference inherits reference)… I’ll try to look into this tomorrow - might be a Python limitation though so you can try IronPython 3 or 2 (in that order) if you’re in CPython.

Also check to see if unwrapping the view input helps.

I figured it out! :tada:
Code is below.
Instead of getting the Element Curve Reference from the walls and area separation lines, I used the GeniusLoci node called Element Reference to get the Autodesk.Revit.DB.References.

The odd thing is, the Python node still throws this error:

image

But when I nudged one of the walls the Area separation line was in fact locked to the wall. So the error will tell you that it didn’t work, but it actually does work.

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

area_plan_view = IN[0]
area_separation_refs = UnwrapElement(IN[1])
wall_refs = UnwrapElement(IN[2])

area_plan = doc.GetElement(area_plan_view.UniqueId)

TransactionManager.Instance.EnsureInTransaction(doc)

for i in range(len(area_separation_refs)):
    area_ref = area_separation_refs[i]
    wall_ref = wall_refs[i]
    doc.Create.NewAlignment(area_plan, area_ref, wall_ref)

TransactionManager.Instance.TransactionTaskDone()

OUT = "Alignments created successfully"

Thanks Jacob!

1 Like

Glad you got it squared away! Hopefully someone can pass the info over to the Revit API forum at some point. :slight_smile:

2 Likes