Yes I think this is a bug, thank you @kandennti
I am trying to create a function to prompt the user to transform a component. They get instances like this where the rotation triad is not aligned well with the part. To rotate the cube around its flat faces instead of the corners it become difficult. I made a button so the user can adjust the triad and align it how they want without rotating the part, but I am having a hard time getting the movement to be correct.

When using the directional arrows the motion is correct, but when using the plane movement is unexpected.

import adsk.core, adsk.fusion, adsk.cam, traceback
app = adsk.core.Application.get()
ui = app.userInterface
handlers = []
cmdID = "testButton"
gOccurrence:adsk.fusion.Occurrence = None
allowRotate:bool = True
transformMatrix:adsk.core.Matrix3D = None
def run(context):
global cmdID
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Get the CommandDefinitions collection.
cmdDefs = ui.commandDefinitions
# Create a button command definition.
button = cmdDefs.addButtonDefinition(cmdID, 'Test', '')
# Connect to the command created event.
created = Create_Command()
button.commandCreated.add(created)
handlers.append(created)
# Execute the command.
button.execute()
# Keep the script running.
adsk.autoTerminate(False)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
global cmdID
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Delete the command definition.
cmdDef = ui.commandDefinitions.itemById(cmdID)
if cmdDef:
cmdDef.deleteMe()
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler for the commandCreated event.
class Create_Command(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args: adsk.core.CommandCreatedEventArgs):
global gOccurrence,transformMatrix
try:
cmd = args.command
inputs = cmd.commandInputs
design:adsk.fusion.Design = app.activeDocument.products.itemByProductType("DesignProductType")
root:adsk.fusion.Component = design.rootComponent
occurrence = root.occurrences.item(0)
#set global variables
gOccurrence = occurrence
transformMatrix = occurrence.transform2
#create triad input
transformInput = inputs.addTriadCommandInput("constructionTransform",transformMatrix)
transformInput.transform = transformMatrix
transformInput.isVisible = True
#create bool input
alignTriadButton = inputs.addBoolValueInput("alignTriad","Align Transformer",True)
execute = Command_Execute()
cmd.execute.add(execute)
handlers.append(execute)
inputChanged = Input_Changed()
cmd.inputChanged.add(inputChanged)
handlers.append(inputChanged)
preview = Preview()
cmd.executePreview.add(preview)
handlers.append(preview)
destroy = Destroy()
cmd.destroy.add(destroy)
handlers.append(destroy)
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
class Destroy(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args: adsk.core.CommandEventArgs):
global gOccurrence,transformMatrix,allowRotate,handlers,cmdID
handlers = []
gOccurrence = None
transformMatrix = None
allowRotate = True
app = adsk.core.Application.get()
ui = app.userInterface
# Delete the command definition.
cmdDef = ui.commandDefinitions.itemById(cmdID)
if cmdDef:
cmdDef.deleteMe()
class Command_Execute(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args: adsk.core.CommandEventArgs):
global gOccurrence
gOccurrence.transform2 = transformMatrix
class Input_Changed(adsk.core.InputChangedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args: adsk.core.InputChangedEventArgs):
global transformMatrix,gOccurrence,allowRotate
input = args.input
transformInput:adsk.core.TriadCommandInput = args.inputs.itemById("constructionTransform")
rotateTriad:adsk.core.BoolValueCommandInput = args.inputs.itemById("alignTriad")
if input == rotateTriad and rotateTriad.value == True:
allowRotate = False
if input == rotateTriad and rotateTriad.value == False:
allowRotate = True
if input == transformInput:
#get the matrix of change between last transform and this one
fromMat = transformInput.lastTransform.getAsCoordinateSystem()
toMat = transformInput.transform.getAsCoordinateSystem()
changeMat = adsk.core.Matrix3D.create()
changeMat.setToAlignCoordinateSystems(fromMat[0],fromMat[1],fromMat[2],fromMat[3],toMat[0],toMat[1],toMat[2],toMat[3])
transformMatrix = gOccurrence.transform2
transformMatrix.transformBy(changeMat)
class Preview(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args: adsk.core.CommandEventArgs):
global transformMatrix,gOccurrence,allowRotate
if allowRotate:
gOccurrence.transform2 = transformMatrix