save plugins Fusion 360
This commit is contained in:
58
demo/demo.py
Normal file
58
demo/demo.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# Fusion360API Python script
|
||||
import adsk.core, adsk.fusion, adsk.cam, traceback
|
||||
import math, random
|
||||
|
||||
# Number of divisions during one revolution
|
||||
COUNT = 60
|
||||
|
||||
def run(context):
|
||||
ui = None
|
||||
try:
|
||||
app: adsk.core.Application = adsk.core.Application.get()
|
||||
ui = app.userInterface
|
||||
|
||||
# get state
|
||||
vi :adsk.core.Viewport = app.activeViewport
|
||||
camera :adsk.core.Camera = vi.camera #This is a deep copy.
|
||||
eye :adsk.core.Point3D = camera.eye
|
||||
tgt :adsk.core.Point3D = camera.target
|
||||
up :adsk.core.Vector3D = camera.upVector
|
||||
baseArea = camera.viewExtents
|
||||
|
||||
# get matrix
|
||||
front :adsk.core.Vector3D = eye.vectorTo(tgt)
|
||||
right :adsk.core.Vector3D = up.copy()
|
||||
right = right.crossProduct(front)
|
||||
mat :adsk.core.Matrix3D = adsk.core.Matrix3D.create()
|
||||
mat.setWithCoordinateSystem(tgt, right, front, up)
|
||||
|
||||
# get position & ratio
|
||||
unit = math.radians(360 // COUNT)
|
||||
rads = [unit] * COUNT
|
||||
ratios = [random.uniform(0.1, 5.0) for _ in range(COUNT)]
|
||||
if 360 % COUNT != 0:
|
||||
rads.append(math.radians(360 % COUNT))
|
||||
ratios.append(1)
|
||||
|
||||
# show
|
||||
camera.isSmoothTransition = False
|
||||
for rad, ratio in zip(rads, ratios):
|
||||
mat.setToRotation(rad, up, tgt)
|
||||
eye.transformBy(mat)
|
||||
up.transformBy(mat)
|
||||
mat.setToRotation(rad, right, tgt)
|
||||
eye.transformBy(mat)
|
||||
up.transformBy(mat)
|
||||
# mat.setToRotation(rad, front, tgt)
|
||||
camera.eye = eye
|
||||
camera.upVector = up
|
||||
# zoom = baseArea * ratio
|
||||
# camera.viewExtents = zoom
|
||||
|
||||
vi.camera = camera
|
||||
vi.refresh()
|
||||
adsk.doEvents()
|
||||
|
||||
except:
|
||||
if ui:
|
||||
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
|
||||
Reference in New Issue
Block a user