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: 

What is flatPattern.name ? Inconsistency with UI ?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
gvisca44
244 Views, 6 Replies

What is flatPattern.name ? Inconsistency with UI ?

Some months ago I was excited to read that the Drawings workspace had introduced some new attributes - part namepart number & part description.  I had previously been typing these in manually to all of my part drawings - which becomes VERRRRRY tedious.  

 

Unfortunately on a Flat Pattern drawing, the part name and part number are both "Flat Pattern".  IMHO - the FP name/description should be the same as the 3D component name/description; they're the same physical thing afterall. I queried Autodesk, and apparently it was a conscious decision.

https://forums.autodesk.com/t5/fusion-360-support/request-sheet-metal-flat-pattern-part-number-and-m...


I decided that I could write a script to change a model's flatpattern objects to have the names/numbers/descriptions mirror the 3D component names/numbers/descriptions.

 

On the user interface, create sheetmetal component, create the flatpattern, activate the flatpattern and check the properties of the flatpattern.

Part Number: Flat Pattern
Part Name: Flat Pattern
Description:
etc.

 

It seems The Part Name is read only.  However, the Part Number and Description can be changed, and these changes are reflected in the drawings that use these attributes.

 

So for giggles I started with this code:

    for component in components:
        for body in component.bRepBodies:
            if body.isSheetMetal:
                #Indicates if this body represents a sheet metal folded part or not and if a flat pattern can be created.
                msg = f'Component \t "{component.name}" has sheet metal body'
                futil.log(msg, adsk.core.LogLevels.InfoLogLevel)

                if not component.flatPattern:
                    msg = f'\tNo flat pattern exists'
                    futil.log(msg, adsk.core.LogLevels.InfoLogLevel)
                else:
                    msg = f'\tFlat pattern name = "{component.flatPattern.name}"'
                    futil.log(msg, adsk.core.LogLevels.InfoLogLevel)

 

which produced:

Component 	 "0400-S001 v1" has sheet metal body
 	Flat pattern name = "FlatPattern1" 
 Component 	 "No Folds" has sheet metal body
 	Flat pattern name = "FlatPattern1" 
 Component 	 "0400-S005-0 v1" has sheet metal body
 	Flat pattern name = "FlatPattern1" 

Huh ? On the UI - the name is "Flat Pattern" - but component.flatPattern.name reveals "FlatPattern1" ?

So where/what is the UI Name/Number/Description ?

 

If I make a change to the component.flatPattern.name property - the change is accepted, and if I query the object again, I can see my change.  However, if I close the model and reopen, the changes are lost.

 

Ideas ? Thoughts ?

 

 

6 REPLIES 6
Message 2 of 7
BrianEkins
in reply to: gvisca44

I guess I can see both sides of this. The part name is the name of the component. This is always the file's name for the root component, but for other components, you can change the part name to whatever you would like. The flat pattern is also a separate component, but apparently, they've chosen to hard-code its name to "Flat Pattern". This makes sense from a UI point of view because then when you have a flat pattern active, the top node in the browser is called "Flat Pattern" to make it obvious where you're at. But it doesn't make sense from a data perspective because logically you would want to name these as you described. It's not possible to override this behavior with the API, because it has to follow the rules too.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 7
gvisca44
in reply to: BrianEkins

Thanks @BrianEkins ,

 

Not sure my question (or perhaps dismay) was clear.

 

With a 'normal' component, the UI Properties box shows me a Part Name, a Part Number and a Description. Through the API, I can change these with component.name, component.number component.description and my API changes are reflected in the UI (as one would expect ).


BUT - if my object is a Flat Pattern, the UI Properties box shoes me a Part Name (read only/hard coded), a Part Number (editable) and a Description (editable).

Through the API, I can change flatPattern.name but flatPattern.number and flatPattern.description are not yet exposed (dont understand why - but that doesnt matter...)

 

What purpose does the flatPattern.name member have - when its quite apparently not linked to the UI ?  If I change API flatPattern.name - what am I changing ? (other than some under the bonnet/hood value).

 

There seems to be either hard coding in the UI / or another hidden "name" object.

 

Now I wait in hope the API gets modified soon to expose flatPattern.number and .description

 

 

Message 4 of 7
BrianEkins
in reply to: gvisca44

What I was talking about is the UI behavior. If I have a flat pattern active, the browser changes to only show me the flat pattern component, and the top node is called "Flat Pattern", which is the name of the component. If I right-click and access the properties, I can edit everything except for the part name. That's the same behavior I'm seeing in the API, because, as I said, the API has to follow the same rules.

 

FlatPartName.png

 

And the number and description are exposed. You just need to get the FlatPatternComponent using the parentComponent property of the FlatPattern object. It has the properties to get and set those values. It also has a partNumber property, but it will fail if you try to set it. 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 7
gvisca44
in reply to: BrianEkins

@BrianEkins - You've got me.

 

Can you share the code snippet you used to change the flatPattern.number and flatPattern.description ?

 

 

 

 

Message 6 of 7
BrianEkins
in reply to: gvisca44

Here it is. I created a simple design to test it where the sheet metal part is in an occurrence in the assembly. The code will set the description and part number but fails on the last line where it tries to set the name. I've attached the design I used to test it with.

def run(context):
    app = adsk.core.Application.get()
    ui = app.userInterface
    try:
        des: adsk.fusion.Design = app.activeProduct
        root = des.rootComponent

        sheetMetalOcc = root.occurrences[0]
        SheetMetalComp = sheetMetalOcc.component
        flat = SheetMetalComp.flatPattern
        flatComp = flat.parentComponent
        flatComp.description = 'Custom Description'
        flatComp.partNumber = 'Custom Part Number'
        flatComp.name = 'Custom name'
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))  

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 7 of 7
gvisca44
in reply to: BrianEkins

Thanks @BrianEkins 

 

I hadn't fully absorbed the FlatPatternComponent object.

 

To my feeble brain, SheetMetal and FlatPattern objects (in the broad sense) seem to be somewhat of an oddity in the way they're structured in the object model.      

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