"""Apply auto-break to supported views on the active sheet."""
import adsk.core
import adsk.drawing
import traceback
def run(context):
app = None
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface if app else None
drawing = adsk.drawing.Drawing.cast(app.activeProduct) if app else None
if not drawing:
drawing_doc = adsk.drawing.DrawingDocument.cast(app.activeDocument) if app else None
drawing = drawing_doc.drawing if drawing_doc else None
if not drawing or not drawing.activeSheet or not drawing.activeSheet.views:
return
# Collect base/projected/auxiliary views only.
target_views = []
for view in drawing.activeSheet.views:
if not view:
continue
if int(view.type) in (
int(adsk.drawing.ViewTypes.BaseViewType),
int(adsk.drawing.ViewTypes.ProjectedViewType),
int(adsk.drawing.ViewTypes.AuxiliaryViewType),
):
target_views.append(view)
if not target_views:
return
drawing.activeSheet.autoBreak(target_views)
except:
if app:
app.log(traceback.format_exc())
if ui:
ui.messageBox("Failed:\n{}".format(traceback.format_exc()))