Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drag selection with 'Edges' selection filter

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
k.kaluza
382 Views, 3 Replies

Drag selection with 'Edges' selection filter

Hello,

 

I'm trying to add 'Edges' or 'CircularEdges' selection filter to Selection Input and use it with drag selection.

What I want is to drag mouse over some component to select all of the entities that qualify for the filter (by drawing the selection rectangle), in this case all the edges or circular edges. Just like in a 'Chamfer' command.

All I can do is draw the selection rectangle and none of the seemingly qualifying entities are selected. But if I change the filter to eg. 'PlanarFaces' it seems to work.

 

I'm modifying script from this solution here: https://forums.autodesk.com/t5/fusion-360-api-and-scripts/onslection-event/td-p/9399382

 

inputs = cmd.commandInputs
i1 = inputs.addSelectionInput(_SelIpt1ID, _SelIpt1ID, _SelIpt1ID)
i1.addSelectionFilter('Edges')
i1.setSelectionLimits(0)

 

How can I solve this problem?

 

Thank you

3 REPLIES 3
Message 2 of 4
kandennti
in reply to: k.kaluza

Hi @k.kaluza .

 

If you want to make strict selection criteria, the selection filter is not enough.

Therefore, I think it is possible to set the desired conditions by using PreSelect Event and PreSelectMouseMove Event.

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-0550963a-ff63-4183-b0a7-a1bf0c99f821 

 

I made a sample to select only arc edges and sketches in PreSelect Event without using selection filter.

#Fusion360API Python script
#Author-kantoku
#Description-Select Event Sample

import adsk.core, adsk.fusion, traceback

_commandId = 'SelectionEvent'
_SelIpt1ID = 'Selectioninput1'

_handlers = []
_app = None
_ui = None


# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-E3D24F04-8576-420E-B9AD-44746A6B12EE
class PreSelectHandler(adsk.core.SelectionEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        args = adsk.core.SelectionEventArgs.cast(args)

        # Temporarily disable the entity selection
        args.isSelectable = False

        # Get entity on mouse cursor
        sel :adsk.core.Selection = args.selection
        ent = sel.entity

        # Find out if you meet the requirements of your selection
        if not hasattr(ent, 'geometry'):
            return

        if ent.geometry.objectType == 'adsk::core::Circle3D':
            # Since the condition is met, selectable
            args.isSelectable = True

class CommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            adsk.terminate()
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

# Event handler for the select event.
# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2ACFFC2F-458B-4740-93B8-CCC56638D8AA
class MySelectHandler(adsk.core.SelectionEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        eventArgs = adsk.core.SelectionEventArgs.cast(args)

        # Code to react to the event.
        _ui.messageBox('In MySelectHandler event handler.')

class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            cmd :adsk.core.Command = args.command

            onDestroy = CommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            onPreSelect = PreSelectHandler()
            cmd.preSelect.add(onPreSelect)
            _handlers.append(onPreSelect)

            onSelect = MySelectHandler()
            cmd.select.add(onSelect)
            _handlers.append(onSelect)

            inputs = cmd.commandInputs
            i1 = inputs.addSelectionInput(_SelIpt1ID, _SelIpt1ID,  _SelIpt1ID)
            i1.setSelectionLimits(0)

        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        cmdDefs = _ui.commandDefinitions

        cmdDef = cmdDefs.itemById(_commandId)
        if cmdDef:
            cmdDef.deleteMe()

        cmdDef = cmdDefs.addButtonDefinition(_commandId, _commandId, _commandId)

        onCmdCreated = CommandCreatedHandler()
        cmdDef.commandCreated.add(onCmdCreated)
        _handlers.append(onCmdCreated)
        cmdDef.execute()

        adsk.autoTerminate(False)
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

I hope it will be useful.

Message 3 of 4
k.kaluza
in reply to: kandennti

Hi @kandennti, of course it's useful. Thank you!

 

I'm still wondering why simply adding a filter to Selection Input doesn't work. Is this a bug?
After all, it works fine for selecting surfaces or sketches so why not for the edge, thus we need a workaround using another method?

Is it possible in the solution you proposed to filter out the sketches?

 

Thank you once again.

 

 

 

Message 4 of 4
kandennti
in reply to: k.kaluza

Probably a filter bug.
I haven't tried it, but this old one may not have improved.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/select-sketchconstraints-using-api/m-p/806... 

I've given up, so think about what to do with the PreSelect Event.

 

Fixed to exclude sketches.

・・・
# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-E3D24F04-8576-420E-B9AD-44746A6B12EE
class PreSelectHandler(adsk.core.SelectionEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        args = adsk.core.SelectionEventArgs.cast(args)

        # Temporarily disable the entity selection
        args.isSelectable = False

        # Get entity on mouse cursor
        sel :adsk.core.Selection = args.selection
        ent = sel.entity

        # Find out if you meet the requirements of your selection
        if hasattr(ent, 'parentSketch'): return

        if not hasattr(ent, 'geometry'): return

        if ent.geometry.objectType != 'adsk::core::Circle3D': return

        # Since the condition is met, selectable
        args.isSelectable = True
・・・

In PreSelectHandler, I think that you should narrow down until you meet the necessary conditions.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report