Insert Legend in sheet

Hi @PR_matthew.terry,

Apologies for the delay in response, I was on holiday and miles away from technology. From observation I believe the sheets should be a single list rather than a nested list as you currently have it, however, I have also updated the code some and the new updates can be found in this thread…

Place multiple views on multiple sheets by coordinates

This should be able to place pretty much any View Type and you can visualise them pre-placement (if you want).

Let me know how you get on.

Cheers,
Dan

Does anyone have a workflow for getting the XY of a legend placed on a sheet?

A legend is categorized as a schedule.

schedule = UnwrapElement(IN[0])
point = schedule.Point

Hi @Architecture_Faster,

I assume you are making a legend copier. Legends on sheet are a viewport element. There are probably a few packages out there that have something like a viewport.centre node. I have one somewhere, but lack a pc right now.

Alternatively, you could do something like this…

https://forum.dynamobim.com/t/viewports-cropbox/10800/3?u=daniel_woodcock1

And get the centre from the polygon, or average the endpoints etc etc…

This however is a question in its own right, so you should really start a new thread. :wink:

got it thanks

@Architecture_Faster
Schedules and legends don’t actually have viewports, at least none that I could find. The code I posted above is a quick and easy way to get their location on a sheet.

Hi @Nick_Boyts,

Schedules on sheet are part of the ScheduleSheetInstance class, whereas, Legends are viewport based View Elements. So, you are correct in what you say with Schedules, but not with Legends. Observe the following…

image

ViewPort.GetBoxCenter (Py)

import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

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

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

vps = tolist(UnwrapElement(IN[0]))

outList = []

for vp in vps:
	outList.append(vp.GetBoxCenter().ToPoint())

OUT = outList

ScheduleSheetInstance.Point (Py)

import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

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

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

vps = tolist(UnwrapElement(IN[0]))

outList = []

for vp in vps:
	outList.append(vp.Point.ToPoint())

OUT = outList

Legends however, as with drafting views, do not have a crop region like most other view type Elements. But both are viewport based when on sheet which means we can treat them like any other view type when placed on sheet (except for schedules and keynotes). :slight_smile:

Cheers,
Dan

1 Like

Weird, I could not get the viewport of my legends earlier. Thanks @Daniel_Woodcock1 for clearing this up!

1 Like

Hi everyone. I´m new in Dynamo, i need to know te coordinates of the legend. I need to place it on a specific place on my sheet but i don´t know wich number i should put on the coordinates. I hope someone could help me.
Bless from México. Tank u :slight_smile:

Hi @AntonioRojasR,

You can do this by do the placing one where you want on a sheet and using the Viewport.GetBoxCentre (Py) code supplied in this post above…

Just copy the pyrhon code into a fresh and clean python node and plug in your legend viewport.

Or you can use the place multiple views on sheet node found in this thread and use sliders to place one where you want it.

Hope this helps.

Cheers,
Dan

Hi, got this to work for a selected range of sheets by sheet number. Just curious why i get so many failed sheets? Is there a better format i should have?

1 Like

Hello,

You can find attached our workflow, which we created with all of your helpful comments.


But we have the same issue as @simvas had. Dynamo automatically place every legend using the coordinates we are giving as the legend center coordinates.
Capture2
We are trying to insert some node so Dynamo can understand that the given coordinates are from the upper left corner from the legend (where the title is), but we can’t find such packages.

Thanks in advance!

Hi,

I am new to dynamo,

do you think I can use the same way to add family to sheet?
I have the following script copied:

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
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference(“RevitAPI”)
from Autodesk.Revit.DB import *
dataEnteringNode = IN
family = UnwrapElement(IN[0])
sheets = IN[1]
loc = XYZ(IN[2].X, IN[2].Y, IN[2].Z)
viewports =
failed =
for vs in sheets:
sheet = UnwrapElement(vs)
canAddToSht = canAddToSht = Viewport.CanAddViewToSheet(doc, sheet.Id, family.Id)
if canAddToSht:
try:
TransactionManager.Instance.EnsureInTransaction(doc)
viewport = Viewport.Create(doc, sheet.Id, family.Id, loc)
TransactionManager.Instance.TransactionTaskDone()
viewports.Add([viewport,sheet])
except:
failed.Add([“Failed”,sheet])
else:
failed.Add([“Failed”,sheet])
OUT = [viewports, failed]

Unfortunately it didn’t do what I was looking for.
here is a screenshot of what I got,

Hi Dan,
I was testing your definition and it’s okay…
is there a way of choosing the viewport type from the beginning?

Hi, I get this error trying to get the schedule location?

That error looks like you aren’t iterating over the list to get single instances. Would you post the code in the node? Also, may have been better to create a new post since this one is set eral years old.

Also, see this topic for reference. Schedule location is different than Legend location.

Try verifying your code against this version by @Konrad_K_Sobon.

Get/Set Location of Schedule graphics follow up

It is your lists. You are tring to place multiple Schedules on one sheet and most likely the Place Views On Sheet node isn’t set up to do that. Test it with one schedule and see if that works. If so, you may need to rework the node or do them one by one.

1 Like

Thanks Sean, going to try the legend placer.

Hi Sorry for such a late reply, just saw this post…
i have also created a dynamo script to place multiple legends on multiple sheets.
the workflow is as below:
Create a Dummy/Reference sheet & place one instance of all the legend in exact location.
Use dynamo to query that reference sheet.
Get view ports & views of that sheet, this would give you the legends on that sheet as well.
Use data shapes package for Reference sheet selection as well as selection of legends from the reference sheet.
use data shapes again to select the sheets you want to place the legends
Now the idea is to query the view port location from reference sheet for legends & use that as locations to be placed in multiple sheets.
you would have to cycle the locations as well as the legends depending on how many sheets you are pasting the legends into.
this workflow would ensure a generic approach for almost all, your projects.
this would also ensure you dont need to worry about manual insertion of legends or moving around using sliders .
thanks

Regards
Sachin