Get Viewport and Sheet from Legend

Hello Dynamo Friends,

I have a script that duplicates views on a sheet.

01_2_View_Duplicate_WithDetailing.dyn (79.9 KB)

I want to add the ability to also duplicate Legends. The problem is that a selected Legend on a sheet gives multiple viewports, i assume a legend gives always all viewports from all sheets where it is placed.

Is there any way i can get the single viewport of my legend? Or will i have to add a workaround, get sheet numbers of the viewports and filter the one i need?

Thanks in advance! :slight_smile:

Can you do it backwards and pick the sheet and then get the Viewport on that sheet only? If not, then you’ll probably have to do as you described and filter on another parameter.

Hello Sean,

oh there was a mistake, my input is the viewport, i accidently transformed it into a view and back to a viewport, thats not necessary. So this problem is solved.

But now i still have another problem, i can`t get the right sheet from the legend, I get the projectinfo sheet :frowning: And i really have no idea how to solve that…

I need to get the sheet directly from the viewport, but it´s not a parameter:

You will need to use the SheetId parameter of the Viewport and then transform that into the actual sheet because elements don’t have a view number.

1 Like

Hello Sean,

Thank you very much, i don´t understand python yet, but i just took an Element-ID code and changed ElementID to SheetID and it works fine. Easy to get the sheet from the ID :slight_smile:

What a good start into the day :slight_smile:

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

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

def GetSheetId(item):
	if hasattr(item, "SheetId"): return item.SheetId.IntegerValue
	else: return None

items = UnwrapElement(IN[0])

if isinstance(IN[0], list): OUT = [GetSheetId(x) for x in items]
else: OUT = GetSheetId(items)
1 Like

Great job! You could also use the Element From Id node so you would have to use contains.

1 Like

Oh, thats great! Thanks for that idea, that cleans everything up!

1 Like

I´m sorry, but back to the start :confused: what I thought is not a problem now is one.

I want the script to work if a view/legend is selected or active.
When I´m in an active Legend on a sheet i get the result we already discussed above:

Because I´m in an active Legend i have no chance of getting the sheet number. I have no idea how i could get the viewport of the active Legend.

Is there some way to get the sheet (tab) that is currently open?

Another Problem: the script should only work when I´m in an active view/legend on a sheet. But it now also runs if I´m directly in the view/legend without being on the sheet. Is there a way to avoid that?

Happy about any help, stuck here again!

If there is no solution to the problem i will have to remove the ability to duplicate an active legend…but I´m so close to make the script perfect :smiley:

For now i removed the “active view” function from all of my scripts.
If someone finds this thread in the future and can answer the following question i would appreciate any help.

How to get the Sheet of a Legend when I´m on the Sheet and the Legend is active.