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: 

Button for Sketch.ShowUnderConstrained

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
christopher_hermansson
463 Views, 6 Replies

Button for Sketch.ShowUnderConstrained

Hi! I want to make an add-in that places a button on the sketch toolbar that runs the command Sketch.ShowUnderConstrained when clicked. I've been trying for several hours, with the help of Chat-GPT, with no real success. Is it even possible?

6 REPLIES 6
Message 2 of 7

Hi @christopher_hermansson -San.

 

The following sample switches between Driving/Driven dimensions.
It should be performed in the edit state of the sketch.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct

        skt: fusion.Sketch = fusion.Sketch.cast(des.activeEditObject)
        if not skt: return

        dim : fusion.SketchDimension = None
        for dim in skt.sketchDimensions:
            dim.isDriving = not dim.isDriving

        ui.messageBox("Done")

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

1.png

 

Message 3 of 7
kandennti
in reply to: kandennti

@christopher_hermansson -San.

 

Sorry, I made a mistake.

In the following sample, you can toggle the "Show Constraints" on the screen.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct

        skt: fusion.Sketch = fusion.Sketch.cast(des.activeEditObject)
        if not skt: return

        skt.areConstraintsShown = not skt.areConstraintsShown

        ui.messageBox("Done")

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

 

However, the Sketch Palette check was not linked.

1.png

 


Therefore, I modified it and used the text command.

・・・
        # skt.areConstraintsShown = not skt.areConstraintsShown
        txtCmd = u'Commands.SetBool show_constraints {}'.format(
            0 if skt.areConstraintsShown else 1
        )
        app.executeTextCommand(txtCmd)
・・・

1.png

Message 4 of 7

Thank you, but that wasn't really what I was asking about. There is a text command "Sketch.ShowUnderConstrained" that you can type into the text command prompt. I just want to add a button to the toolbar that executes that command.

Message 5 of 7

@christopher_hermansson -San.

 

Sorry, I misunderstood again.

The only way to add a button to the menu is to create an add-in.

 

We do not use that text command, but we have created an add-in that does something similar.

https://github.com/kantoku-code/Fusion360_SketchToolPlus 

There are several commands, but the "SketchAnalysis" command does the same thing.


However, they are all displayed in Japanese. If necessary, we will modify it so that it can be displayed in English as well.

Message 6 of 7

Fantastic!
Message 7 of 7

@christopher_hermansson -San.

 

The display has been modified to switch according to the language of preferences.

https://github.com/kantoku-code/Fusion360_SketchToolPlus 

 

Some words may not be appropriate due to the use of a translation site.
Please let me know and I will fix it.

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

Post to forums  

Autodesk Design & Make Report