Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Automatically "Set" & "Read" Fusion 360 Attributes

3 REPLIES 3
Reply
Message 1 of 4
isocam
138 Views, 3 Replies

Automatically "Set" & "Read" Fusion 360 Attributes

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

3 REPLIES 3
Message 2 of 4
Jorge_Jaramillo
in reply to: isocam

@Jorge_Jaramillo - this post is being edited to remove PII.

 

Hi,
As you can have more than one component in the design, which one you want to be selected by default?
Or do you want the root component to be selected?

Regards,
Jorge Jaramillo

Message 3 of 4
isocam
in reply to: Jorge_Jaramillo

Jorge,

 

It will always be the root component.

 

I will only run the AddIn when one component is active on screen.

 

Kind Regards

 

Darren

Message 4 of 4
Jorge_Jaramillo
in reply to: isocam

@Jorge_Jaramillo - this post is being edited to remove PII.

 

Hi @isocam ,

 

You just need to make the following change in you code:

 

    # selectionPrompt = 'Select a component.'
    # selectionFilter = 'Occurrences'
    # selectedOccurence = ui.selectEntity(selectionPrompt, selectionFilter)
    # selectedComponent = selectedOccurence.entity.component
    selectedComponent = adsk.fusion.Design.cast(app.activeProduct).rootComponent

 

Comment out the marked lines and add the last one.

 

For the script to run correctly, Fusion 360 has to be in design mode.

 

Regards,

Jorge Jaramillo

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report