Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone, since I am not a programmer, I use ChatGPT to build a Python Script to rotate the view cube (camera) by 45 degrees.
It almost works perfectly but it also flips the view 180 degrees from left to right, I try changing all the values Z_axis, X and y_axis but it still do a flip.
I put on YouTube a video explaining my problem.
Thank you very much
import adsk.core, adsk.fusion, adsk.cam, traceback, math
def rotate_view_cube():
try:
# Get the Fusion 360 application and user interface
app = adsk.core.Application.get()
ui = app.userInterface
# Get the active viewport
viewport = app.activeViewport
# Get the current camera
camera = viewport.camera
# Set the rotation angle (in degrees) for the view cube
rotation_angle = 45
# Calculate the camera's Z-axis direction (view direction)
y_axis = camera.eye.vectorTo(camera.target)
y_axis.normalize() # Ensure it's a unit vector
# Create a rotation matrix for the eye position and up vector
rotation_matrix = adsk.core.Matrix3D.create()
rotation_matrix.setToRotation(math.radians(rotation_angle), y_axis, camera.target)
# Rotate the camera's eye position around the Z-axis
eye_vector = camera.eye.vectorTo(camera.target)
eye_vector.transformBy(rotation_matrix)
# Update the camera's eye position
new_eye = camera.target.copy()
new_eye.translateBy(eye_vector)
camera.eye = new_eye
# Update the up vector using the same rotation matrix
up_vector = camera.upVector
up_vector.transformBy(rotation_matrix)
camera.upVector = up_vector
# Apply the modified camera to update the viewport
viewport.camera = camera
ui.messageBox(f'View cube rotated by {rotation_angle} degrees around the x-axis.')
except Exception as e:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
rotate_view_cube()
Solved! Go to Solution.