Component Name linked Sketch Text

Component Name linked Sketch Text

troyostrander
Advocate Advocate
2,323 Views
5 Replies
Message 1 of 6

Component Name linked Sketch Text

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. 

 

Screenshot 2021-03-14 at 07.58.27.png

0 Likes
Accepted solutions (1)
2,324 Views
5 Replies
Replies (5)
Message 2 of 6

troyostrander
Advocate
Advocate

Is this even possible through the API?

0 Likes
Message 3 of 6

MichaelT_123
Advisor
Advisor

Hi TroyoStrander,

I think a naming component after a tag defined via the sketch text is possible.

Try the following method (just from the process visualization only, so it is not proven!)

Steps:

  • Create the said component
  • In the component, create a sketch with the predefined, specific name (e.g. “compTag_X”)
  • In the sketch, place a text with the required component name
  • Iterate the design finding all sketches with names starting with  “compTag_”
  • Find in each tagSketch its parent component tagComp=tagSketch.parentComponent
  • Find in each tagSketch respective tagText= tagSketch.sketchTexts.item(0).text
  • Rename a component parenting tagSketch     tagComp.name=tagText
  • Check the results

If the process is successful … enjoy the rest of the day 😊

 

Note:

The process can be 'reversed' so the tagText can be updated after the component's name.

 

Regards

MichaelT

MichaelT
Message 4 of 6

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
Message 5 of 6

troyostrander
Advocate
Advocate

Here is an update with a demo video.  See attached.  Thank again to @BrianEkins 

 

 

Message 6 of 6

drew.porter
Contributor
Contributor
Hi @BrianEkins

I love this script, but I want to be able to run it with a button. I am very new to the API and don't know how to make it into a button. Could you convert it to an add in?

Thanks!
0 Likes