save plugins Fusion 360
This commit is contained in:
65
zoom_test/zoom_test.py
Normal file
65
zoom_test/zoom_test.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# Author-
|
||||
# Description-
|
||||
|
||||
import adsk.core
|
||||
import adsk.fusion
|
||||
import adsk.cam
|
||||
import traceback
|
||||
|
||||
|
||||
def run(context):
|
||||
ui = None
|
||||
try:
|
||||
app = adsk.core.Application.get()
|
||||
ui = app.userInterface
|
||||
|
||||
zoom_camera(app, app.activeViewport)
|
||||
# ui.messageBox('Hello script')
|
||||
|
||||
except:
|
||||
if ui:
|
||||
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
|
||||
|
||||
|
||||
def zoom_camera(app: adsk.core.Application, view: adsk.core.Viewport):
|
||||
try:
|
||||
camera = view.camera
|
||||
eye = camera.eye
|
||||
target = camera.target
|
||||
|
||||
eye_x = eye.x
|
||||
eye_y = eye.y
|
||||
eye_z = eye.z
|
||||
|
||||
tgt_x = target.x
|
||||
tgt_y = target.y
|
||||
tgt_z = target.z
|
||||
|
||||
eye_tgt_vector = eye.vectorTo(target)
|
||||
|
||||
eye_tgt_vector.scaleBy(0.5)
|
||||
|
||||
new_x = eye_tgt_vector.asPoint().x
|
||||
new_y = eye_tgt_vector.asPoint().y
|
||||
new_z = eye_tgt_vector.asPoint().z
|
||||
# eye.set(eye_x - new_x, eye_y - new_y, eye_z - new_z)
|
||||
eye = adsk.core.Point3D.create(
|
||||
eye_x - new_x, eye_y - new_y, eye_z - new_z)
|
||||
# eye.translateBy(eye_tgt_vector)
|
||||
eye = adsk.core.Point3D.create(100, 100, 100)
|
||||
camera.eye = eye
|
||||
fit = camera.isFitView
|
||||
base = camera.viewExtents
|
||||
base = base*2
|
||||
camera.viewExtents = base
|
||||
view.camera = camera
|
||||
view.refresh()
|
||||
|
||||
ui = app.userInterface
|
||||
ui.messageBox('Eye: {0}, {1}, {2} \ntarget: {3}, {4}, {5}'.format(
|
||||
eye.x, eye.y, eye.z, target.x, target.y, target.z))
|
||||
|
||||
except:
|
||||
ui = app.userInterface
|
||||
if ui:
|
||||
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
|
||||
Reference in New Issue
Block a user