Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.vscode/*
1 change: 1 addition & 0 deletions f360-script/External controls/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PYTHONPATH=C:/Users/gena0/AppData/Local/Autodesk/webdeploy/production/525fe9b2ece26c4d179982b11ecdfb713cb5058f/Api/Python/packages
20 changes: 20 additions & 0 deletions f360-script/External controls/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"pathMappings": [{
"localRoot": "${workspaceRoot}",
"remoteRoot": "${workspaceRoot}"
}],
"osx": {
"filePath": "${file}"
},
"windows": {
"filePath": "${file}"
},
"port": 9000,
"host": "localhost"
}]
}
12 changes: 12 additions & 0 deletions f360-script/External controls/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"python.autoComplete.extraPaths": [
"C:\\Users\\gena0\\AppData\\Roaming\\Autodesk\\Autodesk Fusion 360\\API\\Python\\defs"
],
"python.analysis.extraPaths": ["C:/Users/gena0/AppData/Roaming/Autodesk/Autodesk Fusion 360/API/Python/defs"],
"python.pythonPath": "C:/Users/gena0/AppData/Local/Autodesk/webdeploy/production/525fe9b2ece26c4d179982b11ecdfb713cb5058f/Python/python.exe",
"fusion-360-helper.enabled": true,
"fusion-360-helper.python.pythonPath": "C:\\Users\\gena0\\AppData\\Local\\Autodesk\\webdeploy\\production\\eb2a69395707b2ba8a2af9d915b9a52ace64d385\\Python\\python.exe",
"fusion-360-helper.python.extraLibs": [
"C:\\Users\\gena0\\AppData\\Roaming\\Autodesk\\Autodesk Fusion 360\\API\\Python\\defs"
]
}
13 changes: 13 additions & 0 deletions f360-script/External controls/External controls.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"autodeskProduct": "Fusion360",
"type": "addin",
"id": "0afdf698-8eed-4eaa-ac5c-d6ae17db8147",
"author": "InTostor",
"description": {
"": ""
},
"version": "0.1",
"runOnStartup": true,
"supportedOS": "windows|mac",
"editEnabled": true
}
161 changes: 161 additions & 0 deletions f360-script/External controls/External controls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# started experiments with f360 driver-script


# There is a lot of code copied from stackoverflow, autodesk forums, etc.
# windows only yet

import adsk.fusion, adsk.core, traceback
import math

from .lib import joystickapi
from .lib.mathExt import *
from .lib.Joystick import *
from .lib.logger import *

from .lib import fusion360utils as futil
from .config import *
from . import commands


import msvcrt
import time
import inspect, os, sys

logger=Logger()


def greeting():
logger.print("------Starting------")
logger.print("f360 joystick driver")
logger.print(f"version, {VERSION}. By {AUTHOR}.")



def transformCameraByMatrix(camera: adsk.core.Camera, matrix: adsk.core.Matrix3D):
eye: adsk.core.Point3D = camera.eye
eye.transformBy(matrix)
camera.eye = eye

def transformCameraByVector(camera: adsk.core.Camera, vector: adsk.core.Vector3D):
eye: adsk.core.Point3D = camera.eye
eye.translateBy(vector)
camera.eye = eye



def changeCameraZoom(camera: adsk.core.Camera,zoom):
zoomOld = camera.viewExtents
if zoom<0:
zoom=0.001
camera.viewExtents = zoom

numOfJoysticks = joystickapi.joyGetNumDevs()


joy = None

def run(context):

try:
# This will run the start function in each of your commands as defined in commands/__init__.py
commands.start()

except:
futil.handle_error('run')

# This section executes once on script start
ui = None
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
greeting()

if numOfJoysticks==0:
raise Exception("No joystick")
else:
joy = Joystick()

# this found there https://github.com/Rabbid76/python_windows_joystickapi


ret, caps, startinfo = False, None, None
for id in range(numOfJoysticks):
ret, caps = joystickapi.joyGetDevCaps(id)
if ret:
ui.messageBox(str("Using gamepad: " + caps.szPname))
ret, startinfo = joystickapi.joyGetPosEx(id)
break
else:
ui.messageBox(str("no gamepad detected"))

first=True
# This section executes once on script start


# Loop starts

while True:
# viewport
vp: adsk.core.Viewport = app.activeViewport
cam: adsk.core.Camera = vp.camera
vecUp: adsk.core.Vector3D = cam.upVector
target: adsk.core.Point3D = cam.target
eye: adsk.core.Point3D = cam.eye



eTvector=eye.vectorTo(target)
angle1 = eTvector.angleTo(vecUp)
dx,dy,dz = getPerpendicularVector(vecUp.x, vecUp.y, vecUp.z)
perpendicular = adsk.core.Point3D.create(dx,dy,dz)
perpendicular=perpendicular.asVector()

angle2=vecUp.angleTo(perpendicular)


if numOfJoysticks==0:
raise Exception("No joystick")


deg = (joy.getAxes()[6]/262144)
deg=deg*deg*deg

zoom = cam.viewExtents
if cam.cameraType==0:
zoom = zoom-joy.getAxes()[1]/2621*zoom/5000
else:
zoom = zoom-joy.getAxes()[1]/26214400


changeCameraZoom(cam,zoom)

# futil.log( str(str(joy.getAxes()) +"|"+ str(cam.viewExtents))) # all axes output
logger.print(
"vecUp - target angle: "+str(math.degrees(angle1))+ "\n"+
"vecUp - calcul angle: "+str(math.degrees(angle2))+ "\n"+
str(perpendicular.x)+"|"+str(perpendicular.y)+"|"+str(perpendicular.z)
)


# matrix3d
mat: adsk.core.Matrix3D = adsk.core.Matrix3D.create()

mat.setToRotation(math.radians(deg), vecUp, target)
# update camera
cam.isSmoothTransition = False

transformCameraByMatrix(cam,mat)

transformCameraByVector(cam,perpendicular)







#futil.log(str(axisXYZRUV[0])+"|||||"+str(cam.viewExtents))
# cam.viewExtents = zoom
vp.camera = cam
vp.refresh()

adsk.doEvents()
Binary file not shown.
30 changes: 30 additions & 0 deletions f360-script/External controls/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Here you define the commands that will be added to your add-in.

# TODO Import the modules corresponding to the commands you created.
# If you want to add an additional command, duplicate one of the existing directories and import it here.
# You need to use aliases (import "entry" as "my_module") assuming you have the default module named "entry".
from .commandDialog import entry as commandDialog
from .paletteShow import entry as paletteShow
from .paletteSend import entry as paletteSend

# TODO add your imported modules to this list.
# Fusion will automatically call the start() and stop() functions.
commands = [
commandDialog,
paletteShow,
paletteSend
]


# Assumes you defined a "start" function in each of your modules.
# The start function will be run when the add-in is started.
def start():
for command in commands:
command.start()


# Assumes you defined a "stop" function in each of your modules.
# The stop function will be run when the add-in is stopped.
def stop():
for command in commands:
command.stop()
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Loading