Developer Interface¶
This part of the documentation covers all the interfaces of Apper.
Core Apper Modules¶
The core Apper functionality can be accessed by sub-classing these 3 classes.
Step one is to create an instance of the FusionApp
object.
Step two is to add instances of
apper.Fusion360CommandBase
and
apper.PaletteCommandBase
classes.
Each instance of these classes will be a new command in your add-in.
-
class
apper.
FusionApp
(name, company, debug)¶ Base class for creating a Fusion 360 Add-in
- Parameters
name (
str
) – The name of the addincompany (
str
) – the name of your company or organizationdebug (
bool
) – set this flag as True to enable more interactive feedback when developing.
-
add_command
(name, command_class, options)¶ Adds a command to the application
- Parameters
name (
str
) – The name of the commandcommand_class (
Any
) – This should be your subclass of apper.Fusion360CommandBase or apper.PaletteCommandBaseoptions (
dict
) – Set of options for the command see the full set of options
-
add_command_event
(event_id, event_type, event_class)¶ Register a workspace event that can respond to various workspace actions
- Parameters
event_id (
str
) – A unique identifier for the eventevent_type (
Any
) – One of [UserInterface.commandCreated, UserInterface.commandStarting, UserInterface.commandTerminated]event_class (
Any
) – Your subclass of apper.Fusion360CommandEvent class
-
add_custom_event
(event_id, event_class, auto_start=True)¶ Register a custom event to respond to a function running in a new thread
- Parameters
event_id (
str
) – A unique identifier for the eventevent_class (
Any
) – Your subclass of apper.Fusion360CustomThreadauto_start (
bool
) – Whether the thread should start when the addin starts
-
add_custom_event_no_thread
(event_id, event_class)¶ Register a custom event
- Parameters
event_id (
str
) – A unique identifier for the eventevent_class (
Any
) – Your subclass of apper.Fusion360CustomThread
-
add_custom_feature
(name, feature_class, options)¶ Register a workspace event that can respond to various workspace actions
- Parameters
name (
str
) – The name of the commandfeature_class (
Any
) – This should be your subclass of apper.Fusion360CustomFeatureBaseoptions (
dict
) –Set of options for the command see the full set of options
- Return type
Any
-
add_document_event
(event_id, event_type, event_class)¶ Register a document event that can respond to various document actions
- Parameters
event_id (
str
) – A unique identifier for the eventevent_type (
DocumentEvent
) – Any document event in the current applicationevent_class (
Any
) – Your subclass of apper.Fusion360DocumentEvent
-
add_web_request_event
(event_id, event_type, event_class)¶ Register a workspace event that can respond to various workspace actions
- Parameters
event_id (
str
) – A unique identifier for the eventevent_class (
Any
) – Your subclass of apper.Fusion360WebRequestEventevent_type (
WebRequestEvent
) – Opened or Inserting from URL event type such as (app.openedFromURL)
-
add_workspace_event
(event_id, workspace_name, event_class)¶ Register a workspace event that can respond to various workspace actions
- Parameters
event_id (
str
) – A unique identifier for the eventworkspace_name (
str
) – name of the workspace (i.e.event_class (
Any
) – Your subclass of apper.Fusion360WorkspaceEvent
-
check_for_updates
()¶ Not Implemented
-
command_id_from_name
(name)¶ Returns the full cmd_id defined by apper
- Parameters
name (
str
) – this is the value set in options for cmd_id- Return type
Optional
[str
]- Returns
The full cmd_id (i.e. CompanyName_AppName_cmd_id)
-
get_all_preferences
()¶ Gets all preferences stored for this application
- Return type
dict
- Returns
All preferences as a dictionary
-
get_group_preferences
(group_name)¶ Gets preferences for a particular group (typically a given command)
- Parameters
group_name (
str
) – name of parent group in which to store preferences- Return type
dict
- Returns
A dictionary of just the options associated to this particular group
-
initialize_preferences
(defaults, force=False)¶ Initializes preferences for the application
- Parameters
defaults (
dict
) – a default set of preferencesforce – If True, any existing user preferences will be over-written
- Returns
“Created”, “Exists”, or “Failed”
- Return type
A string with possible values
-
static
read_json_file
(file_name)¶ Static method to read a json file and return a dictionary object
Will fail if the input file cannot be interpreted as a JSON object
- Returns
Input file as a dictionary
-
run_app
()¶ Runs the Addin
-
save_preferences
(group_name, new_group_preferences, merge)¶ Saves preferences for the application
- Parameters
group_name (
str
) – name of parent group in which to store preferencesnew_group_preferences (
dict
) – Dictionary of preferences to savemerge (
bool
) – If True then the new preferences in the group will be merged, if False all old values are deleted
- Returns
“Updated”, “Created”, or “Failed”
- Return type
A string with possible values
-
stop_app
()¶ Stops the Addin and cleans up all of the created UI elements
Other Modules¶
Fusion360Utilities.py¶
Tools to leverage when creating a Fusion 360 Add-in¶
- copyright
2019 by Patrick Rainsberry.
- license
Apache 2.0, see LICENSE for more details.
-
class
apper.Fusion360Utilities.
AppObjects
¶ The AppObjects class wraps many common application objects required when writing a Fusion 360 Addin.
-
property
cam
¶ adsk.cam.CAM from the active document
Note if the document has never been activated in the CAM environment this will return None
Returns: adsk.cam.CAM from the active document
- Return type
Optional
[CAM
]
-
property
design
¶ adsk.fusion.Design from the active document
Returns: adsk.fusion.Design from the active document
- Return type
Optional
[Design
]
-
property
document
¶ adsk.fusion.Design from the active document
Returns: adsk.fusion.Design from the active document
- Return type
Optional
[Document
]
-
property
export_manager
¶ adsk.fusion.ExportManager from the active document
Returns: adsk.fusion.ExportManager from the active document
- Return type
Optional
[ExportManager
]
-
property
f_units_manager
¶ adsk.fusion.FusionUnitsManager from the active document.
Only work in design environment.
Returns: adsk.fusion.FusionUnitsManager or None if in a different workspace than design.
- Return type
Optional
[FusionUnitsManager
]
-
property
product
¶ adsk.fusion.Design from the active document
Returns: adsk.fusion.Design from the active document
- Return type
Optional
[Product
]
-
property
root_comp
¶ Every adsk.fusion.Design has exactly one Root Component
It should also be noted that the Root Component in the Design does not have an associated Occurrence
Returns: The Root Component of the adsk.fusion.Design
- Return type
Optional
[Component
]
-
property
time_line
¶ adsk.fusion.Timeline from the active adsk.fusion.Design
Returns: adsk.fusion.Timeline from the active adsk.fusion.Design
- Return type
Optional
[Timeline
]
-
property
units_manager
¶ adsk.core.UnitsManager from the active document
If not in an active document with design workspace active, will return adsk.core.UnitsManager if possible
Returns: adsk.fusion.FusionUnitsManager or adsk.core.UnitsManager if in a different workspace than design.
- Return type
Optional
[UnitsManager
]
-
property
-
apper.Fusion360Utilities.
combine_feature
(target_body, tool_bodies, operation)¶ Creates Combine Feature in target with all tool bodies as source
- Parameters
target_body (
BRepBody
) – Target body for the combine featuretool_bodies (
List
[BRepBody
]) – A list of tool bodies for the combineoperation (
FeatureOperations
) – An Enumerator defining the feature operation type
-
apper.Fusion360Utilities.
create_component
(target_component, name)¶ Creates a new empty component in the target component
- Parameters
target_component (
Component
) – The target component for the new componentname (
str
) – The name of the new component
- Return type
Occurrence
- Returns
The reference to the occurrence of the newly created component.
-
apper.Fusion360Utilities.
end_group
(start_index)¶ Ends a adsk.fusion.TimelineGroup
start_index: adsk.fusion.TimelineGroup index that is returned from start_group
-
apper.Fusion360Utilities.
extrude_all_profiles
(sketch, distance, component, operation)¶ Create extrude features of all profiles in a sketch
The new feature will be created in the given target component and extruded by a distance
- Parameters
sketch (
Sketch
) – The sketch from which to get profilesdistance (
float
) – The distance to extrude the profiles.component (
Component
) – The target component for the extrude featureoperation (
FeatureOperations
) – The feature operation type from enumerator.
- Return type
ExtrudeFeature
- Returns
The new extrude feature.
-
apper.Fusion360Utilities.
get_a_uuid
()¶ Gets a base 64 uuid
- Return type
str
- Returns
The id that was generated
-
apper.Fusion360Utilities.
get_default_dir
(app_name)¶ Creates a directory in the user’s home folder to store data related to this app
- Parameters
app_name (str) – Name of the Application
-
apper.Fusion360Utilities.
get_item_by_id
(this_item_id, app_name)¶ Returns an item based on the assigned ID set with
item_id
- Parameters
this_item_id (
str
) – The unique id generated originally by callingitem_id
app_name (
str
) – Name of the Application
- Return type
Base
- Returns
The Fusion 360 object that the id attribute was attached to.
-
apper.Fusion360Utilities.
get_log_file
(app_name)¶ Gets the filename for a default log file
- Parameters
app_name (
str
) – Name of the Application
-
apper.Fusion360Utilities.
get_log_file_name
(app_name)¶ Gets the filename for a default log file
- Parameters
app_name (
str
) – Name of the Application
-
apper.Fusion360Utilities.
get_settings_file
(app_name)¶ Create (or get) a settings file name in the default app directory
- Parameters
app_name (
str
) – Name of the Application
-
apper.Fusion360Utilities.
get_std_err_file
(app_name)¶ Get temporary stderr file for the app
- Parameters
app_name (
str
) – Name of the Application
-
apper.Fusion360Utilities.
get_std_out_file
(app_name)¶ Get temporary stdout file for the app
- Parameters
app_name (
str
) – Name of the Application
-
apper.Fusion360Utilities.
import_dxf
(dxf_file, component, plane, is_single_sketch_result=False)¶ Import dxf file with one sketch per layer.
- Parameters
dxf_file (
str
) – The full path to the dxf filecomponent (
Component
) – The target component for the new sketch(es)plane (
Union
[ConstructionPlane
,BRepFace
]) – The plane on which to import the DXF file.plane – The plane on which to import the DXF file.
is_single_sketch_result (
bool
) – If true will collapse all dxf layers to a single sketch.
- Return type
ObjectCollection
- Returns
An ObjectCollection of the created sketches
-
apper.Fusion360Utilities.
item_id
(item, group_name)¶ Gets (and possibly assigns) a unique identifier (UUID) to any item in Fusion 360
- Parameters
item (
Base
) – Any Fusion Object that supports attributesgroup_name (
str
) – Name of the Attribute Group (typically use app_name)
- Return type
str
- Returns
The id that was generated or was previously existing
-
class
apper.Fusion360Utilities.
lib_import
(library_folder)¶ The lib_import class is a wrapper class to allow temporary import of a local library directory
By default it assumes there is a folder named ‘lib’ in the add-in root directory.
First install a 3rd party library (such as requests) to this directory.
# Assuming you are in the add-in root directory (sudo may not be required...) sudo python3 -m pip install -t ./lib requests
Then you can temporarily import the library before making a call to the requests function. To do this use the @apper.lib_import(…) decorator on a function that uses the library.
Here is an example function for using Requests:
@apper.lib_import(config.app_path) def make_request(url, headers): import requests r = requests.get(url, headers=headers) return r
- Parameters
app_path (str) – The root path of the addin. Should be dynamically calculated.
library_folder (
str
, optional) – Library folder name (relative to app root). Defaults to ‘lib’
-
apper.Fusion360Utilities.
open_doc
(data_file)¶ Simple wrapper to open a dataFile in the application window
- Parameters
data_file (
DataFile
) – The data file to open
-
apper.Fusion360Utilities.
read_settings
(app_name)¶ Read a settings file into the default directory for the app
- Parameters
app_name (
str
) – Name of the Application
-
apper.Fusion360Utilities.
rect_body_pattern
(target_component, bodies, x_axis, y_axis, x_qty, x_distance, y_qty, y_distance)¶ Creates rectangle pattern of bodies based on vectors
- Parameters
target_component (
Component
) – Component in which to create the paternbodies (
List
[BRepBody
]) – bodies to patternx_axis (
Vector3D
) – vector defining direction 1y_axis (
Vector3D
) – vector defining direction 2x_qty (
int
) – Number of instances in direction 1x_distance (
float
) – Distance between instances in direction 1y_qty (
int
) – Number of instances in direction 2y_distance (
float
) – Distance between instances in direction 2
- Return type
ObjectCollection
-
apper.Fusion360Utilities.
remove_item_id
(item, group_name)¶ Gets (and possibly assigns) a unique identifier (UUID) to any item in Fusion 360
- Parameters
item (
Base
) – Any Fusion Object that supports attributesgroup_name (
str
) – Name of the Attribute Group (typically use app_name)
- Return type
bool
- Returns
True if successful and False if it failed
-
apper.Fusion360Utilities.
sketch_by_name
(sketches, name)¶ Finds a sketch by name in a list of sketches
Useful for parsing a collection of sketches such as DXF import results.
- Parameters
sketches (
Sketches
) – A list of sketches. (Likely would be all sketches in active document).name (
str
) – The name of the sketch to find.
- Return type
Sketch
- Returns
The sketch matching the name if it is found.
-
apper.Fusion360Utilities.
start_group
()¶ Starts a time line group
- Return type
int
- Returns
The index of the adsk.fusion.Timeline where the adsk.fusion.TimelineGroup will begin
-
apper.Fusion360Utilities.
write_settings
(app_name, settings)¶ Write a settings file into the default directory for the app
- Parameters
app_name (
str
) – Name of the Applicationsettings (
dict
) – Stores a dictionary as a json string
Fusion360DebugUtilities.py¶
Utilities to aid in debugging a Fusion 360 Addin¶
- copyright
2019 by Patrick Rainsberry.
- license
Apache 2.0, see LICENSE for more details.
-
apper.Fusion360DebugUtilities.
get_log_file_name
()¶ Creates directory and returns file name for log file :param log: tbd
-
apper.Fusion360DebugUtilities.
perf_log
(log, function_reference, command, identifier='')¶ Performance time logging function :param log: :param function_reference: :param command: :param identifier:
-
apper.Fusion360DebugUtilities.
perf_message
(log)¶ Performance time logging function :param log: tbd
-
apper.Fusion360DebugUtilities.
variable_message
(variable, extra_info='')¶ Displays the value of any single variable as long as the value can be converted to text
- Parameters
variable – variable to print
extra_info – Any other info to display in the message box
-
apper.Fusion360DebugUtilities.
variables_message
(variables)¶ Print a list of list of variables
Format of variables should be [[Variable name 1, variable value 1], [Variable name 2, variable value 2], …]
- Parameters
variables (
list
) – A list of lists of any string based variables from your add-in.