Get View from SectionView | Get DatumPlane from Level | Revit API

Hello forum,

I’m prototyping something and I’m having difficulties.

What I’m trying to achieve:
A script that modifies the 2d extends of levels in a given view.

My problem:
I am trying to call the DatumPlane method SetCurveInView() from the level, but the view parameter wishes for a View and not a SectionView or a FloorPlanView. Also SetCurveInView() should be called with a DatumPlane and not a Level.

I know View and DatumPlane are parent objects, but how do I get them from the current view and a selected level?

Why I’m trying to do it:
I’ve had complains that moving the 2d extends of a view is time consuming (slow model, slow operation, 30 sec to 1 min between view refreshing each time the cursor is moved). So I’m trying to see if it can possibly make the operation faster. Working from a blank file, it seems that the amount of time needed to refresh the view during the dragging of the 2d level extend is directly proportional to the amount of objects hosted on it. Which is peculiar; it’s a 2d representation, I don’t understand the link between them.

Thank you!

Screen Capture:

Python script:

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

view = IN[0]
curve = IN[1]
level = UnwrapElement(IN[2])

level.SetCurveInView(DatumExtentType(1),view,curve)

Dynamo file
Level2dExtend.dyn (10.4 KB)

Blank Revit file (version 2021) with a single elevation, a curve exist over the top-most level:
Level2dExtend.rvt (1.5 MB)

Hello @slepagetrudeau
you need to Unwrap yours inputs (SectionView Class doesn’t exist in Revit API :wink: )

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

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

view = UnwrapElement(IN[0])
detailLine = UnwrapElement(IN[1])
level = UnwrapElement(IN[2])

TransactionManager.Instance.EnsureInTransaction(doc)
level.SetCurveInView(DatumExtentType.ViewSpecific, view, detailLine.GeometryCurve)
TransactionManager.Instance.TransactionTaskDone()
2 Likes

@c.poupin

Ahh, got it. It’s always the little things.

I’ll get into the habit of unwrapping my inputs like it’s Christmas morning.

Also thank you for the much more solid version of the python script. It is very appreciated.

1 Like