Set Annotation Crop

I’m working on a graph to locate Viewports consistently on Sheets.
I have one almost working, but its problem is that the Annotation Crop can vary between the Views. So, while I can get the lower left corner in the same place for all Views, the modeled elements aren’t in the same place everywhere.
What I’m attempting now is to:

  • Save the Crop settings for each View
  • Set every View’s Annotation Crop to the same value
  • Align all the Views
  • Set the Crops back to their original value
    I’ve gotten a lot of help from this thread
    Viewport's CropBox
    and I have everything working except the final one. I don’t know how to pass a list into a Python node and have it operate on the second level.
    Can anyone point me to an example of that?
    Here’s my slightly modified version of andrea’s SetAnnotationSize.dyn
    MySetAnnotationSize.dyn (2.3 KB)
    If I pass in separate values (View ID, Bottom size, Left size, top, right) it works fine.
    But I want to pass in a list of lists for multiple Views. Like this:
    ViewCrop
    (Sorry for the multiple edits)

Hey DaveP, how did you go with this?
We have a script that can align to centre, bottom left, bottom right, etc, but it is viewing the annotation crop as the outer boundary to align to. I either need it to see the crop box as the boundary to align, or something like what you’re doing where you store settings, reset, align, then reapply.

Here’s my finished graph.
Align Views on Sheets.dyn (53.2 KB)
There’s a (green) group in the middle that set the crops via Python.
I did just leave it where it sets all Annotation Crops the same.
It does not restore them after moving

Hi Dave

I m trying to Set every View’s Annotation Crop to the same value
I tried to see the Script that you put in your message
MySetAnnotationSize.dyn
but it s empty
can you help me please with that
Thanks

That version is obsolete.
You should download the Align Views on Sheets.dyn one in my August 2018 post

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

import clr
clr.AddReference('RevitAPI')
import Autodesk.Revit.DB

import clr
clr.AddReference("RevitNodes")
import Revit

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

#The inputs to this node will be stored as a list in the IN variables.
if isinstance(IN[0], list):
	views = UnwrapElement(IN[0])
	Bsize = IN[1]/10
	Lsize = IN[2]/10
	Rsize = IN[3]/10
	Tsize = IN[4]/10

else:
	views = [UnwrapElement(IN[0])]

	
listout = []
for view in views:
	regionMan = view.GetCropRegionShapeManager()
	TransactionManager.Instance.EnsureInTransaction(doc)
	try:
		regionMan.BottomAnnotationCropOffset = Bsize
		regionMan.LeftAnnotationCropOffset = Lsize
		regionMan.RightAnnotationCropOffset = Rsize
		regionMan.TopAnnotationCropOffset = Tsize
		listout.append(view)
	except:
		listout.append("failed")
	
	TransactionManager.Instance.TransactionTaskDone()


#Assign your output to the OUT variable.
OUT = listout

Create a Python script with 0-4 input fields
Input 0 -=FloorPlans
Input 1-4 = Top, right, left, bottom sides of the annotation crop - can also be used wit a number slider, but i prefered a code block

I don’t really know how it handles the units, but this worked for me at setting the crop to the minimum amount possible.

2 Likes

Thank you, exactly what I needed this morning:

Small improvement for other people with regards to the Units. Now it works in mm.

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

import clr
clr.AddReference('RevitAPI')
import Autodesk.Revit.DB

import clr
clr.AddReference("RevitNodes")
import Revit

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)


#Set the Conversion Factor
cf = 304.8
#The inputs to this node will be stored as a list in the IN variables.
if isinstance(IN[0], list):
	views = UnwrapElement(IN[0])
	Bsize = IN[1]/cf
	Lsize = IN[2]/cf
	Rsize = IN[3]/cf
	Tsize = IN[4]/cf

else:
	views = [UnwrapElement(IN[0])]
	    	
listout = []
for view in views:
	regionMan = view.GetCropRegionShapeManager()
	TransactionManager.Instance.EnsureInTransaction(doc)
	try:
		regionMan.BottomAnnotationCropOffset = Bsize
		regionMan.LeftAnnotationCropOffset = Lsize
		regionMan.RightAnnotationCropOffset = Rsize
		regionMan.TopAnnotationCropOffset = Tsize
		listout.append(view)
	except:
		listout.append("failed")
	
	TransactionManager.Instance.TransactionTaskDone()


#Assign your output to the OUT variable.
OUT = listout
3 Likes

I’m not getting any results from this python script. There also are no errors or warnings reported just no discernible result whatsoever.I’m trying to run it using Imperial units, but for all attempts modifying the conversion factor etc. the annotation crop doesn’t change. What else needs to be done for this to affect the annotation crop? Does the crop element have to be collected separately from the view or what am I missing? Thanks.

Did you use the exact same node to get views? (from Modelical nodes)
Can you share a screenshot of what you did exactly?
Also, you need to be in a floor plan view for this to work…

I managed to complete this code, with a little bit of tweaking…
The code gets rooms, and makes new Floor and Ceiling plans from them, then
sorts the rooms and places them on sheets
It works like a charm for me :slight_smile:

Update to my older (deleted) post:
2.1 Create floor and ceiling plans for rooms and trim annotation crop and place floor plans on sheets V3.dyn (94.1 KB)

I hope this helps

@Cody_Winchester I think the reason it wasnt working for you is due to a minor code error whereby @Bjorn_Keulemans1 was defining inputs within an if statement.

So if you fed the python a single view the offset input variables were not being defined.

See below code where they are instead defined outside of the if statement so it should work globally within the code.

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

import clr
clr.AddReference('RevitAPI')
import Autodesk.Revit.DB

import clr
clr.AddReference("RevitNodes")
import Revit

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)


#Set the Conversion Factor
cf = 304.8
Bsize = IN[1]/cf
Lsize = IN[2]/cf
Rsize = IN[3]/cf
Tsize = IN[4]/cf

#The inputs to this node will be stored as a list in the IN variables.
if isinstance(IN[0], list):
	views = UnwrapElement(IN[0])
	
else:
	views = [UnwrapElement(IN[0])]
	    	
listout = []
for view in views:
	regionMan = view.GetCropRegionShapeManager()
	  TransactionManager.Instance.EnsureInTransaction(doc)
	try:
		regionMan.BottomAnnotationCropOffset = Bsize
		regionMan.LeftAnnotationCropOffset = Lsize
		regionMan.RightAnnotationCropOffset = Rsize
		regionMan.TopAnnotationCropOffset = Tsize
		listout.append(view)
	except:
		listout.append("failed")
	
	TransactionManager.Instance.TransactionTaskDone()
	
OUT = listout

As for no error message being thrown, for future reference, if you move code outside of a ‘try / except’ the Python will tell you why it failed. For example, in this case that would look like this:

for view in views:
    regionMan = view.GetCropRegionShapeManager()

    TransactionManager.Instance.EnsureInTransaction(doc)
	
    regionMan.BottomAnnotationCropOffset = Bsize
    regionMan.LeftAnnotationCropOffset = Lsize
    regionMan.RightAnnotationCropOffset = Rsize
    regionMan.TopAnnotationCropOffset = Tsize
    listout.append(view)
	
    TransactionManager.Instance.TransactionTaskDone()

Hope that helps,
Jake