Automatically "Set" & "Read" Fusion 360 Attributes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can anybody help?
I have the following Python code to set and read a parts attribute.....
import adsk.core
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
selectionPrompt = 'Select a component.'
selectionFilter = 'Occurrences'
selectedOccurence = ui.selectEntity(selectionPrompt, selectionFilter)
selectedComponent = selectedOccurence.entity.component
compAttributes = selectedComponent.attributes
AttributeGroupName = 'DarrensAttributes'
AttributeName = "Part: Type"
AttributeValue = "FLAME CUT PROFILE"
newAttribute = compAttributes.add(AttributeGroupName, AttributeName, AttributeValue)
# Read Attribute
readAttribute = compAttributes.itemByName(AttributeGroupName, AttributeName)
attributeValue = readAttribute.value
textString = "Attribute value for " + AttributeName + " = \n" + attributeValue
ui.messageBox(textString)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Does anybody know how to modify the code so that I do not have to physically select the component first, I want it to automatically select the component for me.
Many thanks in advance!
Kind Regards
Darren