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?
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.
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 And i really have no idea how to solve that…
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
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)
I´m sorry, but back to the start 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
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.