selection default setting for api user command

selection default setting for api user command

adminTCYL2
Enthusiast Enthusiast
1,135 Views
8 Replies
Message 1 of 9

selection default setting for api user command

adminTCYL2
Enthusiast
Enthusiast
 I try to create a torial helix using the addIn oft Patric Rainsberry that makes a linear heilx and write some math into:
His code is open and downloadable here:
http://tapnair.github.io/HelixGenerator/
 
At the start the user has to select a plane. The relevant code is: 
        # Create the Selection input to have a planar face or construction plane selected.  
        selection_input = inputs.addSelectionInput('plane''Plane''Select sketch plane.')
        selection_input.addSelectionFilter('PlanarFaces')
        selection_input.addSelectionFilter('ConstructionPlanes')
        selection_input.setSelectionLimits(11)
 
But in an empty document in Fusion 360 there is no plane visible so the user does not know what to select.
So it would be  nice to make origins visible by code or use a standard plane so the helix appears
 
I would like to write something  like: 
if inputs.plane == 0:       # if there is no plane selected
            plane = root_comp.xYConstructionPlane
 
So the helix is done by default on the xYConstructionPlane as long as the user does not select an other plane.
But my problem is: The script stops. No command is executed as long as the user does not do a selection. 
The selection option in the user commands stops the AddIn. 
I do not understand the script good enough to solve this. 
Accepted solutions (2)
1,136 Views
8 Replies
Replies (8)
Message 2 of 9

nnikbin
Collaborator
Collaborator

@adminTCYL2 , I like you idea of making a default plane selection. I would like to know @prainsberry's opinion about your idea.

 

You can add the following code after line 105 of HelixCommand.py

 

app = adsk.core.Application.get()
design = app.activeProduct
root = design.rootComponent
selection_input.addSelection(root.xZConstructionPlane)

 

Or by using @prainsberry 's utility objects defined in Fusion360Utilities.py:

 

root = app_objects['root_comp']
selection_input.addSelection(root.xZConstructionPlane)

 

It makes a default selection but does not prevent the user from clearing the input.

 

0 Likes
Message 3 of 9

adminTCYL2
Enthusiast
Enthusiast

Thanks for your reply. I found a mail adress in the web and wrote to prainsberry, but got no answer by now. 
I am in a hurry... so I try your code tomorrow...

0 Likes
Message 4 of 9

adminTCYL2
Enthusiast
Enthusiast
Accepted solution

Thank You so much. That is just what I wanted! It looks so simple, but I could not solve it by myself!

 

0 Likes
Message 5 of 9

prainsberry
Autodesk
Autodesk

Hello, I apologize I began this reply last week but must not have hit send.  Looks like you have a good solution here.  
I can incorporate that.  
Also it should be noted that this thread spawned a completely renewed interest of mine in this app and I have begun a pretty significant overhaul :). 

 

I will probably post it as a new add-in, but wanted to let you all know and thank you for the kick of inspiration!



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 6 of 9

prainsberry
Autodesk
Autodesk

Hey @adminTCYL2 @nnikbin I made a couple changes.  I added a couple of options from the ideas above.

 

NOTE: The command was moved to the "Create" dropdown in the solid environment.

It seemed weird that I had it in sketch, since it made a new sketch anyway.

 

There are three options that can be set by opening and editing the HelixCommand.py file:

  • USE_DEFAULT_PLANE: Set this to True to automatically populate the initial selection field, default is False
  • DEFAULT_PLANE: If the above value is true this will be the default selection (in the active component)
  • SHOW_COMPONENT_ORIGIN_FOLDER: Whether the default construction entities will be shown for the active component

You can, of course, download the latest here: https://github.com/tapnair/HelixGenerator



Patrick Rainsberry
Developer Advocate, Fusion 360
Message 7 of 9

adminTCYL2
Enthusiast
Enthusiast
Accepted solution

Thank you patric, that is even better than the solution up there, because it works without a new plane. 

0 Likes
Message 8 of 9

nnikbin
Collaborator
Collaborator

@adminTCYL2 , I guess you mistakenly marked your replies as solutions. I suggest adding @prainsberry 's reply to the solutions.

0 Likes
Message 9 of 9

adminTCYL2
Enthusiast
Enthusiast

Oh, sorry...

 

0 Likes