Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I am trying to create a Selection Set of a subcomponent sketch using API with `selectionSets.add()` but had no luck with it. Does anyone know how to make this method work? From the error message it seems this method requires 2 or 3 arguments instead of 1 or 2 mentioned in the documentation. Error message:
Example document structure for testing:
Code to reproduce the error:
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.activeDocument
design = doc.products.item( 0 )
for occ in design.rootComponent.occurrences:
for sketch in occ.component.sketches:
if 'XXXX' in sketch.name:
design.selectionSets.add(sketch, f'my_selection_set')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I was able to solve this problem using commands but would like to know if there is a way using API:
cmdDefs: adsk.core.CommandDefinitions = ui.commandDefinitions
cmdDef: adsk.core.CommandDefinition = cmdDefs.itemById('CreateSelectionGroupCmd')
if cmdDef:
cmdDef.execute()
Solved! Go to Solution.