Selection Input for Sketch

Selection Input for Sketch

Anonymous
Not applicable
1,320 Views
3 Replies
Message 1 of 4

Selection Input for Sketch

Anonymous
Not applicable

I am writing an Extrude like command called FACE (Sheet Metal feature), which takes sketch as input. Following is what I have written, but it does not select the sketch.

class FaceCommandCreatedEventHandlerPanel(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__() 
    def notify(self, args):
        try:
            cmd = args.command
            onFaceExecute = FaceCommandExecuteHandler()
            cmd.execute.add(onFaceExecute)

            onFaceInputChanged = FaceInputChangedHandler()
            cmd.inputChanged.add(onFaceInputChanged)
            
            onFaceValidateInput = FaceValidateInputHandler()
            cmd.validateInputs.add(onFaceValidateInput)
    
            # keep the handler referenced beyond this function
            handlers.append(onFaceExecute)
            handlers.append(onFaceInputChanged)
            #handlers.append(onFaceValidateInput)

            #define the inputs
            # Sketch Selection
            inputs = cmd.commandInputs
            i1 = inputs.addSelectionInput('FaceSketchSelection', 'Sketch', 'Please select an sketch') # 'PlanarSketch'
            i1.addSelectionFilter('Sketches');
        except:
            if ui:
                ui.messageBox(('Panel command created failed: {}').format(traceback.format_exc()))

 

 

Picture:

 

SketchSelectionNotWorking.png

 

What am I missing?

0 Likes
Accepted solutions (2)
1,321 Views
3 Replies
Replies (3)
Message 2 of 4

david_reaume
Autodesk
Autodesk
Accepted solution

Hi kulkarniyh12.mech,

 

Fusion does not actually support selection of a Sketch in the graphics window, only browser selection of a Sketch object is supported.  This is not entirely obvious, because normally when you think you're selecting a Sketch in the graphics window, what you're actually selecting is the Sketch profile.  If you hide the sketch profile (use context menu on the sketch object in the browser to access Hide/Show Profiles command) you'll notice you cannot directly select the Sketch in the graphics window (you can select it's curves/geometry). The API works just like the UI, so if you filter for "Sketches" you'll have to select a sketch from the browser if a Sketch object is actually what you need.

I assume however (and it's usually note wise to do so but I will anyway) that what you are really after is the Profile of the Sketch, and that is something that can be selected from the graphics window.  If my assumption is correct, then use the "Profiles" filter instead of the "Sketches" filter and you'll be on your way.

i1.addSelectionFilter('Profiles');

 

DaVeR
Message 3 of 4

Anonymous
Not applicable
Accepted solution

Use of 'Profiles' is fine with me. Your suggestion worked. Thanks a lot.

0 Likes
Message 4 of 4

yosef.ali.omar
Participant
Participant

Hi 

I doing something where I need to select a sketch, how can I use your approach 

its not clear to me as you define the cmd based on variable args in the function

not very proficient with python so excuse lack of knowledge of args 

0 Likes