Im CAD/CAM System Autodesk Fusion 360 können Bodies, Components, Sketches etc. sichtbar oder unsichtbar gesetzt werden. Wir hatten oft den Fall, dass wir alle Sketches mit einem Befehl sichtbar bzw. unsichtbar setzen wollten. Jedoch gibt es in Fusion dafür kein direkter Befehl. Man kann zwar alle Sketches anwählen, jedoch kann man nicht alle Sketches auf einmal sichtbar oder unsichtbar setzen. Daher haben wir ein kleines Python Skript entwickelt, dass die Sichtbarkeit aller Sketches auf einmal umschaltet, d.h. von sichtbar auf unsichtbar und umgekehrt. Hier ist der Code:
#Author: (c) Hertweck Labs GmbH, Stefan Hertweck
#Description: Skript to show or hide all sketch objects
import adsk.core, adsk.fusion, traceback
_app = None
_ui = None
# Global set of event handlers to keep them referenced for the duration of the command
_handlers = []
# Global variable to define if you want to show or hide sketches
global show
# The showing and hiding of the sketches is split up in two seperate procedures (functions)
def showSketch():
try:
app = adsk.core.Application.get()
#current product
product = app.activeProduct
#current component
rootComp = product.rootComponent
#get sketches collection
sketches = rootComp.sketches
if sketches.count > 0:
#iterate through all sketches
for sketch in sketches:
sketch.isLightBulbOn = True;
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def hideSketch():
try:
app = adsk.core.Application.get()
#current product
product = app.activeProduct
#current component
rootComp = product.rootComponent
#get sketches collection
sketches = rootComp.sketches
if sketches.count > 0:
#iterate through all sketches
for sketch in sketches:
sketch.isLightBulbOn = False;
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler that reacts to any changes a user makes within the command input
class MyCommandInputChangedHandler(adsk.core.InputChangedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
global show
eventArgs = adsk.core.InputChangedEventArgs.cast(args)
inputs = eventArgs.inputs
cmdInput = eventArgs.input
if cmdInput.id == 'RadioButtons':
if inputs[0].listItems[0].isSelected == True:
show = True
else:
show = False
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler that reacts to when the command is destroyed. This terminates the script.
class MyCommandDestroyHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
global show
if show == True:
showSketch()
else:
hideSketch()
adsk.terminate()
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler that reacts when the command definition is executed i.e.,
# the command is created and an event (system notification) is raised
class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
# Get the command that was created
cmd = adsk.core.Command.cast(args.command)
# Connect to the command destroyed event
onDestroy = MyCommandDestroyHandler()
cmd.destroy.add(onDestroy)
_handlers.append(onDestroy)
# Connect to the input changed event
onInputChanged = MyCommandInputChangedHandler()
cmd.inputChanged.add(onInputChanged)
_handlers.append(onInputChanged)
inputs = cmd.commandInputs
# Define the functions of the command input
# In this case we are using radio buttons so that the user can select either show or hide all sketches
radioButtonGroup = inputs.addRadioButtonGroupCommandInput('RadioButtons', '')
radioButtonItems = radioButtonGroup.listItems
radioButtonItems.add("An", False)
radioButtonItems.add("Aus", True)
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def run(context):
try:
global _app, _ui, show
_app = adsk.core.Application.get()
_ui = _app.userInterface
show = False
# Get the existing command definition or create it if it doesn't already exist
cmdDef = _ui.commandDefinitions.itemById('cmdInputs')
if not cmdDef:
cmdDef = _ui.commandDefinitions.addButtonDefinition('cmdInputs', 'Show or Hide all Sketches', 'Dialogue to show or hide all Sketch Objects.','')
# Connect to the command created event
onCommandCreated = MyCommandCreatedHandler()
cmdDef.commandCreated.add(onCommandCreated)
_handlers.append(onCommandCreated)
cmdDef.execute()
# Prevent this module from being terminated when the script returns
# since we are waiting for event handlers to fire
adsk.autoTerminate(False)
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Zurück zur Gesamtliste aller "Einblicke":
Bei Bedarf können Sie uns gern Ihr Feedback mitteilen oder Anfragen stellen. Hier geht es zum Kontakt Formular: