Hello Dynamo Friends
I have a python script that does the following tasks successfully:
- Get a bunch of Viewports
- Get Sheet from Viewports
- Get all Viewports on sheet and their Detail Numbers (example 3,4,5)
- Calculate Detail Numbers for new Viewports (consecutive: example 6,7,8)
- Set these new Detail Numbers to some new Viewports.
Now I want to edit the code to make it also work for multiple sheets. My problem is i don´t really know how to start. Should i make a viewport list with sublists for every sheet? And then work with this leveled list? Zip sublists and sheets together? How can i even make my viewport sublists?
The code should make the following tasks possible:
- Get a bunch of Viewports
- Get the multiple Sheets the Viewports are placed on.
- Get all Viewports on all Sheets an their Detail Numbers (example sheet1: 3,4,5, sheet2:18,19,20, sheet3:34,35,36)
- Calculate Detail Numbers for new Viewports (consecutive: example sheet1: 6,7,8, sheets2:21,22,23, sheet3: 37,38,39)
- Set these new Detail Numbers to the Viewports on multiple sheets.
(Keep in mind, this is only a part from a pretty long python code)
Would really appreciate any push in the right direction!
Kind Regards
def CurrentViewports_DetailNumbers(viewports):
CurrentViewports_DetailNumbers = []
for viewport in viewports:
SheetId = viewport.SheetId
Sheet = doc.GetElement(SheetId)
CurrentViewportIDs = Sheet.GetAllViewports()
CurrentViewports= [doc.GetElement(CurrentViewportID) for CurrentViewportID in CurrentViewportIDs]
for CurrentViewport in CurrentViewports:
CurrentViewports_DetailNumber = CurrentViewport.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString()
try:
integer=int(CurrentViewports_DetailNumber)
CurrentViewports_DetailNumbers.append(integer)
except:
pass
return CurrentViewports_DetailNumbers
def NewViewports_DetailNumbers():
NewViewports_DetailNumbers = []
CurrentViewports_DetailNumbers = []
for NewViewport in NewViewports:
NewViewports_DetailNumber = NewViewport.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString()
try:
integer=int(NewViewports_DetailNumber)
NewViewports_DetailNumbers.append(integer)
except:
pass
def CreateDetailNumbers():
Final_DetailNumbers = []
MaximumDetailNumber = int(max(CurrentViewports_DetailNumbers))
n = 100
numbers = []
for i in range(MaximumDetailNumber+1, n+1):
numbers.append(i)
for i in numbers:
if str(i) not in CurrentViewports_DetailNumbers:
Final_DetailNumbers.append(str(i))
return Final_DetailNumbers
def SetDetailNumbers():
Final_DetailNumbers = CreateDetailNumbers()
for V, D in zip(NewViewports, Final_DetailNumbers):
set = V.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).Set(D)
elements = CurrentSelection()
viewports = FilterViewports()
TransactionManager.Instance.EnsureInTransaction(doc)
if viewports:
CurrentViewports_DetailNumbers = CurrentViewports_DetailNumbers(viewports)
ViewFromViewports = ViewFromViewports()
DuplicatedViews = DuplicateViews(ViewFromViewports)
NewViewports = CreateViewport(DuplicatedViews, viewports)
SetDetailNumbers = SetDetailNumbers()
TransactionManager.Instance.TransactionTaskDone()
OUT = SetDetailNumbers