Component Name Linked to Sketch Text Input Field

Component Name Linked to Sketch Text Input Field

troyostrander
Advocate Advocate
852 Views
9 Replies
Message 1 of 10

Component Name Linked to Sketch Text Input Field

troyostrander
Advocate
Advocate

How can you make a dynamic link between component name controlled in the Fusion browser with the sketch text input field?

 

Practical Example:
The goal is post production part identification.  In a typical production we have of hundreds of similar but slightly different sized components.  For post CNC sorting it is a critical time saver that we have engraved the component name discreetly on the part.

 

ComponentNameLinkToSketchText.png

0 Likes
Accepted solutions (1)
853 Views
9 Replies
Replies (9)
Message 2 of 10

barry9UDQ6
Advocate
Advocate

Yes please!

 

I export nested sheet metal sheets, each one containing loads of loose parts that all need a part no.

And for me something that you did not mention, I need the part nos to be in single line text, not as a 3d line, so that the toolpath programming can pick it up.

And I also need annotations for my bent up parts. Text that reads 'BU 90 deg." etc.

Message 3 of 10

jeff_strater
Community Manager
Community Manager

No, today, there is no way to link component name to any input, sketch text or otherwise.  Today, this is something you will have to do manually.

 


Jeff Strater
Engineering Director
0 Likes
Message 4 of 10

troyostrander
Advocate
Advocate
Hi Jeff, Can it be done through the API?
0 Likes
Message 5 of 10

troyostrander
Advocate
Advocate

Hi Jeff, Can it be done through the API?

0 Likes
Message 7 of 10

jeff_strater
Community Manager
Community Manager

Thanks, @MichaelT_123 !


Jeff Strater
Engineering Director
0 Likes
Message 8 of 10

BrianEkins
Mentor
Mentor
Accepted solution

Here's a little script that will modify sketch text to match the name of a component.  Below is an example that contains two components.  The script looks for all components that contain a sketch named "CompName". If it finds the sketch, it modifies the first text it finds in the sketch so the string is the name of the component.  It should do this for all components in the assembly, regardless of how deep they are in the assembly structure.

 

SketchText.png

 Here's the script that does it.

import adsk.core, adsk.fusion, adsk.cam, traceback

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

        des: adsk.fusion.Design = app.activeProduct

        # Iterate over all components.
        comp: adsk.fusion.Component = None
        for comp in des.allComponents:
            # Check to see if the component has a sketch named "CompName".
            sk = comp.sketches.itemByName('CompName')
            if sk is not None:
                # Modify the text to be the component name.
                skText = sk.sketchTexts.item(0)
                skText.text = comp.name
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

It will be fairly easy to convert this to an add-in so there will be a button to execute it instead of going through the Scripts and Add-Ins dialog.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 9 of 10

troyostrander
Advocate
Advocate

Hey @barry9UDQ6, See Brian Ekins solution below. It worked in my initial test. It's like magic. Try it on yours. Do you know how to use a script? I can help if you don't. Best, @troyostrander 

0 Likes
Message 10 of 10

troyostrander
Advocate
Advocate

Here is a demo of the script in action!

 

See attached video. 

 

Thanks again Brian!

 

0 Likes