Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

How to do the window selection?

john4TMYX
Enthusiast

How to do the window selection?

john4TMYX
Enthusiast
Enthusiast

 

Hi guys,

I use Visual Studio 2022 C++ to develop a plugin for Fusion 360. I have a group of surfaces,  I need to select all the surfaces so my plugin can handle them. Does anyone know how to make a window selection? I can select any individual surface, but not all the surfaces in one selection. 

 

Thank you.

Regards

John

0 Likes
Reply
Accepted solutions (1)
419 Views
5 Replies
Replies (5)

BrianEkins
Mentor
Mentor

I did a quick test by modifying the sample delivered with Fusion called "CommandSample". In the entry.py file in the commands/Selections folder, I edited the last few lines of the command_created function to the following:

    # Create a selection input, apply filters and set the selection limits
    selection_input = inputs.addSelectionInput('selection_input', 'Surfaces', 'Select Surfaces')
    selection_input.addSelectionFilter('SurfaceBodies')
    selection_input.setSelectionLimits(1, 0)

I can now use a window to select multiple surfaces. There are two things here. First, is setting the filter to allow the selection of open bodies, and the second is setting the selection limits to not limit how many items can be selected. The argument value of 1 indicates that at least one surface must be selected. I would guess it will still work if this is zero too. The second argument of 0 is the most important, and it indicates there is no limit to the number of surfaces that can be selected.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes

john4TMYX
Enthusiast
Enthusiast

Hi Brian Ekins,

Thank you for your reply. Could you please tell me how to read all the selected entities?

 

Regards

John

 

0 Likes

BrianEkins
Mentor
Mentor

The SelectionCommandInput object has a selectionCount property that tells you how many items were selected and a selection method where you provide an index and it returns a selection. Using the selection method and going from 0 to selectionCount-1 will return all the selections. 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes

john4TMYX
Enthusiast
Enthusiast

I use c++. The entry code I use is "class MyCommandCreatedHandler : public CommandCreatedEventHandler", it is the sample codes from the web page. The codes that catch the selection event is from "MyUnSelectHandler : public SelectionEventHandler", I don't see any where I could access the SelectionCommandInput. Maybe I am wrong, but the SelectionCommandInput is the ui codes that I use to build the dialog. After I have the dialog, then I should be able to use SelectionEventArgs to read the current selections. But no where I could see any codes that I can use to read the selected entities.

0 Likes

BrianEkins
Mentor
Mentor
Accepted solution

You're correct that the SelectionCommandInput is what you create to have the ability to select available in the command dialog. The SelectionCommandInput remains available for the lifetime of the command. You can save it in a global, or get it from the list of inputs associated with the command, or there are some other cases where it's provided through a property. When the select event is fired, it provides a SselectoinEventArgs object. This object supports the activeInput property, which returns the SelectionCommandInput object the user used for the selection. This is important because a command can have more than one SelectionCommandInput. From this, you can use the selectionCount and selection functions I mentioned before.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes