Get Feature resourceFolder

Get Feature resourceFolder

thomasa88
Advocate Advocate
465 Views
2 Replies
Message 1 of 3

Get Feature resourceFolder

thomasa88
Advocate
Advocate

Is there any way to retrieve the resourceFolder for a Feature object? (Like one can do for CommandDefinition)

0 Likes
Accepted solutions (1)
466 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @thomasa88 .

 

It seems that CommandDefinition cann't be obtained from Feature name.
key : Object type name
value : Command ID
Why not create the above dictionary and get the resourceFolder in advance?
 
I made a sample to scan the feature of the timeline.
I have only checked four, but there are not many types of Features, so it should not be impossible to check all.
#Fusion360API Python script

import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

# Object type name and command ID mapping
# key-ObjectTypeName value-commandID
_featureMap = {
    'ExtrudeFeature':'Extrude',
    'RevolveFeature':'FusionRevolveEditCommand',
    'SweepFeature':'FusionSweepEditCommand',
    'LoftFeature':'FusionRevolveEditCommand'
    }

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface
        des :adsk.fusion.Design = _app.activeProduct

        oKCancelButtonType = adsk.core.MessageBoxButtonTypes.OKCancelButtonType
        noIconIconType = adsk.core.MessageBoxIconTypes.NoIconIconType
        dialogCancel = adsk.core.DialogResults.DialogCancel

        cmdDefs = _ui.commandDefinitions
        global _featureMap
        for tl in des.timeline:
            entType :str = tl.entity.objectType.split('::')[-1]

            if entType in _featureMap:
                cmdDef = cmdDefs.itemById(_featureMap[entType])
                if not cmdDef:
                    continue

                msg = 'ObjectType : {}\nResourceFolder : {}'.format(
                    entType, cmdDef.resourceFolder)

                print(msg)
                res =_ui.messageBox(msg, "", oKCancelButtonType, noIconIconType)
                if res == dialogCancel:
                    break
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

1.png

0 Likes
Message 3 of 3

thomasa88
Advocate
Advocate

Thanks, that's the way I'm ending up doing this.

0 Likes