Button for Sketch.ShowUnderConstrained

Button for Sketch.ShowUnderConstrained

christopher_hermansson
Contributor Contributor
1,225 Views
10 Replies
Message 1 of 11

Button for Sketch.ShowUnderConstrained

christopher_hermansson
Contributor
Contributor

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?

0 Likes
Accepted solutions (1)
1,226 Views
10 Replies
Replies (10)
Message 2 of 11

kandennti
Mentor
Mentor

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

 

0 Likes
Message 3 of 11

kandennti
Mentor
Mentor

@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

0 Likes
Message 4 of 11

christopher_hermansson
Contributor
Contributor

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 11

kandennti
Mentor
Mentor
Accepted solution

@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.

0 Likes
Message 6 of 11

christopher_hermansson
Contributor
Contributor
Fantastic!
Message 7 of 11

kandennti
Mentor
Mentor

@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.

0 Likes
Message 8 of 11

Christoph_360
Advisor
Advisor

Hello

 


@christopher_hermansson wrote:

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.


I think it's a shame that such an important command is not offered in the Sketcher. I had a lot of fun with the Sketcher from the beginning, but I was always afraid of finding a missing Constrain. It was just too much of a relief when I found the command "Sketch.ShowUnderConstrained" in the Forum.

 

Christoph

Thanks

0 Likes
Message 9 of 11

toffypops
Enthusiast
Enthusiast

there is no ZIP file for download at https://github.com/kantoku-code/Fusion360_SketchToolPlus 

0 Likes
Message 10 of 11

kandennti
Mentor
Mentor

Hi @toffypops -san.

Click on the green “Code” to display.

kandennti_0-1749215255437.png

 

Enjoy!

Message 11 of 11

MichaelT_123
Advisor
Advisor

Kandennti-San : Chat-GPT  --> 1:0

MichaelT
0 Likes