Insert Legend in sheet


#8

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]


#9

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)


Repeating and maintaining run order of User Input
#10

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


Dynamo Sheets with view use
#11

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.


#12

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:


#13

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


Creating Standard Sheet
#14

Thank you Dan, you are so great


#15

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.


#16

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.


#17

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


#18

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


#19

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…


#20

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


#21

Hi Daniel,

Thanks for sharing the script. I tried to insert the panel schedule into the sheet using the script but it looks like dynamo does not consider view schedules and panel schedules as the same. Could you please give me some tips about inserting the panel schedules to sheets?

Thank you very much


#22

It’s interesting - I actually did get it to work after trying another legend on a another sheet. It will fail if the legend is already on the sheet like you say, however it will continue to fail even if I delete the legend from the sheet and try again. It’s like it works one time and then it won’t work again even if the legend is deleted.

Regardless - this is great! Thank you for helping me out with it.


#23

Thanks for the feedback @skycostello,

I tested deleting and adding while I was creating this and worked fine, I will look into it further and see if I can replicate the issue. If I can I’ll update and post back here.

Cheers,
Dan


#24

Hi @lyliyiwei,

I’ll have a look at this also, I don’t work with panel schedules so will see if I can fold this in and I’ll post an updated solution.

Cheers,
Dan


#25

Hi Dan:

Thanks for your reply! I looked into the Revit API Doc, there are some classes related to panel schedule under the Autodesk.Revit.DB.Electrical Namespace. However, I am not familiar with python or C#…just hope the information is helpful.

Thanks for your help again!

Yiwei


#26

Hi all,

From the comments by @skycostello and @lyliyiwei i have added some further functionality. The updates are as follows…

Updates:

  • Panel Schedules are now supported and can be placed by point.
  • Refresh port added to allow user to force a re-execution of the node, This should resolve the error of supported view types not placing on sheet if they were deleted or the previos transaction was rolled back (undo command)

Screenshots:


Script
This is the updated script…
LegendPlacer.dyn (20.4 KB)

I have come to realise this is no longer a “legend” placer as it handles most things. :laughing:

Let me know if this works fine though, I have no issues in testing but I can’t test every situation.

Cheers,
Dan


Packing Lots of Views onto Lots of Sheets
Duplicate legend and rename duplicated legend with sheet number
#27

You are awesome. Thanks very much