No prompt for origin construction plane?

No prompt for origin construction plane?

andy.d.doyle
Observer Observer
676 Views
6 Replies
Message 1 of 7

No prompt for origin construction plane?

andy.d.doyle
Observer
Observer

Hey guys, super new to writing scripts/add-ins!

 

I've created SelectionCommandInput to choose which plane to sketch stuff on. I'd like to show the origin construction planes, but can't seem to figure it out.

 

I can choose a default construction plane just fine:

 

 

 

        # Construction pane selection
        construction_plane_input = inputs.addSelectionInput('plane', 'Construction Plane', 'Select a Construction Plane')
        construction_plane_input.addSelectionFilter(adsk.core.SelectionCommandInput.ConstructionPlanes)
        construction_plane_input.addSelection(design.rootComponent.xYConstructionPlane)

 

 

 

 

I'd like to show the origin planes (XY, XZ, YZ) as options similar to creating a new sketch. Something like this:

andyddoyle_1-1663526001375.png

 

I started going down this path, but this doesn't work at all.

 

 

 

def input_changed_handler(args: adsk.core.InputChangedEventArgs):
    # Show construction plane input as necessary
    if args.input.id == 'plane_input':
        plane_input: adsk.core.SelectionCommandInput = args.inputs.itemById('plane_input')

        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent

        # Show construction plane picker
        # THIS DID NOT WORK
        if not plane_input.selectionCount:
            input: adsk.fusion.ConstructionPlaneInput = root.constructionPlanes.createInput(design.activeOccurrence)
            root.constructionPlanes.add(input)

 

 

 

 

Any help at all would be greatly appreciated!

Thanks!

0 Likes
677 Views
6 Replies
Replies (6)
Message 2 of 7

kandennti
Mentor
Mentor

Hi @andy.d.doyle .

 

I may not have understood the question.

If you are saying that the origin is not displayed, then set the Component.isOriginFolderLightBulbOn property to True.

# Fusion360API Python script
import traceback
import adsk.fusion
import adsk.core

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        root.isOriginFolderLightBulbOn = True

        msg: str = 'Select Construction Plane'
        selFilter: str = 'ConstructionPlanes'
        sel: adsk.core.Selection = selectEnt(msg, selFilter)

        root.isOriginFolderLightBulbOn = False

        if not sel:
            return

        root.sketches.add(
            sel.entity
        )

        ui.messageBox('Done')

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


def selectEnt(
        msg: str,
        filterStr: str) -> adsk.core.Selection:

    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui: adsk.core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None


Or are you saying that input_changed_handler is not being called?

0 Likes
Message 3 of 7

andy.d.doyle
Observer
Observer

Hey! Thanks for the reply. That seems to work in the general sense, but I must be getting my event stack ordering messed up or something. I'm trying to show the origin planes when I clear the input, and then hide it when something gets selected.

However doing this in the input_changed_handler doesn't seem to be getting the behavior I'm after.

 

def input_changed_handler(args: adsk.core.InputChangedEventArgs):
    # Show construction plane input as necessary
    if args.input.id == 'plane':
        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent

        # Show/hide construction plane picker
        if (plane_input.selectionCount == 0):
            log('turning on the origin')
            root.isOriginFolderLightBulbOn = True
        else:
            log('turning off the origin')
            root.isOriginFolderLightBulbOn = False

 

 If you don't mind taking a look, I have my code up on GitHub, handlers/input_changed_handler.py 

0 Likes
Message 4 of 7

kandennti
Mentor
Mentor

@andy.d.doyle .

 

Thanks for making this public.

I would like to try it out, but I am not sure of the format of the csv file.

Could you provide a sample csv file?

0 Likes
Message 5 of 7

kandennti
Mentor
Mentor

@andy.d.doyle .

 

I understood one thing.

 

Not only do the events fire at different times, but they are limited in what they can do.

 

The CommandDefinition.commandCreated event is particularly special.
My impression is that the command itself is not created until the CommandCreated event ends.
Therefore, you are trying to have the XYPlane selected first, and that is the reason why it is not selected successfully.

 

1.png

 

If you want it to be selected when the dialog appears, then let it be selected at the time of the Command.activate event.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-eeb18ad8-6ea6-4a35-923f-c96113549704 

 

I sense other problems, but it is not immediately clear what the cause is, since it is obvious that there is a bug in the current version of SelectionCommandInput.

I am attaching only the created_handler.py with the fixes, just in case.

 

0 Likes
Message 6 of 7

kandennti
Mentor
Mentor

@andy.d.doyle .

 

I found out one more thing.

I had my doubts about not being able to reselect planes.

 

I made a few changes to your input_changed_handler and confirmed that the SelectionCommandInput is deselected when the isOriginFolderLightBulbOn property is changed.

1.png

 

Perhaps this is a specification of the Fusion360 API. It should not have been allowed to manipulate the document within the event handler.
So unfortunately, the processing you want is not possible.

 

I have attached the input_changed_handler.py I used for confirmation, just in case.
You do not need to provide the csv file.

 

0 Likes
Message 7 of 7

pieterparker60
Community Visitor
Community Visitor

This is a great information, really helpful. I recently made a plane by using powerful construction tools from valveswood.com.

0 Likes