Make new View with Section Box and Orientation?

Whereas the Set Section Box nodes are currently not working in Revit 2022, I would like to modify this working Python found in Genius Loci nodes. Goal is to create a new 3D View with Section Box and Orientation given the inputs: Name, Eye Point, Target, Bounding Box.

From node 3DView by BoundingBox

From node 3DView Set Orientation

How can I get an orientation from Eye Point & Target to feed a new line like view.SetOrientation(viewSetting) ?

I haven’t coded this myself, but I did take a quick look at the API and have posted my notes below. This type of ‘research’ is often how I start my more involved API efforts, and in conjunction with noting up your code is a good set of habits to pick up. Pretty much all of these methods are directly in the code above, but I’m guessing that by providing a little bit of guidance things will become clear enough that you can manipulate them yourself.

  1. To start with you’ll need a new isometric view - there is just such method in the View3D class here: CreateIsometric Method (revitapidocs.com). This will require the 3D view type you want to use, which could be a new input or you could use a filtered element collector and check for the ViewFamily.ThreeDimensional as shown in the first set of code under the #Get 3D View ViewFamilyType heading.

  2. Once the new view is created, you can go about setting it to what you intend it to be. Setting the orientation appears to have a fairly straightforward method:
    SetOrientation Method (revitapidocs.com).

  3. The SetOrientation method requires a ViewOrientation3D object, which also appears to have a fairly straightforward constructor: ViewOrientation3D Constructor (revitapidocs.com)

  4. The notes for the SetOrientation also mention that this is not saved directly into the model, which seems like something you’re after, so you’ll want to use one of these as well: SaveOrientation Method (revitapidocs.com); SaveOrientationAndLock Method (revitapidocs.com)

  5. This hasn’t touched on setting the section box yet, which also has a readily findable method: SaveOrientationAndLock Method (revitapidocs.com)

  6. The input for that is a bounding box, which means you’ll need to build a Revit bounding box with the default constructor: BoundingBoxXYZ Class (revitapidocs.com)

  7. But that constructor sets the bounding box to (-100,-100,-100),(100,100,100), so you’ll have to set the Min and Max XYZ values to your desired inputs: Min Property (revitapidocs.com) and Max Property (revitapidocs.com) respectively.

  8. For the inputs to #6 you could convert a Dynamo bounding box to a Revit bounding box by pulling the Min and Max points, convert each to a Revit XYZ element, and set your new bounding box’s min and max points.

Alternatively for #6, #7 and #8 you could pull an element’s bounding box with this method: BoundingBox Property (revitapidocs.com). That could then be scaled up to give more ‘context’ if that is what you desire. This may require a larger change in your graph, but as I am not certain how or why you’ve defined the bounding box I can’t be sure.

Hope this helps. Give it a shot and if you get stuck just post back and the larger community will continue to help as we can.

2 Likes

Is there a guide anywhere showing how to convert the Revit API Docs into Python?
Is there an IDE that is helpful to code the Python and can even do debugging? VS Code? This is good on installing autocomplete but is 5 years old: Loom | Free Screen & Video Recording Software | Loom

I am already stuck in my first attempts…
image

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

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 )

def tolist(obj1):
    if hasattr(obj1,"__iter__"): return obj1
    else: return [obj1]

viewNames = tolist(IN[0])
mins = tolist(IN[1])
maxs = tolist(IN[2])
doc = DocumentManager.Instance.CurrentDBDocument

#Get 3D View ViewFamilyType
viewType = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements().Find(lambda x : x.ViewFamily == ViewFamily.ThreeDimensional)

def CreateView(name, newmax, newmin):
    view = View3D.CreateIsometric(doc, viewType.Id)
    view.Name = name
    newbox = BoundingBoxXYZ()
    newbox.Max = newmax
    newbox.Min = newmin
    view.SetSectionBox(newbox)
    return view

TransactionManager.Instance.ForceCloseTransaction()
t = Transaction(doc,'Create3D')
t.Start()
views=ProcessParallelLists(CreateView, viewNames, mins, maxs)
t.Commit()
#TransactionManager.Instance.ForceCloseTransaction()

#Assign your output to the OUT variable
OUT = views