-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDemo1Command.py
More file actions
91 lines (70 loc) · 4.45 KB
/
Copy pathDemo1Command.py
File metadata and controls
91 lines (70 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import adsk.core
import adsk.fusion
import traceback
from .Fusion360Utilities.Fusion360Utilities import AppObjects
from .Fusion360Utilities.Fusion360CommandBase import Fusion360CommandBase
# Class for a Fusion 360 Command
# Place your program logic here
# Delete the line that says "pass" for any method you want to use
class Demo1Command(Fusion360CommandBase):
# Run whenever a user makes any change to a value or selection in the addin UI
# Commands in here will be run through the Fusion processor and changes will be reflected in Fusion graphics area
def on_preview(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, args, input_values):
pass
# Run after the command is finished.
# Can be used to launch another command automatically or do other clean up.
def on_destroy(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, reason, input_values):
pass
# Run when any input is changed.
# Can be used to check a value and then update the add-in UI accordingly
def on_input_changed(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, changed_input, input_values):
# Selections are returned as a list so lets get the first one
all_selections = input_values.get('selection_input_id', None)
if all_selections is not None:
the_first_selection = all_selections[0]
# Update the text of the string value input to show the type of object selected
text_box_input = inputs.itemById('text_box_input_id')
text_box_input.text = the_first_selection.objectType
# Run when the user presses OK
# This is typically where your main program logic would go
def on_execute(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, args, input_values):
# Get the values from the user input
the_value = input_values['value_input_id']
the_boolean = input_values['bool_input_id']
the_string = input_values['string_input_id']
all_selections = input_values['selection_input_id']
the_drop_down = input_values['drop_down_input_id']
# Selections are returned as a list so lets get the first one and its name
the_first_selection = all_selections[0]
the_selection_type = the_first_selection.objectType
# Get a reference to all relevant application objects in a dictionary
ao = AppObjects()
converted_value = ao.units_manager.formatInternalValue(the_value, 'in', True)
ao.ui.messageBox('The value, in internal units, you entered was: {} \n'.format(the_value) +
'The value, in inches, you entered was: {} \n'.format(converted_value) +
'The boolean value checked was: {} \n'.format(the_boolean) +
'The string you typed was: {} \n'.format(the_string) +
'The type of the first object you selected is: {} \n'.format(the_selection_type) +
'The drop down item you selected is: {}'.format(the_drop_down)
)
# Run when the user selects your command icon from the Fusion 360 UI
# Typically used to create and display a command dialog box
# The following is a basic sample of a dialog UI
def on_create(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs):
# Create a default value using a string
ao = AppObjects()
default_value = adsk.core.ValueInput.createByString('1.0 in')
default_units = ao.units_manager.defaultLengthUnits
inputs.addValueInput('value_input_id', '*Sample* Value Input', default_units, default_value)
# Other Input types
inputs.addBoolValueInput('bool_input_id', '*Sample* Check Box', True)
inputs.addStringValueInput('string_input_id', '*Sample* String Value', 'Some Default Value')
inputs.addSelectionInput('selection_input_id', '*Sample* Selection', 'Select Something')
# Read Only Text Box
inputs.addTextBoxCommandInput('text_box_input_id', 'Selection Type: ', 'Nothing Selected', 1, True)
# Create a Drop Down
drop_down_input = inputs.addDropDownCommandInput('drop_down_input_id', '*Sample* Drop Down',
adsk.core.DropDownStyles.TextListDropDownStyle)
drop_down_items = drop_down_input.listItems
drop_down_items.add('List_Item_1', True, '')
drop_down_items.add('List_Item_2', False, '')