-
Notifications
You must be signed in to change notification settings - Fork 27
Custom ContextMenu commands #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
Cool I'm all for a selectable object enum, shall we call it SelectableObjectType? Because solidworks does lots of things with selectable objects in the API and I'd like to teach others what item types are selectable and which ones are not. Let's not make any breaking changes, so let's introduce a new enum and mark methods that use the old one obsolete. Please make it a separate PR. Selection needs more work, see #17. In my common code, I have a Select and a GetSelected class and that works well. I don't know how well that translates to DNA. I see it already has a SelectedObject class, we should probably use that in GetSelected. |
|
"SelectableObjectType" is a good name. But I have an idea about using a complicated type object: a combined enum value and string value, because sometimes SW wants a string implementation of type identifier. If I understood you correctly, you want to find a way to determine which objects user can select and which not, and do it at compile time. As a first idea, I could suggest using a marker interface "ISelectableObject" in all selectable SolidDnaObject (add interface to each derived object). It is not the best practice I think, but it's just an idea. I'll check the current implementation of SelectionManager. It uses the SolidDna approach, enumerating through items by user's selector (Action<>), and after each iteration it disposes the item. About this approach I have two questions:
About the new PR: Did I misunderstand the order of work? Should I leave this PR for some time, then create a new one, add the new enum, wait until it is merged, then return to this PR? Is that correct? |
|
I think I misunderstood you. You want to use reflection to get the string value? Are you sure this is a good way? I think it might cause performance issues in some scenarios. Maybe we can just use the "AsString" extension method with a switch inside? It's not a perfect solution, but it won't cause any problems. |
|
The DescriptionAttribute doesn't use reflection: But indeed, my method to get it from the enum does, GetCustomAttributes uses reflection. I'll check if there is a way to avoid reflection, I may already have found one but I want to do some benchmarking. Generally, nothing we do in our code is meaningfully slow since a single rebuild can take seconds, but that doesn't mean we should become sloppy. |
|
Yes, that's exactly what I mean. In this solution, we have a lot of method calls to get a string, which is just a static value. For example, if a user calls the Description extension while iterating through some loop, it might take longer than a hard-coded alternative (a switch or a composite type). Yes, this is just a potential situation, but in my opinion, it's a good practice to avoid these risks. |
|
|
|
I implemented SelectionType by myself. I thought about enum implementation, but there are user custom feature types, and I decided to implement it as a union type with int, string, and custom names values. |
It took me a while to figure out why those custom feature types are there, but I see now that those are necessary for the command manager. I'll attempt to understand this PR later. Right now, it changes the language version, adds the iterator approach, adds selection types and renames/moves files just as side effects. I guess moving files is not a breaking change since we use a single namespace, so that's not too bad. |
That said, upgrading the language version and enabling nullability support is a good practice - I always do it for my add-ins (SolidWorks and other CAD systems) and have no problem with that. However, I’m unsure about the implications of applying this change to the library itself. It’s worth considering, but we should evaluate potential consequences first. |



I'd like to propose adding support for custom context menu commands in SolidDna. I've implemented a working solution that allows users to extend the context menu with their own commands.
Implementation Overview
Current Limitations
Next Steps
If this implementation approach is acceptable, I can:
Would appreciate feedback on the current implementation and which enum migration path would be preferred.
