Legend Corruption - Revit Legend bounds Larger than contents

Got my Revit View Title Position Reset working.
But I broke all my legends by checking the “crop”. (Dynamo/Revit bug?)

Is there a more effective way to fix this issue other than copying and recreating the legends?

#https://forum.dynamobim.com/t/set-crop-region-visible-to-no/44658/4
##from rpw import db.element.Element
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

from functools import wraps
from Autodesk.Revit.Exceptions import InvalidOperationException

ViewsDone=[]
ViewPreVis=[]
ViewPreCrop=[]
ViewPreAnno=[]
##https://www.revitapidocs.com/code/#Python_RevitTransactionDecorator-py
def revit_transaction(transaction_name):
    def wrap(f):
        @wraps(f)
        def wrapped_f(*args):
            try:
                t = Transaction(doc, transaction_name)
                t.Start()
            except InvalidOperationException as errmsg:
                print('Transaciton Error: {}'.format(errmsg))
                return_value = f(*args)
            else:
                return_value = f(*args)
                t.Commit()
            return return_value
        return wrapped_f
    return wrap

#@revit_transaction('ViewCropReset')        ##Need to understand how wrapping works and how to call
def ViewCheck (views):
    for v in views:
        v=UnwrapElement(views)
        ViewPreVis = v.CropBoxVisible
        ViewPreCrop = v.CropView
        ViewPreAnno = v.AnnotationCrop

#The inputs to this node will be stored as a list in the IN variables.
views = UnwrapElement(IN[0])

ViewCheck (views)

#TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable.
OUT = [ViewPreVis,ViewPreCrop,ViewPreAnno]

Reset-View-Title-Locations-R22±v0.00.dyn (43.1 KB)

@Ron_Allen ,

did use any .dwg “import” ? maybe the view is contaminated by random lines or points?

Are they actual Legend views? Legends don’t have a crop.

If they’re plan views then it may be a scaling issue. It looks like the crop has the correct shape/ratios but is just too big.

Your code also looks off. You have for v in view: but then set v equal to the unwrapped list of views. I assume this should just be the unwrapped view itself (which is also redundant since you unwrap the views before feeding them to ViewCheck).

I’m also not sure what your next steps are, but I don’t think your final output OUT is returning anything. Your function ViewCheck doesn’t return any values. You would likely want to add that output to the function itself and then have OUT = ViewCheck(views).

Nope. Just checking the “cropt limits” of the drafting view breaks it.

They are actual legend views. I found this trying to reset all crop regions for all views in a project… Turn on crop views and annotations.

I would recommend filtering out views that don’t allow crop.

Thanks Nick. Yeah, it’s odd. I was starting to look at the py wrapper utility but I think it is gone in 2022.

I filtered them out moving forward… but as for all the broken ones- ugh.

I was hoping for a way to reset the limits of the legend view having initially broken them all with the script. Must be an glitch/error in the '22 database. I’ll try an audit repair.

Does removing them from the sheet not reset them? If not then audit or manual reset may be the only option.

Thanks. Nope : (

Duplicating them duplicates the issue.

New>Copy/Paste is the only way to fix it.

thanks for offering the suggestions!

FYI, Legends DO have crop boundaries and you can ONLY turn them on or off in the API. Ran into this with a script that was to turn all crops on / off on a sheet, and it broke all the Legends and it took a little bit before I figured out.

Here i have two legends with the same items in them, but you can see the “Crop Region” of Legend 1 is different.

5 Likes

Very interesting. Nice find, @SeanP. Does setting the crop back to false fix the issue?

1 Like

Yes @Nick_Boyts, when I ran into it before it was resolved by setting it back. We too initially thought it was corrupted and tried to copy, but the setting went with it.

1 Like

Also, once the region is active, you are then able to control the size on the Ribbon.

Nice find!

Can the limits be set to the bounds of the items in the box?

I suppose you could set it to something that works, but I’d just turn it back off and then not have to worry about it.

Use this to reset it.

element.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION).Set(0)

1 Like