Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I cannot find the way to change angle manipulator's origin in preview. I can set the origin in CreatedEventHandler.notify(), but not in PreviewHandler.notify(). Is it impossible?
The code below should move the origin when SelectionCommandInput worked first time, but it doesn't happen.
Thanks,
import sys
import traceback
import adsk.core as ac
import adsk.fusion as af
import adsk
HANDLERS = []
BUTTON_ID = "test_angle_manipulator_button"
SELECT_OCC_ID = 'select_occ'
INP_ANGLE_ID = 'input_angle'
def notify_catcher(func):
def f(*args, **kwargs):
try:
func(*args, **kwargs)
except Exception:
print(traceback.format_exc(), file=sys.stderr)
return f
class MyExecutePreviewHandler(ac.CommandEventHandler):
def __init__(self):
super().__init__()
@Anonymous_catcher
def notify(self, args):
cmd_args = ac.CommandEventArgs.cast(args)
cmd_inputs = cmd_args.command.commandInputs
angle_input = ac.AngleValueCommandInput.cast(cmd_inputs.itemById(INP_ANGLE_ID))
angle_input.manipulatorOrigin.set(-1, 2, 0)
class MyExecuteHandler(ac.CommandEventHandler):
def __init__(self):
super().__init__()
@Anonymous_catcher
def notify(self, args):
pass
class MyCommandCreatedHandler(ac.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
@Anonymous_catcher
def notify(self, args):
# Code to react to the event.
command = ac.Command.cast(args.command)
cmd_inputs = command.commandInputs
sel_input = cmd_inputs.addSelectionInput(SELECT_OCC_ID, 'Selection', 'Select an occurrence')
sel_input.addSelectionFilter('Occurrences')
sel_input.setSelectionLimits(1, 1)
angle_input = cmd_inputs.addAngleValueCommandInput(INP_ANGLE_ID, 'Angle', ac.ValueInput.createByString('0 degree'))
origin = ac.Point3D.create(1, 2, 0)
vx = ac.Vector3D.create(1, 0, 0)
vy = ac.Vector3D.create(0, 1, 0)
angle_input.setManipulator(origin, vx, vy)
angle_input.isEnabled = True
angle_input.hasMinimumValue = False
angle_input.hasMaximumValue = False
# Connect to the execute preview and execute events.
on_exec_preview = MyExecutePreviewHandler()
command.executePreview.add(on_exec_preview)
HANDLERS.append(on_exec_preview)
on_exec = MyExecuteHandler()
command.execute.add(on_exec)
HANDLERS.append(on_exec)
@notify_catcher
def run(context):
app = ac.Application.get()
ui = app.userInterface
# create the button definition and add a control to the INSPECT panel.
button_def = ui.commandDefinitions.itemById(BUTTON_ID)
if button_def:
button_def.deleteMe()
button_def = ui.commandDefinitions.addButtonDefinition(BUTTON_ID, 'Angle Manipulator Test', 'Angle Manipulator Test.', 'Resources/Geometry')
on_cmd_created = MyCommandCreatedHandler()
button_def.commandCreated.add(on_cmd_created)
HANDLERS.append(on_cmd_created)
inspect_panel = ui.allToolbarPanels.itemById('InspectPanel')
ctrl = inspect_panel.controls.itemById(BUTTON_ID)
if ctrl:
ctrl.deleteMe()
inspect_panel.controls.addCommand(button_def)
@notify_catcher
def stop(context):
app = ac.Application.get()
ui = app.userInterface
button_def = ui.commandDefinitions.itemById(BUTTON_ID)
if button_def:
button_def.deleteMe()
inspect_panel = ui.allToolbarPanels.itemById('InspectPanel')
ctrl = inspect_panel.controls.itemById(BUTTON_ID)
if ctrl:
ctrl.deleteMe()
Solved! Go to Solution.