### Handle Command Created Event (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This event is triggered immediately after a command is created within Fusion. It allows for pre-command setup or inspection of the command object right after its instantiation.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var eventHandlers = ui.commandCreated;
// Add an event handler
// var handler = {}
// handler.notify = function(args) {
// adsk.debug.log("Command created: " + args.command.name);
// }
// eventHandlers.add(handler);
// Remove the event handler when done
// eventHandlers.remove(handler);
```
--------------------------------
### Handle Command Starting Event (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This event fires just before a command is executed. It provides an opportunity to inspect the command request and potentially cancel its execution by modifying the event arguments. This is useful for command validation or custom pre-execution logic.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var eventHandlers = ui.commandStarting;
// Add an event handler
// var handler = {}
// handler.notify = function(args) {
// adsk.debug.log("Command starting: " + args.commandName);
// // To cancel the command:
// // args.cancel = true;
// }
// eventHandlers.add(handler);
// Remove the event handler when done
// eventHandlers.remove(handler);
```
--------------------------------
### Get Workspaces by Product Type in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Demonstrates how to obtain all workspaces associated with a specific product type using the 'workspacesByProductType' method of the UserInterface object in the Autodesk Fusion API. This allows scripts to identify and interact with workspaces relevant to a particular Fusion product.
```javascript
var productType = "Sculpt"; // Example product type
var workspaces = fusion.userInterface.workspacesByProductType(productType);
// 'workspaces' is a collection of Workspace objects for the given product type.
```
--------------------------------
### UserInterface Properties API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This section details the properties of the UserInterface object, which allow you to get and set various aspects of the Fusion user interface.
```APIDOC
## UserInterface Properties
### Description
Provides access to various properties of the Fusion user interface, including its enabled state, validity, object type, palettes, progress bar, status messages, toolbars, and workspaces.
### Methods/Properties
- **isUIEnabled**
- **Description**: Returns true if Tabbed Toolbars are being used.
- **Type**: Boolean
- **Access**: Read-only
- **getIsEnabled**
- **Description**: Gets if the Fusion user interface is enabled or not. By default it is enabled allowing the user to interact with Fusion. When set to false, the UI is disabled which blocks all interaction, including running commands, manipulating the view and interacting with the browser.
- **Type**: Boolean
- **Access**: Read/Write
- **isValid**
- **Description**: Indicates if this object is still valid, i.e. hasn't been deleted or some other action done to invalidate the reference.
- **Type**: Boolean
- **Access**: Read-only
- **objectType**
- **Description**: This property is supported by all objects in the API and returns a string that contains the full name (namespace::objecttype) describing the type of the object.
- **Type**: String
- **Access**: Read-only
- **palettes**
- **Description**: Returns the collection object that provides access to all of the existing palettes and provides the functionality to create new custom palettes.
- **Type**: adsk.core.Palettes
- **Access**: Read-only
- **progressBar**
- **Description**: Gets the ProgressBar object that can be used to display a progress bar in the lower-right corner of the Fusion window.
- **Type**: adsk.core.ProgressBar
- **Access**: Read-only
- **statusMessage**
- **Description**: Gets and sets the current message displayed in the lower-right corner of the Fusion window. This is useful when displaying progress information to the user for the current process. Set the value to an empty string to remove the message. The lifetime of your message is indeterminant because Fusion uses the same field to display messages.
- **Type**: String
- **Access**: Read/Write
- **toolbars**
- **Description**: Gets a collection that provides access to the toolbars. This includes the left and right QAT, and the Navbar.
- **Type**: adsk.core.Toolbars
- **Access**: Read-only
- **workspaces**
- **Description**: Gets all of the workspaces currently available.
- **Type**: adsk.core.Workspaces
- **Access**: Read-only
```
--------------------------------
### Get Localized Text String in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This JavaScript example shows how to retrieve localized text strings used within the Fusion application. The 'getText' method of the UserInterface object accesses strings from XML files installed with Fusion, ensuring the UI displays correctly based on user preferences.
```javascript
var localizedString = fusion.userInterface.getText("SomeTextKey");
// localizedString will contain the text for 'SomeTextKey' in the user's preferred language.
```
--------------------------------
### Get All Workspaces (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This property retrieves a collection of all available workspaces within Fusion. Workspaces represent different environments tailored for specific design tasks. The returned collection allows iteration and access to individual workspace objects.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var workspaces = ui.workspaces;
// Example: Iterate through workspaces
// for (var i = 0; i < workspaces.count; i++) {
// var workspace = workspaces.item(i);
// adsk.debug.log("Workspace Name: " + workspace.name);
// }
```
--------------------------------
### Get Toolbar Panels by Product Type in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Shows how to retrieve all toolbar panels associated with a specific product type using the 'toolbarPanelsByProductType' method of the UserInterface object in the Autodesk Fusion API. This allows for dynamic access to UI elements based on the active product.
```javascript
var productType = "Design"; // Example product type
var panels = fusion.userInterface.toolbarPanelsByProductType(productType);
// Iterate through 'panels' to access individual toolbar panels.
```
--------------------------------
### Get ProgressBar Object (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This property returns the ProgressBar object, which allows displaying a progress bar in the lower-right corner of the Fusion window. This is useful for providing visual feedback on the progress of long-running operations.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var progressBar = ui.progressBar;
// To use the progress bar:
// progressBar.text = "Processing...";
// progressBar.show(0, 100, 0); // Show with range 0-100, current value 0
// // ... perform operations ...
// progressBar.progressValue = 50;
// // ... complete operations ...
// progressBar.hide();
```
--------------------------------
### Get Toolbar Tabs by Product Type in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Illustrates retrieving all toolbar tabs associated with a given product type using the 'toolbarTabsByProductType' method of the UserInterface object in the Autodesk Fusion API. This enables programmatic access and management of UI tabs for different Fusion products.
```javascript
var productType = "Manufacture"; // Example product type
var tabs = fusion.userInterface.toolbarTabsByProductType(productType);
// 'tabs' will contain a collection of toolbar tabs for the specified product.
```
--------------------------------
### Enable/Disable Fusion User Interface (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This property allows getting and setting the enabled state of the Fusion user interface. When disabled, user interaction with Fusion is blocked. Setting it requires careful consideration as it can halt all user operations.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
// Check if UI is enabled
var isEnabled = ui.isUIEnabled;
// Disable UI
// ui.isUIEnabled = false;
// Enable UI
// ui.isUIEnabled = true;
```
--------------------------------
### Select Single Entity in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Illustrates using the 'selectEntity' method of the UserInterface object in the Autodesk Fusion API to prompt the user for a single entity selection. This method provides a basic way to get user input for entity selection within a script.
```javascript
var selectedEntity = fusion.userInterface.selectEntity("Please select a face:");
// selectedEntity will contain the chosen entity if the user makes a selection.
```
--------------------------------
### Get Object Type Name (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This property returns a string representing the full namespace and type of an object. It's useful for type checking, especially when combined with the classType method, to determine if an object is of a specific type.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
// Assuming 'obj' is a Fusion API object
// var obj = ...;
// var objectTypeName = obj.objectType;
// adsk.debug.log(objectTypeName);
// Example usage with classType:
// if (obj.objectType == adsk.core.Point3D.classType()) {
// adsk.debug.log("Object is a Point3D");
// }
```
--------------------------------
### Get and Set Status Message (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This property allows retrieving and setting the status message displayed in the lower-right corner of the Fusion window. It's useful for informing the user about the current process. Setting it to an empty string clears the message. Note that Fusion may overwrite the message, and `adsk.doEvents()` might be needed for UI updates in the main thread.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
// Set a status message
// ui.statusMessage = "Loading data...";
// Get the current status message
// var currentMessage = ui.statusMessage;
// Clear the status message
// ui.statusMessage = "";
// If running in main thread, might need to yield:
// adsk.doEvents();
```
--------------------------------
### Create Standard File Dialog in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Illustrates how to create a standard file dialog using the UserInterface object in the Autodesk Fusion API. This dialog allows users to select files from their local system. The 'createFileDialog' method returns a FileDialog object for further interaction.
```javascript
var fileDialog = fusion.userInterface.createFileDialog();
// Use fileDialog to open the dialog and process the selected file.
```
--------------------------------
### Create Folder Dialog in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Shows the process of creating a standard folder selection dialog using the UserInterface object in the Autodesk Fusion API. The 'createFolderDialog' method returns a FolderDialog object, enabling users to choose a folder. This is useful for operations requiring directory selection.
```javascript
var folderDialog = fusion.userInterface.createFolderDialog();
// Use folderDialog to allow the user to select a folder.
```
--------------------------------
### Create Cloud File Dialog in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Demonstrates the creation of a CloudFileDialog object using the UserInterface object in the Autodesk Fusion API. This dialog allows users to select files from the Fusion web client. The created object provides methods for managing the file selection process.
```javascript
var cloudFileDialog = fusion.userInterface.createCloudFileDialog();
// Use cloudFileDialog to show the dialog and handle user selection.
```
--------------------------------
### Fusion Palette Communication (HTML/JavaScript)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Demonstrates how to create an HTML-based palette for Fusion. It includes functions to send data to Fusion (`sendInfoToFusion`) and a handler (`fusionJavaScriptHandler`) to receive data from Fusion. This allows for two-way communication between the palette's JavaScript and the Fusion add-in.
```html
Click the button below to send data to Fusion.
Run the "Send Info to HTML" command in the ADD-INS panel to update this text.
```
--------------------------------
### UserInterface Object Methods
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This section details the methods available within the UserInterface object for interacting with the Fusion user interface.
```APIDOC
## UserInterface Object Methods
### Description
Provides access to user-interface related objects and functionality.
### Methods
#### `classType()`
* **Description**: Static function that returns the type of the class as a string. Matches the `objectType` property.
* **Returns**: `string` - The class type.
#### `createCloudFileDialog()`
* **Description**: Creates a new CloudFileDialog object for selecting files from the Fusion web client.
* **Returns**: `CloudFileDialog` - A new CloudFileDialog object.
#### `createFileDialog()`
* **Description**: Creates a new FileDialog object for showing a standard file selection dialog.
* **Returns**: `FileDialog` - A new FileDialog object.
#### `createFolderDialog()`
* **Description**: Creates a new FolderDialog object for showing a standard folder selection dialog.
* **Returns**: `FolderDialog` - A new FolderDialog object.
#### `createProgressDialog()`
* **Description**: Creates a new ProgressDialog object for displaying and controlling a progress dialog.
* **Returns**: `ProgressDialog` - A new ProgressDialog object.
#### `getText(textId)`
* **Description**: Gets the localized text for a specific application text string.
* **Parameters**:
* `textId` (string) - Required - The ID of the text string to retrieve.
* **Returns**: `string` - The localized text.
#### `inputBox(prompt, initialValue)`
* **Description**: Displays a modal dialog to get string input from the user.
* **Parameters**:
* `prompt` (string) - Required - The message to display to the user.
* `initialValue` (string) - Optional - The initial value for the input field.
* **Returns**: `string` - The user's input string, or null if cancelled.
#### `messageBox(text)`
* **Description**: Displays a modal message box with the provided text.
* **Parameters**:
* `text` (string) - Required - The text to display in the message box.
#### `selectEntity(prompt)`
* **Description**: Supports the selection of a single entity, prompting the user for a selection.
* **Parameters**:
* `prompt` (string) - Optional - The message to display to the user during selection.
* **Returns**: `Object` - The selected entity, or null if no entity is selected or cancelled.
#### `terminateActiveCommand()`
* **Description**: Causes the currently active (running) command to be terminated.
#### `toolbarPanelsByProductType(productType)`
* **Description**: Gets all of the toolbar panels associated with the specified product.
* **Parameters**:
* `productType` (string) - Required - The type of the product (e.g., 'Design').
* **Returns**: `Array` - An array of toolbar panels.
#### `toolbarTabsByProductType(productType)`
* **Description**: Gets all of the toolbar tabs associated with the specified product.
* **Parameters**:
* `productType` (string) - Required - The type of the product (e.g., 'Design').
* **Returns**: `Array` - An array of toolbar tabs.
#### `workspacesByProductType(productType)`
* **Description**: Returns all of the workspaces associated with the specified product.
* **Parameters**:
* `productType` (string) - Required - The type of the product (e.g., 'Design').
* **Returns**: `Array` - An array of workspaces.
```
--------------------------------
### Handle Marking Menu Displaying Event (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This event fires just before the marking menu (right-click context menu) and standard context menus are displayed. It allows modification of these menus by examining and editing their contents before they appear to the user.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var eventHandlers = ui.markingMenuDisplaying;
// Add an event handler
// var handler = {}
// handler.notify = function(args) {
// adsk.debug.log("Marking menu is displaying.");
// // args.markingMenu and args.contextMenu allow inspection and modification
// // Example: Remove an item from the context menu
// // var itemToRemove = args.contextMenu.controls.itemByName('someMenuItemName');
// // if (itemToRemove) {
// // itemToRemove.deleteMe();
// // }
// }
// eventHandlers.add(handler);
// Remove the event handler when done
// eventHandlers.remove(handler);
```
--------------------------------
### Handle Workspace Pre-Activate Event (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This event fires at the very beginning of a workspace activation process, before any significant changes occur. It allows for preliminary actions or checks before the workspace fully becomes active.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var eventHandlers = ui.workspacePreActivate;
// Add an event handler
// var handler = {}
// handler.notify = function(args) {
// adsk.debug.log("Workspace about to activate: " + args.workspace.name);
// // Perform checks or pre-activation tasks here
// }
// eventHandlers.add(handler);
// Remove the event handler when done
// eventHandlers.remove(handler);
```
--------------------------------
### Access Toolbars Collection (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This property returns a collection that provides access to the various toolbars in Fusion, including the Quick Access Toolbar (QAT) and the Navbar. It allows programmatic interaction with these UI elements.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var toolbars = ui.toolbars;
// Example: Iterate through toolbars (specific types might need checking)
// for (var i = 0; i < toolbars.count; i++) {
// var toolbar = toolbars.item(i);
// adsk.debug.log("Toolbar Name: " + toolbar.name);
// }
```
--------------------------------
### Display Input Dialog in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Demonstrates how to display a modal dialog for string input from the user using the 'inputBox' method of the UserInterface object in the Autodesk Fusion API. This function is suitable for simple text-based user input requirements within scripts.
```javascript
var userInput = fusion.userInterface.inputBox("Enter your name:", "Input Required");
// userInput will hold the string entered by the user.
```
--------------------------------
### Display Message Box in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Shows how to display a modal message box to the user with provided text using the 'messageBox' method of the UserInterface object in the Autodesk Fusion API. This is a straightforward way to present information or alerts to the user.
```javascript
fusion.userInterface.messageBox("Operation completed successfully.", "Information");
```
--------------------------------
### UserInterface Object Properties
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This section details the properties available within the UserInterface object for accessing current UI states.
```APIDOC
## UserInterface Object Properties
### Description
Provides access to user-interface related objects and functionality.
### Properties
#### `activeCommand`
* **Description**: Gets the id of the command definition from the active command.
* **Type**: `string`
#### `activeSelections`
* **Description**: Gets the current set of selected objects.
* **Type**: `Array`
#### `activeToolbar`
* **Description**: Retrieve the active Toolbar being displayed in the user interface.
* **Type**: `Toolbar`
#### `activeToolbarTab`
* **Description**: Retrieve the active ToolbarTab being displayed in the user interface.
* **Type**: `ToolbarTab` | `null`
#### `activeWorkspace`
* **Description**: Gets the active workspace. This can be null if there is no active product.
* **Type**: `Workspace` | `null`
#### `allToolbarPanels`
* **Description**: Gets all of the toolbar panels available, regardless of workspace or product association.
* **Type**: `Array`
#### `allToolbarTabs`
* **Description**: Gets all of the toolbar tabs available, regardless of workspace or product association.
* **Type**: `Array`
#### `commandDefinitions`
* **Description**: Gets all of the command definitions currently defined, both internal and API-defined.
* **Type**: `Array`
#### `isTabbedToolbarUI`
* **Description**: Indicates whether the user interface is using a tabbed toolbar.
* **Type**: `boolean`
```
--------------------------------
### Create Progress Dialog in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This snippet demonstrates how to create and utilize a ProgressDialog object via the UserInterface object in the Autodesk Fusion API. The ProgressDialog allows for displaying and controlling a progress bar, providing visual feedback to the user during lengthy operations.
```javascript
var progressDialog = fusion.userInterface.createProgressDialog();
// Update progressDialog with values and control its visibility.
```
--------------------------------
### UserInterface Events API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This section details the events associated with the UserInterface object, which are fired in response to various user actions and system changes.
```APIDOC
## UserInterface Events
### Description
Events related to user interface interactions and changes within Fusion.
### Events
- **activeSelectionChanged**
- **Description**: This event fires whenever the contents of the active selection changes. This occurs as the user selects or unselects entities while using the Fusion Select command. The Select command is the default command that is always running if no other command is active. Pressing Escape terminates the currently active command and starts the Select command. If the Select command is running and you press Escape, it terminates the current Select command and starts a new one. This event is only associated with the selection associated with the Select command and does not fire when any other command is running. The event fires when there is any change to the active selection, including when the selection is cleared when the Select command is terminated. It is also fired when the user clicks in an open area of the canvas to clear the current selection.
- **commandCreated**
- **Description**: The commandCreated event fires immediately after the command is created.
- **commandStarting**
- **Description**: The commandStarting event fires when a request for a command to be executed has been received but before the command is executed. Through this event, it's possible to cancel the command from being executed.
- **commandTerminated**
- **Description**: Gets an event that is fired when a command is terminated.
- **markingMenuDisplaying**
- **Description**: The markingMenuDisplaying event fires just before the marking menu and context menus are displayed. The marking menu is the round menu displayed when the user right-clicks the mouse within Fusion. The context menu is the vertical menu displayed. The event provides both the marking menu and the context menu so you can examine and edit the contents of either one or both of them before they are displayed. Fusion will then display the marking and context menu that you've customized. If either one is empty it will not be displayed.
- **workspaceActivated**
- **Description**: The workspaceActivated event fires at the VERY end of a workspace being activated. The client can add or remove WorkspaceEventHandlers from the WorkspaceEvent.
- **workspaceDeactivated**
- **Description**: The workspaceDeactivated event fires at the VERY end of a workspace being deactivated. The client can add or remove WorkspaceEventHandlers from the WorkspaceEvent.
- **workspacePreActivate**
- **Description**: The workspacePreActivate event fires at the VERY start of a workspace being activated. The client can add or remove WorkspaceEventHandlers from the WorkspaceEvent.
- **workspacePreDeactivate**
- **Description**: The workspacePreDeactivate event fires at the VERY start of a workspace being deactivated. The client can add or remove WorkspaceEventHandlers from the WorkspaceEvent.
```
--------------------------------
### Access Palettes Collection (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This property provides access to a collection of all existing palettes within Fusion. It also offers functionality to create new custom palettes. The returned object allows iteration and manipulation of palettes.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var palettes = ui.palettes;
// To access existing palettes:
// for (var i = 0; i < palettes.count; i++) {
// var palette = palettes.item(i);
// adsk.debug.log("Palette Name: " + palette.name);
// }
// To create a new custom palette (example):
// var customPalette = palettes.add('MyCustomPalette', 'My Custom Palette', 'com.example.mypalette');
// customPalette.visible = true;
```
--------------------------------
### Handle Command Terminated Event (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This event is fired when a command finishes its execution, whether successfully or due to an error. It can be used for post-command cleanup or logging. The event arguments may contain information about the termination status.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var eventHandlers = ui.commandTerminated;
// Add an event handler
// var handler = {}
// handler.notify = function(args) {
// adsk.debug.log("Command terminated.");
// // args.command will be null if the command was cancelled before execution
// }
// eventHandlers.add(handler);
// Remove the event handler when done
// eventHandlers.remove(handler);
```
--------------------------------
### Handle Workspace Activated Event (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This event fires at the very end of a workspace being activated. It's the appropriate place to add or remove event handlers related to the newly active workspace, ensuring your code runs within the correct context.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var eventHandlers = ui.workspaceActivated;
// Add an event handler
// var handler = {}
// handler.notify = function(args) {
// adsk.debug.log("Workspace activated: " + args.workspace.name);
// // Add workspace-specific event handlers here
// }
// eventHandlers.add(handler);
// Remove the event handler when done
// eventHandlers.remove(handler);
```
--------------------------------
### Terminate Active Command in Fusion API
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
Demonstrates how to terminate the currently running command using the 'terminateActiveCommand' method of the UserInterface object in the Autodesk Fusion API. This is useful for canceling or stopping an ongoing operation programmatically.
```javascript
fusion.userInterface.terminateActiveCommand();
```
--------------------------------
### Check if Tabbed Toolbars are Used (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This function returns a boolean value indicating whether the tabbed toolbars feature is currently enabled in the Fusion user interface. It is a simple check with no specific input or output beyond the boolean result.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var tabbedToolbarsEnabled = ui.isTabbedToolbarsEnabled;
```
--------------------------------
### Handle Active Selection Changed Event (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This event fires when the active selection in the Fusion viewport changes. This typically occurs when the user selects or deselects entities using the Select command. It's useful for reacting to user interaction with the model.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var eventHandlers = ui.activeSelectionChanged;
// Add an event handler
// var handler = {}
// handler.notify = function(args) {
// adsk.debug.log("Active selection changed!");
// // Access selection set if needed: var selectionSet = ui.activeSelections;
// }
// eventHandlers.add(handler);
// Remove the event handler when done (important for cleanup)
// eventHandlers.remove(handler);
```
--------------------------------
### Check Object Validity (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This method indicates whether an object reference is still valid. It's crucial for ensuring that operations are performed on existing, non-deleted objects. It returns a boolean value.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
// Assuming 'myObject' is a valid Fusion API object
// var myObject = ...;
// if (myObject.isValid) {
// // Object is valid, proceed with operations
// } else {
// // Object is no longer valid
// }
```
--------------------------------
### Handle Workspace Deactivated Event (Fusion API)
Source: https://github.com/ipendle/autodesk-fusion-api-documentation/blob/main/UserInterface.htm
This event fires at the very end of a workspace being deactivated. It's the ideal place to clean up any workspace-specific resources or event handlers before the user switches to a different workspace.
```JavaScript
importPackage(Packages.Autodesk.Fusion);
var ui = adsk.core.UserInterface.get();
var eventHandlers = ui.workspaceDeactivated;
// Add an event handler
// var handler = {}
// handler.notify = function(args) {
// adsk.debug.log("Workspace deactivated: " + args.workspace.name);
// // Remove workspace-specific event handlers here
// }
// eventHandlers.add(handler);
// Remove the event handler when done
// eventHandlers.remove(handler);
```