diff --git a/SolidDna/CADBooster.SolidDna/Errors/SolidDnaErrorCode.cs b/SolidDna/CADBooster.SolidDna/Errors/SolidDnaErrorCode.cs
index 6ee6c93..f29fbd0 100644
--- a/SolidDna/CADBooster.SolidDna/Errors/SolidDnaErrorCode.cs
+++ b/SolidDna/CADBooster.SolidDna/Errors/SolidDnaErrorCode.cs
@@ -228,6 +228,11 @@ public enum SolidDnaErrorCode
///
SolidWorksCommandItemPositionError = 12010,
+ ///
+ /// There was an error while trying to activate a Context Menu Item that was already activated
+ ///
+ SolidWorksCommandContextMenuItemReActivateError = 12011,
+
#endregion
#region Export Data (13,000)
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/CommandManager.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/CommandManager.cs
index db81b28..baded2f 100644
--- a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/CommandManager.cs
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/CommandManager.cs
@@ -19,6 +19,11 @@ public class CommandManager : SolidDnaObject
///
private readonly List mCommandFlyouts = new List();
+ ///
+ /// A list of all created command context menu items
+ ///
+ private readonly List mCommandContextItems = new List();
+
///
/// Unique ID for flyouts (just increment every time we add one)
///
@@ -76,6 +81,16 @@ public CommandManagerGroup CreateCommandTab(string title, int id, List
+ /// Creates context menu items from the provided collection of objects
+ ///
+ /// The collection of command items to create
+ public void CreateContextMenuItems(IEnumerable commandItems)
+ {
+ foreach (var item in commandItems)
+ mCommandContextItems.AddRange(item.Create());
+ }
+
///
/// Create a command group from a list of items. Uses a single list of items, separators and flyouts.
/// NOTE: If you set to false, you should pick a new ID every time you change your tab.
@@ -119,7 +134,7 @@ public CommandManagerGroup CreateCommandGroupAndTabs(string title, int id, List<
// Track all flyouts for all add-ins that use SolidDNA
mCommandFlyouts.AddRange(commandManagerItems.OfType());
-
+
// Create the group
group.Create(this, title);
@@ -251,7 +266,10 @@ private CommandManagerGroup CreateCommandGroup(string title, int id, List
@@ -262,7 +280,10 @@ private void RemoveCommandFlyout(CommandManagerFlyout flyout)
private void RemoveCommandGroup(CommandManagerGroup group, bool runtimeOnly = false)
{
lock (mCommandGroups)
+ {
BaseObject.RemoveCommandGroup2(group.UserId, runtimeOnly);
+ mCommandGroups.Remove(group);
+ }
}
///
@@ -318,6 +339,10 @@ public override void Dispose()
// Remove all command flyouts
mCommandFlyouts?.ForEach(RemoveCommandFlyout);
+ // Dispose all command context menu items
+ mCommandContextItems?.ForEach(x => x.Dispose());
+ mCommandContextItems.Clear();
+
base.Dispose();
}
}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerItemExtensions.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerItemExtensions.cs
new file mode 100644
index 0000000..cddcb48
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerItemExtensions.cs
@@ -0,0 +1,54 @@
+using SolidWorks.Interop.swconst;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// Provides extension methods for converting objects to
+ ///
+ public static class CommandManagerItemExtensions
+ {
+ ///
+ /// Converts a collection of objects to objects
+ ///
+ /// The collection of objects to convert
+ /// An optional function to determine the selection type for each item
+ /// A collection of objects
+ public static IEnumerable AsCommandCreatable(this IEnumerable items,
+ Func selectTypeSelector = null)
+ => items.Select(x =>
+ x.AsCommandCreatable(
+ selectTypeSelector is null
+ ? SelectionType.Everything
+ : selectTypeSelector.Invoke(x)));
+
+ ///
+ /// Converts a single object to an object
+ ///
+ /// The object to convert
+ /// An object
+ public static ICommandCreatable AsCommandCreatable(this CommandManagerItem item)
+ => item.AsCommandCreatable(SelectionType.Everything);
+
+ ///
+ /// Converts a single object to an object
+ ///
+ /// The object to convert
+ /// The selection type for the item (defaults to )
+ /// An object
+ public static ICommandCreatable AsCommandCreatable(this CommandManagerItem item, SelectionType selectType)
+ => new CommandContextItem()
+ {
+ Name = item.Name,
+ Hint = item.Hint,
+ OnClick = item.OnClick,
+ OnStateCheck = item.OnStateCheck,
+ SelectionType = selectType,
+ VisibleForAssemblies = item.VisibleForAssemblies,
+ VisibleForDrawings = item.VisibleForDrawings,
+ VisibleForParts = item.VisibleForParts
+ };
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextBase.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextBase.cs
new file mode 100644
index 0000000..d0c3d0e
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextBase.cs
@@ -0,0 +1,73 @@
+using SolidWorks.Interop.swconst;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// A command context menu item base class
+ ///
+ public abstract class CommandContextBase
+ {
+
+ private bool _isCreated;
+
+ #region Public Properties
+
+ ///
+ /// The help text for this item.
+ ///
+ public string Hint { get; set; }
+
+ ///
+ /// True to show this item in the context menu when an assembly is open.
+ ///
+ public bool VisibleForAssemblies { get; set; } = true;
+
+ ///
+ /// True to show this item in the context menu when a drawing is open.
+ ///
+ public bool VisibleForDrawings { get; set; } = true;
+
+ ///
+ /// True to show this item in the context menu when a part is open.
+ ///
+ public bool VisibleForParts { get; set; } = true;
+
+ ///
+ /// The action to call when the item is clicked
+ ///
+ public Action OnClick { get; set; }
+
+ ///
+ /// The action to call when the item state requested
+ ///
+ public Action OnStateCheck { get; set; }
+
+ ///
+ /// The selection type that determines where the context menu will be shown
+ ///
+ public SelectionType SelectionType { get; set; } = SelectionType.Everything;
+
+ #endregion
+
+ ///
+ /// Creates the command context item for the specified document types
+ ///
+ /// The path to use for hierarchical naming. If empty, the item's name is used
+ /// A list of created command context items
+ /// Thrown if the item has already been created
+ public virtual IEnumerable Create(string path = "")
+ {
+ if (_isCreated)
+ throw new SolidDnaException(
+ SolidDnaErrors.CreateError(SolidDnaErrorTypeCode.SolidWorksCommandManager,
+ SolidDnaErrorCode.SolidWorksCommandContextMenuItemReActivateError));
+
+ _isCreated = true;
+
+ return Enumerable.Empty();
+ }
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextCreatedBase.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextCreatedBase.cs
new file mode 100644
index 0000000..6b6c06e
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextCreatedBase.cs
@@ -0,0 +1,126 @@
+using SolidWorks.Interop.swconst;
+using System;
+
+namespace CADBooster.SolidDna
+{
+ internal abstract class CommandContextCreatedBase : ICommandCreated, ICommandItem
+ {
+ ///
+ /// Gets the unique callback ID for this command context item
+ ///
+ public string CallbackId { get; } = Guid.NewGuid().ToString("N");
+
+ ///
+ /// Gets the name of this command context item
+ ///
+ public abstract string Name { get; }
+
+ ///
+ /// Gets the hint text for this command context item
+ ///
+ public string Hint { get; }
+
+ ///
+ /// Gets the selection type that determines where this item is shown
+ ///
+ public SelectionType SelectionType { get; }
+
+ ///
+ /// Gets the document type (Assembly, Part, or Drawing) for which this item is created
+ ///
+ public DocumentType DocumentType { get; }
+
+ ///
+ /// Gets the action to call when this item is clicked
+ ///
+ public Action OnClick { get; }
+
+ ///
+ /// Gets the action to call when the state of this item is checked
+ ///
+ public Action OnStateCheck { get; private set; }
+
+ ///
+ /// Initializes a new instance of the class
+ ///
+ /// The command context item to create
+ /// The full name of the item, including its hierarchical path
+ /// The document type (Assembly, Part, or Drawing) for which this item is created
+ public CommandContextCreatedBase(CommandContextBase commandContextBase, DocumentType documentType)
+ {
+ Hint = commandContextBase.Hint;
+ OnClick = commandContextBase.OnClick;
+ OnStateCheck = commandContextBase.OnStateCheck;
+ SelectionType = commandContextBase.SelectionType;
+ DocumentType = documentType;
+
+ // Listen out for callbacks
+ PlugInIntegration.CallbackFired += PlugInIntegration_CallbackFired;
+
+ // Listen out for EnableMethod
+ PlugInIntegration.ItemStateCheckFired += PlugInIntegration_EnableMethodFired;
+
+ Logger.LogDebugSource("Context menu item created");
+ }
+
+ ///
+ /// Fired when a SolidWorks callback is fired
+ ///
+ /// The name of the callback that was fired
+ private void PlugInIntegration_CallbackFired(string name)
+ {
+ if (CallbackId != name)
+ return;
+
+ // Call the action
+ OnClick?.Invoke();
+ }
+
+ ///
+ /// Fired when a SolidWorks UpdateCallbackFunction is fired
+ ///
+ /// The arguments for user handling
+ private void PlugInIntegration_EnableMethodFired(CommandManagerItemStateCheckArgs args)
+ {
+ if (CallbackId != args.CallbackId)
+ return;
+
+ // Call the action
+ OnStateCheck?.Invoke(args);
+ }
+
+ ///
+ /// Disposing
+ ///
+ public void Dispose()
+ {
+ /// I can't find the way to remove the item
+
+ /// It always returns false, and the item isn't removed.
+ //var removeMenuPopupItemResult = AddInIntegration.SolidWorks.UnsafeObject.RemoveMenuPopupItem2(
+ // (int)DocumentType,
+ // SolidWorksEnvironment.Application.SolidWorksCookie,
+ // (int)SelectionType,
+ // FullName,
+ // $"{nameof(SolidAddIn.Callback)}({CallbackId})",
+ // $"{nameof(SolidAddIn.ItemStateCheck)}({CallbackId})",
+ // Hint,
+ // string.Empty
+ //);
+
+ /// It always returns true, but the item isn't removed.
+ //var removeFromPopupMenuResult = AddInIntegration.SolidWorks.UnsafeObject.RemoveFromPopupMenu(
+ // CommandId,
+ // (int)DocumentType,
+ // (int)SelectionType,
+ // true
+ //);
+
+ /// Besides, the user can hide it using .
+
+ // Stop listening out for callbacks
+ PlugInIntegration.CallbackFired -= PlugInIntegration_CallbackFired;
+ PlugInIntegration.ItemStateCheckFired -= PlugInIntegration_EnableMethodFired;
+ }
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextIcon.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextIcon.cs
new file mode 100644
index 0000000..ac06abe
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextIcon.cs
@@ -0,0 +1,42 @@
+using System.Collections.Generic;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// Represents a context icon in SolidWorks
+ ///
+ public class CommandContextIcon : CommandContextBase, ICommandCreatable
+ {
+ ///
+ /// Gets or sets the icon formatted path
+ ///
+ public string Icon { get; set; }
+
+ ///
+ /// Gets the name of the command (implementing ICommandCreatable interface)
+ ///
+ string ICommandCreatable.Name => Hint;
+
+ ///
+ /// Creates the command context icon for the specified document types
+ ///
+ /// Not used for icon
+ /// A list of created command context icons
+ /// Thrown if the item has already been created
+ public sealed override IEnumerable Create(string _s = "")
+ {
+ _ = base.Create();
+
+ var created = new List();
+
+ if (VisibleForAssemblies)
+ created.Add(new CommandContextIconCreated(this, DocumentType.Assembly));
+ if (VisibleForDrawings)
+ created.Add(new CommandContextIconCreated(this, DocumentType.Drawing));
+ if (VisibleForParts)
+ created.Add(new CommandContextIconCreated(this, DocumentType.Part));
+
+ return created;
+ }
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextIconCreated.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextIconCreated.cs
new file mode 100644
index 0000000..1259ea5
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextIconCreated.cs
@@ -0,0 +1,43 @@
+using SolidWorks.Interop.sldworks;
+using System.Runtime.InteropServices;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// Represents a created command context icon in the SolidWorks
+ ///
+ internal class CommandContextIconCreated : CommandContextCreatedBase
+ {
+ ///
+ /// Gets the name of this command context item
+ ///
+ public sealed override string Name => Hint;
+
+ ///
+ /// Initializes a new command context icon in the SolidWorks UI
+ ///
+ /// The icon configuration
+ /// The document type this icon applies to
+ public CommandContextIconCreated(CommandContextIcon commandContextIcon,
+ DocumentType documentType) : base(commandContextIcon, documentType)
+ {
+ // The list of icons. There should be a one multi sized icon.
+ var icons = Icons.GetArrayFromDictionary(Icons.GetFormattedPathDictionary(commandContextIcon.Icon));
+
+ // Get the SolidWorks frame and add the menu icon
+ var frame = (IFrame)AddInIntegration.SolidWorks.UnsafeObject.Frame();
+
+ _ = frame.AddMenuPopupIcon3(
+ (int)DocumentType,
+ SelectionType,
+ Hint,
+ SolidWorksEnvironment.Application.SolidWorksCookie,
+ $"{nameof(SolidAddIn.Callback)}({CallbackId})",
+ $"{nameof(SolidAddIn.ItemStateCheck)}({CallbackId})",
+ SelectionType.GetCustomFeaturesSelection(),
+ icons);
+
+ _ = Marshal.ReleaseComObject(frame);
+ }
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextItemCreated.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextItemCreated.cs
new file mode 100644
index 0000000..0a27d4b
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextItemCreated.cs
@@ -0,0 +1,47 @@
+using System.Runtime.InteropServices;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// A command context menu item
+ ///
+ internal class CommandContextItemCreated : CommandContextCreatedBase
+ {
+ ///
+ /// Gets the name of this command context item
+ ///
+ public sealed override string Name => _name;
+
+ ///
+ /// Gets the command ID assigned by SolidWorks for this item
+ ///
+ public int CommandId { get; }
+
+ private readonly string _name;
+
+ ///
+ /// Creates the command context item for the specified document types
+ ///
+ /// The path to use for hierarchical naming. If empty, the item's name is used
+ /// A list of created command context items
+ /// Thrown if the item has already been created
+ public CommandContextItemCreated(CommandContextItem commandContextItem,
+ string fullName,
+ DocumentType documentType) : base(commandContextItem, documentType)
+ {
+ _name = commandContextItem.Name;
+
+ /// We have , but it adds a group, and there's no possibility to add a root item.
+ CommandId = AddInIntegration.SolidWorks.UnsafeObject.AddMenuPopupItem3(
+ (int)DocumentType,
+ SolidWorksEnvironment.Application.SolidWorksCookie,
+ SelectionType,
+ fullName,
+ $"{nameof(SolidAddIn.Callback)}({CallbackId})",
+ $"{nameof(SolidAddIn.ItemStateCheck)}({CallbackId})",
+ Hint,
+ SelectionType.GetCustomFeaturesSelection()
+ );
+ }
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextMenuGroup.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextMenuGroup.cs
new file mode 100644
index 0000000..ffb7929
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextMenuGroup.cs
@@ -0,0 +1,47 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// Represents a command context menu group in SolidWorks
+ ///
+ public class CommandContextMenuGroup : ICommandCreatable
+ {
+ private bool _isCreated;
+
+ #region Public Properties
+
+ ///
+ /// The name of this command group
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Context menu items in this group
+ ///
+ public List Items { get; set; }
+
+ #endregion
+
+ ///
+ /// Creates the command context menu group and its items
+ ///
+ /// The hierarchical path for the group
+ /// A list of created command context menu items
+ /// Thrown if the group has already been created
+ public IEnumerable Create(string path)
+ {
+ if (_isCreated)
+ throw new SolidDnaException(
+ SolidDnaErrors.CreateError(SolidDnaErrorTypeCode.SolidWorksCommandManager,
+ SolidDnaErrorCode.SolidWorksCommandContextMenuItemReActivateError));
+
+ _isCreated = true;
+
+ return Enumerable.Repeat(new CommandContextMenuGroupCreated(Name, path, Items), 1);
+ }
+
+ public override string ToString() => $"ContextMenuGroup with name: {Name}. Count of sub items: {Items.Count}";
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextMenuGroupCreated.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextMenuGroupCreated.cs
new file mode 100644
index 0000000..2bdcd13
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextMenuGroupCreated.cs
@@ -0,0 +1,55 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// Represents a created command context menu group in SolidWorks
+ /// This class handles the creation and disposal of a group of context menu items
+ ///
+ internal class CommandContextMenuGroupCreated : ICommandCreated
+ {
+ ///
+ /// Gets the unique callback ID for this command context menu group
+ ///
+ public string CallbackId => string.Empty;
+
+ ///
+ /// Gets the name of this command context menu group
+ ///
+ public string Name { get; }
+
+ ///
+ /// A list of created command items within this group
+ ///
+ private readonly List _createdItems;
+
+ ///
+ /// Initializes a new instance of the class
+ ///
+ /// The name of the group
+ /// The hierarchical path for the group
+ /// The list of command items to include in the group
+ public CommandContextMenuGroupCreated(string name, string path, List items)
+ {
+ Name = name;
+
+ // Construct the full name for the group using the provided path
+ var fullName = string.IsNullOrEmpty(path) ? $"{Name}" : $"{path}@{Name}";
+
+ // Create all child items and store them in the list
+ _createdItems = items
+ .SelectMany(x => x.Create(fullName))
+ .ToList();
+ }
+
+ ///
+ /// Disposing
+ ///
+ public void Dispose()
+ {
+ // Dispose all child items
+ _createdItems.ForEach(x => x.Dispose());
+ }
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextMenuItem.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextMenuItem.cs
new file mode 100644
index 0000000..2b174ab
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/CommandContextMenuItem.cs
@@ -0,0 +1,39 @@
+using System.Collections.Generic;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// A command context menu item
+ ///
+ public class CommandContextItem : CommandContextBase, ICommandCreatable
+ {
+ ///
+ /// The name of this command
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Creates the command context item for the specified document types
+ ///
+ /// The path to use for hierarchical naming. If empty, the item's name is used
+ /// A list of created command context items
+ /// Thrown if the item has already been created
+ public sealed override IEnumerable Create(string path = "")
+ {
+ _ = base.Create(path);
+
+ var fullName = string.IsNullOrEmpty(path) ? $"{Name}" : $"{path}@{Name}";
+
+ var created = new List();
+
+ if (VisibleForAssemblies)
+ created.Add(new CommandContextItemCreated(this, fullName, DocumentType.Assembly));
+ if (VisibleForDrawings)
+ created.Add(new CommandContextItemCreated(this, fullName, DocumentType.Drawing));
+ if (VisibleForParts)
+ created.Add(new CommandContextItemCreated(this, fullName, DocumentType.Part));
+
+ return created;
+ }
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/ICommandCreatable.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/ICommandCreatable.cs
new file mode 100644
index 0000000..d3e79a4
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/ICommandCreatable.cs
@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// Represents an interface for creating command items in the SolidWorks
+ ///
+ public interface ICommandCreatable
+ {
+ ///
+ /// Name of the command item
+ ///
+ string Name { get; }
+
+ ///
+ /// Creates the command item for the specified path
+ ///
+ /// The path to use for hierarchical naming. If empty, the item's name is used
+ /// A list of created command items
+ IEnumerable Create(string path = "");
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/ICommandCreated.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/ICommandCreated.cs
new file mode 100644
index 0000000..22c571c
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ContextMenuItems/ICommandCreated.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// Represents an interface for a created command item in SolidWorks
+ ///
+ public interface ICommandCreated : IDisposable
+ {
+ ///
+ /// Gets the name of the created command item
+ ///
+ string Name { get; }
+ }
+}
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerFlyout.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/Flyouts/CommandManagerFlyout.cs
similarity index 98%
rename from SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerFlyout.cs
rename to SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/Flyouts/CommandManagerFlyout.cs
index 5d24c60..4aa857f 100644
--- a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerFlyout.cs
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/Flyouts/CommandManagerFlyout.cs
@@ -200,6 +200,7 @@ private void AddCommandItem(CommandManagerItem item)
/// The name of the callback that was fired
private void PlugInIntegration_CallbackFired(string callbackId)
{
+ // TODO: This is not works with FlyoutGroup itself
// Find the item, if any
var item = Items?.FirstOrDefault(f => f.CallbackId == callbackId);
@@ -213,6 +214,7 @@ private void PlugInIntegration_CallbackFired(string callbackId)
/// The arguments for user handling
private void PlugInIntegration_UpdateCallbackFunctionFired(CommandManagerItemStateCheckArgs args)
{
+ // TODO: This is not works with FlyoutGroup itself
// Find the item, if any
var item = Items?.FirstOrDefault(f => f.CallbackId == args.CallbackId);
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerFlyoutType.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/Flyouts/CommandManagerFlyoutType.cs
similarity index 100%
rename from SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerFlyoutType.cs
rename to SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/Flyouts/CommandManagerFlyoutType.cs
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ICommandItem.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ICommandItem.cs
new file mode 100644
index 0000000..94c518b
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ICommandItem.cs
@@ -0,0 +1,25 @@
+using System;
+
+namespace CADBooster.SolidDna
+{
+ ///
+ /// Represents an interface for a command item
+ ///
+ public interface ICommandItem
+ {
+ ///
+ /// The unique Callback ID
+ ///
+ string CallbackId { get; }
+
+ ///
+ /// The action to call when the item is clicked
+ ///
+ Action OnClick { get; }
+
+ ///
+ /// The action to call when the item's state is requested
+ ///
+ Action OnStateCheck { get; }
+ }
+}
\ No newline at end of file
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerItemTabView.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ManagerItems/CommandManagerItemTabView.cs
similarity index 100%
rename from SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerItemTabView.cs
rename to SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ManagerItems/CommandManagerItemTabView.cs
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerSeparator.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ManagerItems/CommandManagerSeparator.cs
similarity index 100%
rename from SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/CommandManagerSeparator.cs
rename to SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ManagerItems/CommandManagerSeparator.cs
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ICommandManagerItem.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ManagerItems/ICommandManagerItem.cs
similarity index 74%
rename from SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ICommandManagerItem.cs
rename to SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ManagerItems/ICommandManagerItem.cs
index e9eff98..8564f3e 100644
--- a/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ICommandManagerItem.cs
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/CommandManager/Item/ManagerItems/ICommandManagerItem.cs
@@ -2,33 +2,18 @@
namespace CADBooster.SolidDna
{
- public interface ICommandManagerItem
+ public interface ICommandManagerItem : ICommandItem
{
///
/// True if the command should be added to the tab
///
bool AddToTab { get; set; }
- ///
- /// The unique Callback ID (set by creator)
- ///
- string CallbackId { get; }
-
///
/// The command ID for this flyout item
///
int CommandId { get; }
- ///
- /// The action to call when the item is clicked
- ///
- Action OnClick { get; set; }
-
- ///
- /// The action to call when the item state is requested
- ///
- Action OnStateCheck { get; set; }
-
///
/// The position of the item in the list. Specify 0 to add the item to the beginning of the toolbar or menu, or specify -1 to add it to the end.
/// After creating the item, we set this to the actual position (flyouts and separators are not included in the count) and we use the actual position to get the .
diff --git a/SolidDna/CADBooster.SolidDna/SolidWorks/SelectionManager/SelectionType.cs b/SolidDna/CADBooster.SolidDna/SolidWorks/SelectionManager/SelectionType.cs
new file mode 100644
index 0000000..108a962
--- /dev/null
+++ b/SolidDna/CADBooster.SolidDna/SolidWorks/SelectionManager/SelectionType.cs
@@ -0,0 +1,884 @@
+using System;
+
+namespace CADBooster.SolidDna
+{
+ public class SelectionType
+ {
+ #region Static values
+
+ ///
+ /// Nothing selected.
+ ///
+ public static readonly SelectionType Nothing = new SelectionType(0, string.Empty);
+
+ ///
+ /// Edge selection.
+ ///
+ public static readonly SelectionType Edge = new SelectionType(1, "EDGE");
+
+ ///
+ /// Face selection.
+ ///
+ public static readonly SelectionType Face = new SelectionType(2, "FACE");
+
+ ///
+ /// Vertex selection.
+ ///
+ public static readonly SelectionType Vertex = new SelectionType(3, "VERTEX");
+
+ ///
+ /// Datum plane selection.
+ ///
+ public static readonly SelectionType DatumPlane = new SelectionType(4, "PLANE");
+
+ ///
+ /// Datum axis selection.
+ ///
+ public static readonly SelectionType DatumAxis = new SelectionType(5, "AXIS");
+
+ ///
+ /// Datum point selection.
+ ///
+ public static readonly SelectionType DatumPoint = new SelectionType(6, "DATUMPOINT");
+
+ ///
+ /// OLE item selection.
+ ///
+ public static readonly SelectionType OleItem = new SelectionType(7, "OLEITEM");
+
+ ///
+ /// Attribute selection.
+ ///
+ public static readonly SelectionType Attribute = new SelectionType(8, "ATTRIBUTE");
+
+ ///
+ /// Sketch selection.
+ ///
+ public static readonly SelectionType Sketch = new SelectionType(9, "SKETCH");
+
+ ///
+ /// Sketch segment selection.
+ ///
+ public static readonly SelectionType SketchSegment = new SelectionType(10, "SKETCHSEGMENT");
+
+ ///
+ /// Sketch point selection.
+ ///
+ public static readonly SelectionType SketchPoint = new SelectionType(11, "SKETCHPOINT");
+
+ ///
+ /// Drawing view selection.
+ ///
+ public static readonly SelectionType DrawingView = new SelectionType(12, "DRAWINGVIEW");
+
+ ///
+ /// Geometric tolerance selection.
+ ///
+ public static readonly SelectionType GeometricTolerance = new SelectionType(13, "GTOL");
+
+ ///
+ /// Dimension selection.
+ ///
+ public static readonly SelectionType Dimension = new SelectionType(14, "DIMENSION");
+
+ ///
+ /// Note selection.
+ ///
+ public static readonly SelectionType Note = new SelectionType(15, "NOTE");
+
+ ///
+ /// Section line selection.
+ ///
+ public static readonly SelectionType SectionLine = new SelectionType(16, "SECTIONLINE");
+
+ ///
+ /// Detail circle selection.
+ ///
+ public static readonly SelectionType DetailCircle = new SelectionType(17, "DETAILCIRCLE");
+
+ ///
+ /// Section text selection.
+ ///
+ public static readonly SelectionType SectionText = new SelectionType(18, "SECTIONTEXT");
+
+ ///
+ /// Sheet selection.
+ ///
+ public static readonly SelectionType Sheet = new SelectionType(19, "SHEET");
+
+ ///
+ /// Component selection.
+ ///
+ public static readonly SelectionType Component = new SelectionType(20, "COMPONENT");
+
+ ///
+ /// Mate selection.
+ ///
+ public static readonly SelectionType Mate = new SelectionType(21, "MATE");
+
+ ///
+ /// Body feature selection.
+ ///
+ public static readonly SelectionType BodyFeature = new SelectionType(22, "BODYFEATURE");
+
+ ///
+ /// Reference curve selection.
+ ///
+ public static readonly SelectionType ReferenceCurve = new SelectionType(23, "REFCURVE");
+
+ ///
+ /// External sketch segment selection.
+ ///
+ public static readonly SelectionType ExternalSketchSegment = new SelectionType(24, "EXTSKETCHSEGMENT");
+
+ ///
+ /// External sketch point selection.
+ ///
+ public static readonly SelectionType ExternalSketchPoint = new SelectionType(25, "EXTSKETCHPOINT");
+
+ ///
+ /// Helix selection.
+ ///
+ public static readonly SelectionType Helix = new SelectionType(26, "HELIX");
+
+ ///
+ /// Reference surface selection.
+ ///
+ public static readonly SelectionType ReferenceSurface = new SelectionType(27, "REFSURFACE");
+
+ ///
+ /// Center mark selection.
+ ///
+ public static readonly SelectionType CenterMark = new SelectionType(28, "CENTERMARKS");
+
+ ///
+ /// In-context feature selection.
+ ///
+ public static readonly SelectionType InContextFeature = new SelectionType(29, "INCONTEXTFEAT");
+
+ ///
+ /// Mate group selection.
+ ///
+ public static readonly SelectionType MateGroup = new SelectionType(30, "MATEGROUP");
+
+ ///
+ /// Break line selection.
+ ///
+ public static readonly SelectionType BreakLine = new SelectionType(31, "BREAKLINE");
+
+ ///
+ /// In-context features selection.
+ ///
+ public static readonly SelectionType InContextFeatures = new SelectionType(32, "INCONTEXTFEATS");
+
+ ///
+ /// Mate groups selection.
+ ///
+ public static readonly SelectionType MateGroups = new SelectionType(33, "MATEGROUPS");
+
+ ///
+ /// Sketch text selection.
+ ///
+ public static readonly SelectionType SketchText = new SelectionType(34, "SKETCHTEXT");
+
+ ///
+ /// SF symbol selection.
+ ///
+ public static readonly SelectionType SfSymbol = new SelectionType(35, "SFSYMBOL");
+
+ ///
+ /// Datum tag selection.
+ ///
+ public static readonly SelectionType DatumTag = new SelectionType(36, "DATUMTAG");
+
+ ///
+ /// Component pattern selection.
+ ///
+ public static readonly SelectionType ComponentPattern = new SelectionType(37, "COMPPATTERN");
+
+ ///
+ /// Weld selection.
+ ///
+ public static readonly SelectionType Weld = new SelectionType(38, "WELD");
+
+ ///
+ /// Cosmetic thread selection.
+ ///
+ public static readonly SelectionType CosmeticThread = new SelectionType(39, "CTHREAD");
+
+ ///
+ /// Datum target selection.
+ ///
+ public static readonly SelectionType DatumTarget = new SelectionType(40, "DTMTARG");
+
+ ///
+ /// Point reference selection.
+ ///
+ public static readonly SelectionType PointReference = new SelectionType(41, "POINTREF");
+
+ ///
+ /// Cabinet selection.
+ ///
+ public static readonly SelectionType Cabinet = new SelectionType(42, "DCABINET");
+
+ ///
+ /// Exploded view selection.
+ ///
+ public static readonly SelectionType ExplodedView = new SelectionType(43, "EXPLODEDVIEWS");
+
+ ///
+ /// Explode step selection.
+ ///
+ public static readonly SelectionType ExplodeStep = new SelectionType(44, "EXPLODESTEPS");
+
+ ///
+ /// Explode line selection.
+ ///
+ public static readonly SelectionType ExplodeLine = new SelectionType(45, "EXPLODELINES");
+
+ ///
+ /// Silhouette selection.
+ ///
+ public static readonly SelectionType Silhouette = new SelectionType(46, "SILHOUETTE");
+
+ ///
+ /// Configuration selection.
+ ///
+ public static readonly SelectionType Configuration = new SelectionType(47, "CONFIGURATIONS");
+
+ ///
+ /// Object handle selection.
+ ///
+ public static readonly SelectionType ObjectHandle = new SelectionType(48, string.Empty);
+
+ ///
+ /// Arrow selection.
+ ///
+ public static readonly SelectionType Arrow = new SelectionType(49, "VIEWARROW");
+
+ ///
+ /// Zone selection.
+ ///
+ public static readonly SelectionType Zone = new SelectionType(50, "ZONES");
+
+ ///
+ /// Reference edge selection.
+ ///
+ public static readonly SelectionType ReferenceEdge = new SelectionType(51, "REFERENCE-EDGE");
+
+ ///
+ /// Reference face selection.
+ ///
+ public static readonly SelectionType ReferenceFace = new SelectionType(52, string.Empty);
+
+ ///
+ /// Reference silhouette selection.
+ ///
+ public static readonly SelectionType ReferenceSilhouette = new SelectionType(53, string.Empty);
+
+ ///
+ /// BOM selection.
+ ///
+ public static readonly SelectionType Bom = new SelectionType(54, "BOM");
+
+ ///
+ /// Equation folder selection.
+ ///
+ public static readonly SelectionType EquationFolder = new SelectionType(55, "EQNFOLDER");
+
+ ///
+ /// Sketch hatch selection.
+ ///
+ public static readonly SelectionType SketchHatch = new SelectionType(56, "SKETCHHATCH");
+
+ ///
+ /// Import folder selection.
+ ///
+ public static readonly SelectionType ImportFolder = new SelectionType(57, "IMPORTFOLDER");
+
+ ///
+ /// Viewer hyperlink selection.
+ ///
+ public static readonly SelectionType ViewerHyperlink = new SelectionType(58, "HYPERLINK");
+
+ ///
+ /// Midpoint selection.
+ ///
+ public static readonly SelectionType Midpoint = new SelectionType(59, string.Empty);
+
+ ///
+ /// Custom symbol selection.
+ ///
+ public static readonly SelectionType CustomSymbol = new SelectionType(60, "CUSTOMSYMBOL");
+
+ ///
+ /// Coordinate system selection.
+ ///
+ public static readonly SelectionType CoordinateSystem = new SelectionType(61, "COORDSYS");
+
+ ///
+ /// Datum line selection.
+ ///
+ public static readonly SelectionType DatumLine = new SelectionType(62, "REFLINE");
+
+ ///
+ /// Route curve selection.
+ ///
+ public static readonly SelectionType RouteCurve = new SelectionType(63, string.Empty);
+
+ ///
+ /// BOM template selection.
+ ///
+ public static readonly SelectionType BomTemplate = new SelectionType(64, "BOMTEMP");
+
+ ///
+ /// Route point selection.
+ ///
+ public static readonly SelectionType RoutePoint = new SelectionType(65, "ROUTEPOINT");
+
+ ///
+ /// Connection point selection.
+ ///
+ public static readonly SelectionType ConnectionPoint = new SelectionType(66, "CONNECTIONPOINT");
+
+ ///
+ /// Route sweep selection.
+ ///
+ public static readonly SelectionType RouteSweep = new SelectionType(67, string.Empty);
+
+ ///
+ /// Position group selection.
+ ///
+ public static readonly SelectionType PositionGroup = new SelectionType(68, "POSGROUP");
+
+ ///
+ /// Browser item selection.
+ ///
+ public static readonly SelectionType BrowserItem = new SelectionType(69, "BROWSERITEM");
+
+ ///
+ /// Fabricated route selection.
+ ///
+ public static readonly SelectionType FabricatedRoute = new SelectionType(70, "ROUTEFABRICATED");
+
+ ///
+ /// Sketch point feature selection.
+ ///
+ public static readonly SelectionType SketchPointFeature = new SelectionType(71, "SKETCHPOINTFEAT");
+
+ ///
+ /// Component don't override selection.
+ ///
+ public static readonly SelectionType ComponentDontOverride = new SelectionType(72, string.Empty);
+
+ ///
+ /// Light selection.
+ ///
+ public static readonly SelectionType Light = new SelectionType(73, "LIGHTS");
+
+ ///
+ /// Wire body selection.
+ ///
+ public static readonly SelectionType WireBody = new SelectionType(74, string.Empty);
+
+ ///
+ /// Surface body selection.
+ ///
+ public static readonly SelectionType SurfaceBody = new SelectionType(75, "SURFACEBODY");
+
+ ///
+ /// Solid body selection.
+ ///
+ public static readonly SelectionType SolidBody = new SelectionType(76, "SOLIDBODY");
+
+ ///
+ /// Frame point selection.
+ ///
+ public static readonly SelectionType FramePoint = new SelectionType(77, "FRAMEPOINT");
+
+ ///
+ /// Surface body first selection.
+ ///
+ public static readonly SelectionType SurfaceBodyFirst = new SelectionType(78, string.Empty);
+
+ ///
+ /// Manipulator selection.
+ ///
+ public static readonly SelectionType Manipulator = new SelectionType(79, "MANIPULATOR");
+
+ ///
+ /// Picture body selection.
+ ///
+ public static readonly SelectionType PictureBody = new SelectionType(80, "PICTURE BODY");
+
+ ///
+ /// Solid body first selection.
+ ///
+ public static readonly SelectionType SolidBodyFirst = new SelectionType(81, string.Empty);
+
+ ///
+ /// Hole series selection.
+ ///
+ public static readonly SelectionType HoleSeries = new SelectionType(83, "HOLESERIES");
+
+ ///
+ /// Leader selection.
+ ///
+ public static readonly SelectionType Leader = new SelectionType(84, "LEADER");
+
+ ///
+ /// Sketch bitmap selection.
+ ///
+ public static readonly SelectionType SketchBitmap = new SelectionType(85, "SKETCHBITMAP");
+
+ ///
+ /// Dowel symbol selection.
+ ///
+ public static readonly SelectionType DowelSymbol = new SelectionType(86, "DOWLELSYM");
+
+ ///
+ /// External sketch text selection.
+ ///
+ public static readonly SelectionType ExternalSketchText = new SelectionType(88, "EXTSKETCHTEXT");
+
+ ///
+ /// Block instance selection.
+ ///
+ public static readonly SelectionType BlockInstance = new SelectionType(93, "BLOCKINST");
+
+ ///
+ /// Feature folder selection.
+ ///
+ public static readonly SelectionType FeatureFolder = new SelectionType(94, "FTRFOLDER");
+
+ ///
+ /// Sketch region selection.
+ ///
+ public static readonly SelectionType SketchRegion = new SelectionType(95, "SKETCHREGION");
+
+ ///
+ /// Sketch contour selection.
+ ///
+ public static readonly SelectionType SketchContour = new SelectionType(96, "SKETCHCONTOUR");
+
+ ///
+ /// BOM feature selection.
+ ///
+ public static readonly SelectionType BomFeature = new SelectionType(97, "BOMFEATURE");
+
+ ///
+ /// Annotation table selection.
+ ///
+ public static readonly SelectionType AnnotationTable = new SelectionType(98, "ANNOTATIONTABLES");
+
+ ///
+ /// Block definition selection.
+ ///
+ public static readonly SelectionType BlockDefinition = new SelectionType(99, "BLOCKDEF");
+
+ ///
+ /// Center mark symbol selection.
+ ///
+ public static readonly SelectionType CenterMarkSymbol = new SelectionType(100, "CENTERMARKSYMS");
+
+ ///
+ /// Simulation selection.
+ ///
+ public static readonly SelectionType Simulation = new SelectionType(101, "SIMULATION");
+
+ ///
+ /// Simulation element selection.
+ ///
+ public static readonly SelectionType SimulationElement = new SelectionType(102, "SIMULATION_ELEMENT");
+
+ ///
+ /// Center line selection.
+ ///
+ public static readonly SelectionType CenterLine = new SelectionType(103, "CENTERLINE");
+
+ ///
+ /// Hole table feature selection.
+ ///
+ public static readonly SelectionType HoleTableFeature = new SelectionType(104, "HOLETABLE");
+
+ ///
+ /// Hole table axis selection.
+ ///
+ public static readonly SelectionType HoleTableAxis = new SelectionType(105, "HOLETABLEAXIS");
+
+ ///
+ /// Weldment selection.
+ ///
+ public static readonly SelectionType Weldment = new SelectionType(106, "WELDMENT");
+
+ ///
+ /// Sub weld folder selection.
+ ///
+ public static readonly SelectionType SubWeldFolder = new SelectionType(107, "SUBWELDMENT");
+
+ ///
+ /// Exclude manipulator selection.
+ ///
+ public static readonly SelectionType ExcludeManipulator = new SelectionType(111, string.Empty);
+
+ ///
+ /// Sub-sketch instance selection.
+ ///
+ public static readonly SelectionType SubSketchInstance = new SelectionType(114, "SUBSKETCHINST");
+
+ ///
+ /// Weldment table feature selection.
+ ///
+ public static readonly SelectionType WeldmentTableFeature = new SelectionType(116, "WELDMENTTABLE");
+
+ ///
+ /// Body folder selection.
+ ///
+ public static readonly SelectionType BodyFolder = new SelectionType(118, "BDYFOLDER");
+
+ ///
+ /// Revision table feature selection.
+ ///
+ public static readonly SelectionType RevisionTableFeature = new SelectionType(119, "REVISIONTABLEFEAT");
+
+ ///
+ /// Sub-atom folder selection.
+ ///
+ public static readonly SelectionType SubAtomFolder = new SelectionType(121, string.Empty);
+
+ ///
+ /// Weld bead selection.
+ ///
+ public static readonly SelectionType WeldBead = new SelectionType(122, "WELDBEADS");
+
+ ///
+ /// Embed link document selection.
+ ///
+ public static readonly SelectionType EmbedLinkDoc = new SelectionType(123, "EMBEDLINKDOC");
+
+ ///
+ /// Journal selection.
+ ///
+ public static readonly SelectionType Journal = new SelectionType(124, "JOURNAL");
+
+ ///
+ /// Documents folder selection.
+ ///
+ public static readonly SelectionType DocsFolder = new SelectionType(125, "DOCSFOLDER");
+
+ ///
+ /// Comments folder selection.
+ ///
+ public static readonly SelectionType CommentsFolder = new SelectionType(126, "COMMENTSFOLDER");
+
+ ///
+ /// Comment selection.
+ ///
+ public static readonly SelectionType Comment = new SelectionType(127, "COMMENT");
+
+ ///
+ /// Swift annotation selection.
+ ///
+ public static readonly SelectionType SwiftAnnotation = new SelectionType(130, "SWIFTANN");
+
+ ///
+ /// Swift feature selection.
+ ///
+ public static readonly SelectionType SwiftFeature = new SelectionType(132, "SWIFTFEATURE");
+
+ ///
+ /// Camera selection.
+ ///
+ public static readonly SelectionType Camera = new SelectionType(136, "CAMERAS");
+
+ ///
+ /// Mate supplement selection.
+ ///
+ public static readonly SelectionType MateSupplement = new SelectionType(138, "MATESUPPLEMENT");
+
+ ///
+ /// Annotation view selection.
+ ///
+ public static readonly SelectionType AnnotationView = new SelectionType(139, "ANNVIEW");
+
+ ///
+ /// General table feature selection.
+ ///
+ public static readonly SelectionType GeneralTableFeature = new SelectionType(142, "GENERALTABLEFEAT");
+
+ ///
+ /// Sub-sketch definition selection.
+ ///
+ public static readonly SelectionType SubSketchDefinition = new SelectionType(154, "SUBSKETCHDEF");
+
+ ///
+ /// Object group selection.
+ ///
+ public static readonly SelectionType ObjectGroup = new SelectionType(155, "OBJGROUP");
+
+ ///
+ /// Swift schema selection.
+ ///
+ public static readonly SelectionType SwiftSchema = new SelectionType(159, "SWIFTSCHEMA");
+
+ ///
+ /// Title block selection.
+ ///
+ public static readonly SelectionType TitleBlock = new SelectionType(192, "TITLEBLOCK");
+
+ ///
+ /// Title block table feature selection.
+ ///
+ public static readonly SelectionType TitleBlockTableFeature = new SelectionType(206, "TITLEBLOCKTABLEFEAT");
+
+ ///
+ /// Cosmetic weld selection.
+ ///
+ public static readonly SelectionType CosmeticWeld = new SelectionType(220, "COSMETICWELDS");
+
+ ///
+ /// Magnetic line selection.
+ ///
+ public static readonly SelectionType MagneticLine = new SelectionType(225, "MAGNETICLINES");
+
+ ///
+ /// Punch table feature selection.
+ ///
+ public static readonly SelectionType PunchTableFeature = new SelectionType(234, "PUNCHTABLE");
+
+ ///
+ /// Revision cloud selection.
+ ///
+ public static readonly SelectionType RevisionCloud = new SelectionType(240, string.Empty);
+
+ ///
+ /// Selection set folder selection.
+ ///
+ public static readonly SelectionType SelectionSetFolder = new SelectionType(258, "SELECTIONSETFOLDER");
+
+ ///
+ /// Selection set node selection.
+ ///
+ public static readonly SelectionType SelectionSetNode = new SelectionType(259, "SUBSELECTIONSETNODE");
+
+ ///
+ /// Graphics body selection.
+ ///
+ public static readonly SelectionType GraphicsBody = new SelectionType(262, "MESH BODY FEATURE");
+
+ ///
+ /// Facet selection.
+ ///
+ public static readonly SelectionType Facet = new SelectionType(268, "MESHFACETREF");
+
+ ///
+ /// Mesh facet edge selection.
+ ///
+ public static readonly SelectionType MeshFacetEdge = new SelectionType(269, "MESHFINREF");
+
+ ///
+ /// Mesh facet vertex selection.
+ ///
+ public static readonly SelectionType MeshFacetVertex = new SelectionType(270, "MESHVERTEXREF");
+
+ ///
+ /// Mesh solid body selection.
+ ///
+ public static readonly SelectionType MeshSolidBody = new SelectionType(274, "MSOLIDBODY");
+
+ ///
+ /// Belt chain feature selection.
+ ///
+ public static readonly SelectionType BeltChainFeature = new SelectionType(149, "SKETCHBELT");
+
+ ///
+ /// Advanced structure member selection.
+ ///
+ public static readonly SelectionType AdvStructMember = new SelectionType(295, "ADVSTRUCTMEMBER");
+
+ ///
+ /// Everything selection.
+ ///
+ public static readonly SelectionType Everything = new SelectionType(-3, "EVERYTHING");
+
+ ///
+ /// Location selection.
+ ///
+ public static readonly SelectionType Location = new SelectionType(-2, "LOCATIONS");
+
+ ///
+ /// Unsupported selection.
+ ///
+ public static readonly SelectionType Unsupported = new SelectionType(-1, "UNSUPPORTED");
+
+ #endregion
+
+ private readonly int _intValue;
+ private readonly string _stringValue;
+ private readonly string[] _customFeatureNames;
+
+ ///
+ /// Internal constructor for predefined selection types.
+ /// Initializes a new with the specified integer and string values.
+ ///
+ /// The numeric identifier for the selection type.
+ /// The string representation used in the SOLIDWORKS API.
+ ///
+ /// Custom feature types should use instead.
+ ///
+ internal SelectionType(int intValue, string stringValue)
+ {
+ _intValue = intValue;
+ _stringValue = stringValue;
+ _customFeatureNames = null;
+ }
+
+ ///
+ /// Internal constructor for custom feature selection types.
+ /// Initializes a new with custom feature names.
+ ///
+ /// An array of custom feature names.
+ ///
+ /// This constructor is used for user-defined selection types not covered by the standard enum.
+ /// The integer value is set to as a default for custom types.
+ ///
+ internal SelectionType(SelectionType baseType, string[] customFeatureNames)
+ {
+ _intValue = baseType;
+ _stringValue = baseType;
+ _customFeatureNames = customFeatureNames;
+ }
+
+ ///
+ /// Creates a new for a single custom feature.
+ ///
+ /// The name of the custom feature.
+ /// A new instance.
+ ///
+ /// var weldBeadType = SelectionType.CreateCustomFeatureType("MyAwesomeFeature");
+ ///
+ ///
+ /// Can be used with
+ ///
+ public static SelectionType CreateCustomFeatureType(SelectionType baseType, string featureName)
+ => new SelectionType(baseType, new[] { featureName });
+
+ ///
+ /// Creates a new for multiple custom features.
+ ///
+ /// An array of custom feature names.
+ /// A new instance.
+ ///
+ /// var customTypes = SelectionType.CreateCustomFeatureType(new[] { "MyAwesomeFeature1", "MyAwesomeFeature2" });
+ ///
+ ///
+ /// Can be used with
+ ///
+ public static SelectionType CreateCustomFeatureType(SelectionType baseType, string[] featureNames)
+ => new SelectionType(baseType, featureNames);
+
+ ///
+ /// Gets a semicolon-separated string of custom feature names (if applicable).
+ ///
+ ///
+ /// A combined string of custom feature names, or if this is not a custom type.
+ ///
+ ///
+ /// Used internally for SOLIDWORKS API calls that require multiple selection identifiers.
+ ///
+ internal string GetCustomFeaturesSelection()
+ => _customFeatureNames is null ? string.Empty : string.Join(";", _customFeatureNames);
+
+ ///
+ /// Implicitly converts a to its integer value.
+ ///
+ /// The to convert.
+ /// The underlying integer value.
+ ///
+ /// Allows seamless use of where an integer is expected (e.g., API calls).
+ ///
+ public static implicit operator int(SelectionType selectionType)
+ {
+ return selectionType._intValue;
+ }
+
+ ///
+ /// Implicitly converts a to its string representation.
+ ///
+ /// The to convert.
+ ///
+ /// The underlying string value, or for custom types.
+ ///
+ ///
+ /// Allows seamless use of where a string is expected (e.g., API calls).
+ ///
+ public static implicit operator string(SelectionType selectionType)
+ {
+ return selectionType._stringValue;
+ }
+
+ ///
+ /// Determines whether the specified object is equal to the current SelectionType.
+ ///
+ /// The object to compare with the current object
+ /// true if the objects are considered equal; otherwise, false
+ public override bool Equals(object obj)
+ {
+ // Null and type check
+ if (obj == null || GetType() != obj.GetType())
+ return false;
+
+ var other = (SelectionType)obj;
+
+ // Compare primitive values first for early exit
+ if (_intValue != other._intValue)
+ return false;
+
+ // String comparison for _stringValue not used it depends on _intValue
+
+ // Handle null cases for custom feature names
+ if (_customFeatureNames == null || other._customFeatureNames == null)
+ return _customFeatureNames == null && other._customFeatureNames == null;
+
+ // Compare array lengths first for quick mismatch detection
+ if (_customFeatureNames.Length != other._customFeatureNames.Length)
+ return false;
+
+ // Element-by-element comparison
+ for (var i = 0; i < _customFeatureNames.Length; i++)
+ {
+ if (!string.Equals(_customFeatureNames[i], other._customFeatureNames[i], StringComparison.Ordinal))
+ return false;
+ }
+
+ return true;
+ }
+
+ ///
+ /// Serves as the default hash function for SelectionType.
+ ///
+ /// A hash code for the current object
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ if (_customFeatureNames is null)
+ {
+ // Handless only _intValue if no custom features, _stringValue check not needed
+ return _intValue.GetHashCode();
+ }
+ else
+ {
+ // Handless _intValue and custom features array if has custom features, _stringValue check not needed
+ var hashCode = 0;
+ for (var i = 0; i < _customFeatureNames.Length; i++)
+ {
+ hashCode += _customFeatureNames[i].GetHashCode() * 17;
+ }
+ hashCode += _intValue.GetHashCode();
+ return hashCode;
+ }
+ }
+ }
+ }
+}
diff --git a/Tutorials/09-CommandItems/SolidDna.CommandItems/CommandItems.cs b/Tutorials/09-CommandItems/SolidDna.CommandItems/CommandItems.cs
index 40718e6..4980e76 100644
--- a/Tutorials/09-CommandItems/SolidDna.CommandItems/CommandItems.cs
+++ b/Tutorials/09-CommandItems/SolidDna.CommandItems/CommandItems.cs
@@ -1,6 +1,10 @@
using CADBooster.SolidDna;
+using SolidWorks.Interop.sldworks;
+using SolidWorks.Interop.swconst;
+using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using static CADBooster.SolidDna.SolidWorksEnvironment;
@@ -102,89 +106,170 @@ private void CreateMenus()
title: "CreateCommandMenu Example",
id: 150_001,
commandManagerItems: CreateCommandItems());
- }
- ///
- /// Create a list of command items for a toolbar, Tools menu and a flyout. Create this list for each menu so its IDs are unique.
- ///
- public List CreateCommandItems() =>
- new List
- {
- new CommandManagerItem
- {
- Name = "DeselectedDisabled item",
- Tooltip = "DeselectedDisabled item Tooltip",
- ImageIndex = 0,
- Hint = "DeselectedDisabled item Hint",
- VisibleForDrawings = true,
- VisibleForAssemblies = true,
- VisibleForParts = true,
- OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab DeselectedDisabled item clicked!"),
- OnStateCheck = (args) => args.Result = CommandManagerItemState.DeselectedDisabled
- },
- new CommandManagerItem
- {
- Name = "DeselectedEnabled item",
- Tooltip = "DeselectedEnabled item Tooltip",
- ImageIndex = 1,
- Hint = "DeselectedEnabled item Hint",
- VisibleForDrawings = true,
- VisibleForAssemblies = true,
- VisibleForParts = true,
- OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab DeselectedEnabled item clicked!"),
- OnStateCheck = (args) => args.Result = CommandManagerItemState.DeselectedEnabled
- },
+ Action onContextMenuItemClick = () => System.Windows.MessageBox.Show("Context menu item clicked");
- new CommandManagerItem
- {
- Name = "SelectedDisabled item",
- Tooltip = "SelectedDisabled item Tooltip",
- ImageIndex = 2,
- Hint = "SelectedDisabled item Hint",
- VisibleForDrawings = true,
- VisibleForAssemblies = true,
- VisibleForParts = true,
- OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab SelectedDisabled item clicked!"),
- OnStateCheck = (args) => args.Result = CommandManagerItemState.SelectedDisabled
- },
- new CommandManagerItem
+ Application.CommandManager.CreateContextMenuItems(
+ [
+ new CommandContextIcon
{
- Name = "SelectedEnabled item",
- Tooltip = "SelectedEnabled item Tooltip",
- ImageIndex = 0,
- Hint = "SelectedEnabled item Hint",
- VisibleForDrawings = true,
- VisibleForAssemblies = true,
- VisibleForParts = true,
- OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab SelectedEnabled item clicked!"),
- OnStateCheck = (args) => args.Result = CommandManagerItemState.SelectedEnabled
+ Hint = "Icon Hint",
+ OnClick = () => System.Windows.MessageBox.Show("Context icon clicked"),
+ OnStateCheck = args => args.Result = CommandManagerItemState.DeselectedEnabled,
+ // Example only. Use indexed single icon instead.
+ Icon = imageFormat,
+ SelectionType = SelectionType.InContextFeatures
},
- new CommandManagerItem
+ new CommandContextItem
{
- Name = "Hidden item",
- Tooltip = "Hidden item Tooltip",
- ImageIndex = 1,
- Hint = "Hidden item Hint",
- VisibleForDrawings = true,
- VisibleForAssemblies = true,
- VisibleForParts = true,
- OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab Hidden item clicked!"),
- OnStateCheck = (args) => args.Result = CommandManagerItemState.Hidden
+ Name = "RootItem",
+ Hint = "RootItem Hint",
+ OnClick = onContextMenuItemClick,
+ OnStateCheck = args => args.Result = CommandManagerItemState.SelectedEnabled,
+ SelectionType = SelectionType.Component
},
- new CommandManagerItem
+ new CommandContextMenuGroup
{
- Name = "Toggle item",
- Tooltip = "Toggle item Tooltip",
- ImageIndex = 2,
- Hint = "Toggle item Hint",
- VisibleForDrawings = true,
- VisibleForAssemblies = true,
- VisibleForParts = true,
- OnClick = () => mToggle = !mToggle,
- OnStateCheck = (args) =>
- args.Result = mToggle ? CommandManagerItemState.SelectedEnabled : CommandManagerItemState.DeselectedEnabled
+ Name = "RootGroup",
+ Items =
+ [..
+ CreateCommandItems().AsCommandCreatable(x => SelectionType.Component),
+ new CommandContextItem
+ {
+ Name = "PlaneItem",
+ Hint = "PlaneItem Hint",
+ OnClick = onContextMenuItemClick,
+ SelectionType = SelectionType.DatumPlane
+ },
+ new CommandContextMenuGroup
+ {
+ Name = "SubGroup",
+ Items =
+ [
+ new CommandContextItem
+ {
+ Name = "SubSubItem",
+ Hint = "SubSubItem Hint",
+ OnClick = onContextMenuItemClick,
+ SelectionType = SelectionType.Component
+ },
+ new CommandContextMenuGroup
+ {
+ Name = "SubSubGroup",
+ Items =
+ [
+ new CommandContextItem
+ {
+ Name = "SubSubSubItem",
+ Hint = "SubSubSubItem Hint",
+ OnClick = onContextMenuItemClick,
+ SelectionType = SelectionType.Component
+ }
+ ]
+ },
+ ]
+ }
+ ]
}
- };
+ ]);
+ }
+
+ ///
+ /// Create a list of command items for a toolbar, Tools menu and a flyout. Create this list for each menu so its IDs are unique.
+ ///
+ public List CreateCommandItems() =>
+ [
+ // We cant hide item in ToolBar by document type, but it can be disabled manually
+ new CommandManagerItem
+ {
+ Name = "Item for assembly",
+ Tooltip = "Item tool tip",
+ ImageIndex = 0,
+ Hint = "Item disabled in tool bar by active dock type (Assembly)",
+ VisibleForDrawings = false,
+ VisibleForAssemblies = false,
+ VisibleForParts = false,
+ OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab DeselectedDisabled item clicked!"),
+ OnStateCheck = (args) =>
+ {
+ if(Application.ActiveModel?.IsAssembly is true)
+ args.Result = CommandManagerItemState.DeselectedDisabled;
+ }
+ },
+ new CommandManagerItem
+ {
+ Name = "DeselectedDisabled item",
+ Tooltip = "DeselectedDisabled item Tooltip",
+ ImageIndex = 0,
+ Hint = "DeselectedDisabled item Hint",
+ VisibleForDrawings = true,
+ VisibleForAssemblies = true,
+ VisibleForParts = true,
+ OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab DeselectedDisabled item clicked!"),
+ OnStateCheck = (args) => args.Result = CommandManagerItemState.DeselectedDisabled
+ },
+ new CommandManagerItem
+ {
+ Name = "DeselectedEnabled item",
+ Tooltip = "DeselectedEnabled item Tooltip",
+ ImageIndex = 1,
+ Hint = "DeselectedEnabled item Hint",
+ VisibleForDrawings = true,
+ VisibleForAssemblies = true,
+ VisibleForParts = true,
+ OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab DeselectedEnabled item clicked!"),
+ OnStateCheck = (args) => args.Result = CommandManagerItemState.DeselectedEnabled
+ },
+ new CommandManagerItem
+ {
+ Name = "SelectedDisabled item",
+ Tooltip = "SelectedDisabled item Tooltip",
+ ImageIndex = 2,
+ Hint = "SelectedDisabled item Hint",
+ VisibleForDrawings = true,
+ VisibleForAssemblies = true,
+ VisibleForParts = true,
+ OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab SelectedDisabled item clicked!"),
+ OnStateCheck = (args) => args.Result = CommandManagerItemState.SelectedDisabled
+ },
+ new CommandManagerItem
+ {
+ Name = "SelectedEnabled item",
+ Tooltip = "SelectedEnabled item Tooltip",
+ ImageIndex = 0,
+ Hint = "SelectedEnabled item Hint",
+ VisibleForDrawings = true,
+ VisibleForAssemblies = true,
+ VisibleForParts = true,
+ OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab SelectedEnabled item clicked!"),
+ OnStateCheck = (args) => args.Result = CommandManagerItemState.SelectedEnabled
+ },
+ new CommandManagerItem
+ {
+ Name = "Hidden item",
+ Tooltip = "Hidden item Tooltip",
+ ImageIndex = 1,
+ Hint = "Hidden item Hint",
+ VisibleForDrawings = true,
+ VisibleForAssemblies = true,
+ VisibleForParts = true,
+ OnClick = () => System.Windows.MessageBox.Show("CreateCommandTab Hidden item clicked!"),
+ OnStateCheck = (args) => args.Result = CommandManagerItemState.Hidden
+ },
+ new CommandManagerItem
+ {
+ Name = "Toggle item",
+ Tooltip = "Toggle item Tooltip",
+ ImageIndex = 2,
+ Hint = "Toggle item Hint",
+ VisibleForDrawings = true,
+ VisibleForAssemblies = true,
+ VisibleForParts = true,
+ OnClick = () => mToggle = !mToggle,
+ OnStateCheck = (args) =>
+ args.Result = mToggle ? CommandManagerItemState.SelectedEnabled : CommandManagerItemState.DeselectedEnabled
+ }
+ ];
///
/// Create a list of command items for a toolbar. A toolbar can hold normal items (buttons), flyouts and separators, all of which implement ICommandManagerItem.
diff --git a/Tutorials/09-CommandItems/SolidDna.CommandItems/SolidDna.CommandItems.csproj b/Tutorials/09-CommandItems/SolidDna.CommandItems/SolidDna.CommandItems.csproj
index 3967c75..c0be980 100644
--- a/Tutorials/09-CommandItems/SolidDna.CommandItems/SolidDna.CommandItems.csproj
+++ b/Tutorials/09-CommandItems/SolidDna.CommandItems/SolidDna.CommandItems.csproj
@@ -3,6 +3,7 @@
net48-windows
Library
false
+ latest
true
@@ -30,4 +31,7 @@
+
+
+
\ No newline at end of file