I’ve tried to add some other functionality to the code of a previous post:
I’d like to:
- Choose between active view or a list of views
- Choose between Hide or Show Level Names
See below code. It works but there’s lots of code repetition.
What’s the best way to avoid that?
is it possible to create a function the swaps the methods HideBubbleInView & ShowBubbleInView?
When I choose the current view I cannot use the second for loop of it gives me an error (for v in view) so I have to repeat the code.
Any suggestion is much appreciated.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk
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
a = UnwrapElement(IN[0])
CurrentViewOrMultiple=IN[1]
if CurrentViewOrMultiple:
view=UnwrapElement(IN[2])
else:
view=UnwrapElement(IN[3])
HideOrShow=IN[4]
TransactionManager.Instance.EnsureInTransaction(doc)
if HideOrShow:
for i in a:
if not CurrentViewOrMultiple:
for v in view:
i.HideBubbleInView(DatumEnds.End0,v)
i.HideBubbleInView(DatumEnds.End1,v)
elif CurrentViewOrMultiple:
v=view
i.HideBubbleInView(DatumEnds.End0,v)
i.HideBubbleInView(DatumEnds.End1,v)
elif not HideOrShow:
for i in a:
if not CurrentViewOrMultiple:
for v in view:
i.ShowBubbleInView(DatumEnds.End0,v)
i.ShowBubbleInView(DatumEnds.End1,v)
elif CurrentViewOrMultiple:
v=view
i.ShowBubbleInView(DatumEnds.End0,v)
i.ShowBubbleInView(DatumEnds.End1,v)
TransactionManager.Instance.TransactionTaskDone()
OUT = 0