Insert Legend in sheet

Hi all,

is it possible to insert a legend in list of existing sheet ?

2 Likes

What do you mean in ā€œListā€? Do you mean a legend copier? So to copy/place a Legend View to multiple SheetViews?

I created a quick script that places legends on sheet. Please see image. It essentially wants a view (Your legend), a list of sheets and a location. It will handle which Legends Have successfully been created and which ones failed. You could use this as a Legend Copier pretty easily with some minor tweaks. LegendPlacerLegendPlacer

7 Likes

Thank you Danielā€¦ I will install the new version of Dynamo (i use the 0.8 old version) and i will try your code.

Ā 

You are welcome. The python code should be compatible with all versions of Revit so you can use this 2014 onwards, but I did develop in Dynamo 1.0. you can build upon this a lot more, it was just a quick proof of concept to get you started.

Thanks for sharing this Daniel!

1 Like

@Daniel_Woodcock1 I tried your python script, but it doesnā€™t place any legends on my sheets.

It teels me this:

and I used this part of your python sentence:
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

legend = 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 = Viewport.CanAddViewToSheet(doc, sheet.Id, legend.Id)
if canAddToSht:
try:
TransactionManager.Instance.EnsureInTransaction(doc)
viewport = Viewport.Create(doc, sheet.Id, legend.Id, loc)
TransactionManager.Instance.TransactionTaskDone()
viewports.Add([viewport,sheet])
except:
failed.Add([ā€œFailedā€,sheet])
else:
failed.Add([ā€œFailedā€,sheet])

OUT = [viewports, failed]

Hi @simme13mu,
It appears you are passing in a Schedule View, not a legend. The node I posted earlier in this thread takes the following parameters:-
ā€¢ IN[0] - ViewType of Legend (Single Legend view Only)
ā€¢ IN[1] - ViewType of ViewSheet (Supports list of ViewSheet)
ā€¢ IN[2] - Placement Point (Single Point Only)

Since it looks like you are trying to add a schedule, I have updated the script quickly to allow you to do so. However, please note since schedules do not have the same stringent constraints as all other views, this means you can place the same Schedule on the same view multiple times. Please make sure you take that into account.

The updated code, Copy paste into your node and indent accordingly. Let me know if you have any problems with this. :wink:

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

view = 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 = True;
if view.ViewType != ViewType.Schedule:
canAddToSht = Viewport.CanAddViewToSheet(doc, sheet.Id, view.Id)
if canAddToSht:
try:
if view.ViewType == ViewType.Schedule:
TransactionManager.Instance.EnsureInTransaction(doc)
viewport = ScheduleSheetInstance.Create(doc, sheet.Id, view.Id, loc)
TransactionManager.Instance.TransactionTaskDone()
viewports.Add([viewport,sheet])
else:
TransactionManager.Instance.EnsureInTransaction(doc)
viewport = Viewport.Create(doc, sheet.Id, view.Id, loc)
TransactionManager.Instance.TransactionTaskDone()
viewports.Add([viewport,sheet])
except:
failed.Add([ā€œFailedā€,sheet])
else:
failed.Add([ā€œFailedā€,sheet])

OUT = [viewports, failed]

1 Like

Hi,

I have gotten this working with some input nodes (dropdown and checkbox) but cannot get this to refresh/prompt for user input each time the script is run by the user. Can anyone help with this?

Thanks,

Place Legends on Multiple Sheets v2.dyn (26.7 KB)

1 Like

Hi @Ewan_Opie,

Apologies for the late reply, I havenā€™t been on here in a while.

I see what you are trying to do, please see my comment on the other post you submitted (below)

https://forum.dynamobim.com/t/repeating-and-maintaining-run-order-of-user-input/6562

In short, you can add a dummy port to the python script or custom component and plug in a boolean toggle, then switch this before running the script again, it doesnā€™t matter if it true or false, as long as you change the value dynamo will register a node changed event and queue it up for re-execution. A more thorough explanation in your other post.

On another note, Have you thought about using a dedicated legend copier/placer add-in? There are free ones out there, if i remember rightly, lmnts architects do one and iā€™m sure iā€™ve seen a few others as well as written one myself.

Cheers,
Dan

Thanks for the Tip, Iā€™m downloaded the LMNts add-in for testing now. I just approached this from Dynamo to highlight a point to our Revit team, that the seconds saved when using Dynamo on a simple task really do add up during the course of a day/project.

We are just adopting a more proactive approach to using Dynamo, and I am spearheading this incentive in our company. Going well so far, with the help of community members such as yourself. Thanks again.

Ah, fair enough! Yeah, Dynamo is a massively powerful tool and time saver. Iā€™m sure your company will see the benefits in no time! Good luck in your Dynamo endeavours though! :slight_smile:

Hi all,

I have added some additional functionality and reposting for completeness.

Updated features includes:

  • Support to add KeyNotes (as requested in another post) so now Schedules/Legends & Keynote Legends are supported as valid views to place.
  • Handling for single View Sheet only (had to be a list of views previously)
  • You can now add multiple views (Schedules/Legends & Keynote Legends) to View Sheet(s).(Note: List lengths of Views to add and Locations must match)

Image of updated Script (Create custom nodes and add to your own library if you wish to keep your graph cleaner)

dyn file of updated scriptā€¦
LegendPlacer.dyn (19.1 KB)

Cheers,
Dan

8 Likes

Thank you Dan, you are so great

1 Like

Hi,

I slightly modified the script to adapt it to my case.
I am trying to assign a specific legend (Legend U) to all the sheets of a specific discipline (U - Ventilation). I modified the script in a way that it automatically counts how many legends have to be placed and the insertion point for each. The coordinates of the location on the sheet are calculated depending on the format (A1, etc.).

The main problem is that it attaches the legend (red box in the image) where it is defined by the script (purple circle) but using a central point of the legend view while I would like to use the origin of the legend view (which corresponds to the green circle). How can I find out the coordinates of the point that it uses to attach the legend view in order to modify them?

Many thanks!

S.

Question - Iā€™m a bit of a beginner here and Iā€™m having some issues. I seem to be able to have it read the legend I am trying to place as well as the sheet Iā€™d like to place it on. Iā€™ve also disconnected to have a single coordinate input. SOmething still seems to be breaking when I run the process. I get an error that reads

ā€œWarning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File ā€œā€, line 35, in
AttributeError: ā€˜strā€™ object has no attribute 'Idā€

Any idea what Iā€™m missing? Thanks for your help.

Hi @skycostello,

You are pretty close, but you are passing a string (text) to the input ā€œSheetsā€, this needs to be a sheet element and not just text. To fix this, in the ā€œget all sheets in projectā€ group, try changing the Index in your code block to be [0][128].

Let me know if that works! :wink:

Cheers,
Dan

Youā€™re looking for the lower and upper values of the viewport of the legend. There is a node for that just canā€™t remember what package :thinking: But Iā€™m sure if you look it up youā€™ll find it

Thanks Daniel - still seems to be hitting a snag when I change that code block to reference the element ID instead of the sheet number. Now it runs but it seems to fail to do what itā€™s supposed to do. Iā€™m sure Iā€™m missing something simple hereā€¦

Hmm, not sure @skycostello,

Have you checked that itā€™s definitely not on sheet already, thatā€™s the only time Iā€™ve seen that node fail where you have run successfully once, then run again and it canā€™t place as there is one there already.

Cheers,
Dan