What is flatPattern.name ? Inconsistency with UI ?

What is flatPattern.name ? Inconsistency with UI ?

gvisca44
Advocate Advocate
1,010 Views
6 Replies
Message 1 of 7

What is flatPattern.name ? Inconsistency with UI ?

gvisca44
Advocate
Advocate

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 ?

 

 

0 Likes
Accepted solutions (1)
1,011 Views
6 Replies
Replies (6)
Message 2 of 7

BrianEkins
Mentor
Mentor

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
0 Likes
Message 3 of 7

gvisca44
Advocate
Advocate

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

 

 

0 Likes
Message 4 of 7

BrianEkins
Mentor
Mentor

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
0 Likes
Message 5 of 7

gvisca44
Advocate
Advocate

@BrianEkins - You've got me.

 

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

 

 

 

 

0 Likes
Message 6 of 7

BrianEkins
Mentor
Mentor
Accepted solution

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
0 Likes
Message 7 of 7

gvisca44
Advocate
Advocate

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.      

0 Likes