Cannot add an extrudeFeature to activeSelections

Cannot add an extrudeFeature to activeSelections

chevyhou0117
Explorer Explorer
305 Views
2 Replies
Message 1 of 3

Cannot add an extrudeFeature to activeSelections

chevyhou0117
Explorer
Explorer

I got a "Invalid Argument Entity" Error on:

ui.activeSelections.add(occurrence.component.features.extrudeFeatures.item(0)) 
 
But it can successfully run if the code is:
extrude_feature = selectionInput.selection(0).entity #I selected the same extrudeFeature
ui.activeSelections.add(extrude_feature)
 
It seems like the selected feature and the original feature is different... Is there anyone know the reason? Thank you very much!
0 Likes
Accepted solutions (1)
306 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @chevyhou0117 -San.

 

This is a Proxy issue when dealing with component elements.

# 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
        root: fusion.Component = des.rootComponent

        occurrence: fusion.Occurrence = root.allOccurrences[0]

        extrudeFeature: fusion.ExtrudeFeature = occurrence.component.features.extrudeFeatures.item(0)

        # error
        # ui.activeSelections.add(extrudeFeature)

        # ok
        extrudeFeature_proxy: fusion.ExtrudeFeature = extrudeFeature.createForAssemblyContext(
            occurrence
        )
        ui.activeSelections.add(extrudeFeature_proxy)

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

 

See "Proxies" in this document.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A 

Message 3 of 3

chevyhou0117
Explorer
Explorer

Thank you so much, @kandennti -San.

0 Likes