Creating dependent views with scope boxes

#1

Hi there,

I am trying to create dependent views from the current view with a scope box.
The script does make the views, but the created views does not contain the scope boxes i want to create from it.

I am trying to create them while using a python script, with 3 inputs.
IN[0] are the views
IN[1] are the minimums for the scope box
IN[2] are the maximums for the scope box

The script i have is :

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

clr.AddReference(“RevitNodes”)
import Revit
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
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

views = UnwrapElement(IN[0])
Min =
Max =

for i in IN[1]:
Min.append(UnwrapElement(i.ToXyz(True)))
for i in IN[2]:
Max.append(UnwrapElement(i.ToXyz(True)))

elementlist = list()
failedlist = list()

TransactionManager.Instance.EnsureInTransaction(doc)
for number in views:
try:
newbox = app.Create.NewBoundingBoxXYZ()
newbox.Max = UnwrapElement(Max.ToXyz)
newbox.Min = UnwrapElement(Min.ToXyz)
box.append(newbox)
elementlist.append[views]
except:
elementlist.append(list())
TransactionManager.Instance.TransactionTaskDone()

OUT = elementlist

Once i run the the dynamo script, it does work, does create the view, but gives back an empty list as output because it does not create the scope boxes (like in the image)

Can anyone help me with the code and show me what i’m doing wrong?

thanks!

0 Likes

#2

Hi Spijkerman

I wanted to do something to with scope boxes
see my topic:

maybe some answers off the experts can help you

maybe this post from the building coder can help you

i am stil learning python (net yet good in it)

BTW
revit API does not support creation off scope boxes
i looked it up and i think al the experts are right

nico

0 Likes

#3

Take a look at Modelical, there’s a Scope Boxes to Views node in it that could help (description: “Create as many dependent view as needed to selected views to apply selected Scope Boxes”)…

0 Likes

#4

@Nico_Stegeman,

You cannot CREATE a new scope box, but if one exist you can assign it to a view.

0 Likes

#5

@s.spijkerman,

Please refer to: How to get help on the Dynamo forums for information on how to properly post code on this blog.

Cheers!

0 Likes

#6

Actually, you can create a new scope box using Dynamo. The API gives you acces to the PostableCommands (your toolbar buttons basically). Have a look at the following code…

import clr

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

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

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

pCmd = RevitCommandId.LookupPostableCommandId(PostableCommand.ScopeBox)

This will initiate the create scope box command and let you draw one insitu.

A bit of a hack but does the trick. :stuck_out_tongue_winking_eye:

3 Likes

#7

@Daniel_Woodcock1,

Great suggestion, but imagine that you put this in a loop and now a user has to click twice for every dependant view that gets created. It will be a bit of a hassle. Until we are able to pass arguments into postable commands I can’t suggest them to others as workable solutions. Also, you are missing one last line that will actually prompt the command:

uiapp.PostCommand(pCmd)
3 Likes

#8

@Konrad_K_Sobon

Haha, oops! That is the most important line, my bad! Thanks for pointing that out.

Yeah, in this context it wouldn’t be ideal unless you could zoom the view extents and programmatically get two points in the UI space as mouse clicks. There is also the other matter of how you continue postable commands downstream as they return null. There are ways to get around this but super-hacky.

2 Likes

#9

Well to that point currently Dynamo doesn’t support setting active view so that only reinforces my point that i would stay away from workflows that require user input in a loop like that. It’s very similar to plotting 100s of sheets to PDF and forgetting to have default print location set…now you are clicking OK for every view. It’s bad.

Ps. What’s the hacky way of programmatically setting inputs into postable commands? Care to share?

2 Likes

#10

Yeah, I do wish changing view wasn’t prohibited sometimes.

What I meant is when you create a scope box via postable command it returns null although it has clearly placed one. But typically you want the output that element downstream to manipulate it somehow. The way you could do this is finding the last ElementId created as it will be the largest integer value. It is not the nicest method but works.

But, we’ve both agreed this is not a solution for this problem, but you can create scope boxes through Dynamo, just the same way you would in Revit.

1 Like

#11

Hi Daniel and Konrad

Good thinking
i have tried youre script and indeed with dymamo we can create a scope box
and i agree it is not the solution for this problem and mine problem

thanks for your effort :+1:

1 Like