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?
Solved! Go to Solution.
Solved by kandennti. Go to Solution.
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()))
@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.
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)
・・・
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.
@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.
@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.