0: ortho_w = min(1.0, w / h) else: ortho_w = 1.0 cam.par.orthowidth = ortho_w except Exception: pass finally: _updating_ortho = False def onValueChange(par, val, prev): if par.name == 'Usecamera': prin"> 0: ortho_w = min(1.0, w / h) else: ortho_w = 1.0 cam.par.orthowidth = ortho_w except Exception: pass finally: _updating_ortho = False def onValueChange(par, val, prev): if par.name == 'Usecamera': prin"> 0: ortho_w = min(1.0, w / h) else: ortho_w = 1.0 cam.par.orthowidth = ortho_w except Exception: pass finally: _updating_ortho = False def onValueChange(par, val, prev): if par.name == 'Usecamera': prin">
# me - this DAT
# par - the Par object that has changed
# val - the current value
# prev - the previous value
#
# Make sure the corresponding toggle is enabled in the Parameter Execute DAT.

import webbrowser

_updating_ortho = False

def _update_ortho_width():
	"""Set camera ortho width so the preview frames portrait canvases correctly.

	The Trace SOP normalises the longer axis to -0.5..0.5.  For landscape
	the SOP content width is 1.0 and orthowidth=1 works.  For portrait
	the content width is W/H (<1), so the camera must zoom in to match.
	"""
	global _updating_ortho
	if _updating_ortho:
		return
	cam = op('default_cam')
	if cam is None:
		return
	try:
		_updating_ortho = True
		w = float(parent.svg.par.Canvasmm1)
		h = float(parent.svg.par.Canvasmm2)
		if h > 0:
			ortho_w = min(1.0, w / h)
		else:
			ortho_w = 1.0
		cam.par.orthowidth = ortho_w
	except Exception:
		pass
	finally:
		_updating_ortho = False

def onValueChange(par, val, prev):

	if par.name == 'Usecamera':
		print(val)
		if val == 'on':
			op('render1').bypass = False
			_update_ortho_width()
		else:
			# Issue 6 fix: was False (bug), should be True
			op('render1').bypass = True

	elif par.name in ('Canvasmm1', 'Canvasmm2'):
		_update_ortho_width()

	else:
		pass
	return

def _reset_camera():
	"""Reset default_cam to factory defaults."""
	cam = op('default_cam')
	if cam is None:
		print('WARNING: default_cam not found')
		return

	# Xform tab
	cam.par.tx = 0
	cam.par.ty = 0
	cam.par.tz = 5
	cam.par.rx = 0
	cam.par.ry = 0
	cam.par.rz = 0
	cam.par.sx = 1
	cam.par.sy = 1
	cam.par.sz = 1
	cam.par.px = 0
	cam.par.py = 0
	cam.par.pz = 0

	# View tab
	cam.par.projection = 1		# Orthographic
	cam.par.orthoorigin = 0		# Center
	cam.par.orthowidth = 1
	cam.par.near = 0.1
	cam.par.far = 1000
	cam.par.fox = 11.416
	cam.par.winx = 0
	cam.par.winy = 0
	cam.par.winsize = 1
	cam.par.winroll = 0
	cam.par.ipdshift = 0
	cam.par.winrollpivot = 1	# Camera Origin

	_update_ortho_width()
	print('Camera reset to defaults')

def onPulse(par):
	print()
	if par.name 	== 'Savesvg':
		parent.svg.Save()

	elif par.name	== 'Resetcamera':
		_reset_camera()

	elif par.name 	== 'Axidrawwiki':
		url 		= parent.svg.Axidocumentation
		webbrowser.open_new(url)

	elif par.name 	== 'Axidrawpdf':
		url 		= parent.svg.Axipdf
		webbrowser.open_new(url)

	elif par.name	 == 'Svgwritedocs':
		url 		= parent.svg.Svgwritedocumentation
		webbrowser.open_new(url)

	else:
		pass

	return

def onExpressionChange(par, val, prev):
	if par.name in ('Canvasmm1', 'Canvasmm2'):
		_update_ortho_width()
	return

def onExportChange(par, val, prev):
	return

def onEnableChange(par, val, prev):
	return

def onModeChange(par, val, prev):
	return