Is there a script to push the Part Name to the Description?

Is there a script to push the Part Name to the Description?

tookemtoni
Collaborator Collaborator
558 Views
3 Replies
Message 1 of 4

Is there a script to push the Part Name to the Description?

tookemtoni
Collaborator
Collaborator

Is there a script to push the Part Name to the Description?

 

msedge_0U40a5EKln.png

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

tookemtoni
Collaborator
Collaborator

I got this work but only for one component at a time.  I would to this to work on multiple selections...Is that possible?

 

import adsk.core
import adsk.fusion
import traceback

def run(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = app.activeProduct

        # Get the active selection in Fusion 360
        selections = ui.activeSelections

        if selections.count == 0:
            ui.messageBox("No components selected. Please select one or more components.")
            return

        for selection in selections:
            if isinstance(selection.entity, adsk.fusion.Occurrence):
                component = selection.entity
                part_name = component.name

                # Update the Description to match the Part Name
                component.component.description = part_name

        ui.messageBox("Updated the Description for selected components.")

    except:
        if ui:
            ui.messageBox("Error: " + traceback.format_exc())

if __name__ == "__main__":
    run(None)

 

 

0 Likes
Message 3 of 4

kandennti
Mentor
Mentor
Accepted solution

Hi @tookemtoni .

 

Try this.

# 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

        comp: fusion.Component = None
        for comp in des.allComponents:
            comp.description = comp.name

        ui.messageBox("Done")

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 4 of 4

tookemtoni
Collaborator
Collaborator

@kandennti Done.... Thank you!