"""Edit basic properties of an existing drawing view."""
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
view = next(iter(drawing.activeSheet.views), None)
if not view:
return
# Update core display settings.
view.scaleValue = 0.5
view.style = adsk.drawing.DrawingViewStyleTypes.VisibleEdgesDrawingViewStyleType
view.tangentEdges = adsk.drawing.TangentEdgeDisplayTypes.OffTangentEdgeDisplayType
view.isShowInterferenceEdges = True
view.isShowThreadEdges = True
# Update center mark/line options when available.
mark_options = view.getCenterMarkOptions()
if mark_options:
mark_options.isAppliedToHoles = True
mark_options.isAppliedToRoundExtrudes = True
mark_options.isAppliedToRoundCuts = True
mark_options.isAppliedToPatterns = True
mark_options.isAppliedToFillets = False
mark_options.filletMinimumRadius = 0.0
mark_options.filletMaximumRadius = 0.0
view.setCenterMarkOptions(mark_options)
line_options = view.getCenterLineOptions()
if line_options:
line_options.isAppliedToHoles = True
line_options.isAppliedToRoundExtrudes = True
line_options.isAppliedToRoundCuts = True
view.setCenterLineOptions(line_options)
# Lens length applies only to perspective views.
if int(view.type) == int(adsk.drawing.ViewTypes.PerspectiveViewType):
view.lensLength = adsk.drawing.PerspectiveLensLengthTypes.Lens90mmPerspectiveLensLengthType
except:
if app:
app.log(traceback.format_exc())
if ui:
ui.messageBox("Failed:\n{}".format(traceback.format_exc()))