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: 

Appearance Assign

8 REPLIES 8
Reply
Message 1 of 9
MichaelT_123
263 Views, 8 Replies

Appearance Assign

Hi TF360,

I have a script which applies different (custom) appearances to the same material. It is soo basic that I will not attach it. One critical code line is stated below. F360 kernel issues the warning message

"Appearance can't be deleted because it is linked with an applied Physical Material: Steel. To delete the appearance, first unassign and delete this material from the Physical Material command".

It is not only one message but a stream of them accumulating in the warning queue (depending on how many assigned operations the script attempted to perform).

 

So there is a couple of issues here:

  • Why issue the subsequent frivolous dialogues with the warning when the previous one hasn't been cleared up? Tens of such dialogues can accumulate on the screen, requiring laborious mouse clicking to clear them up.
  • Why issue an exhibitionist type of warning in the form of the interactive screen dialogue even if the F360 is run via a script, which so far does not have the ability to click the mouse button?
  • What is the logic behind such a warning? It is legal to add appearance to the Design. appearancesDesign.addByCopy(thisAppear, newAppearName).
  • By the logic? presented in the warning message, once added (addByCopy()), such custom appearance can not be deleted …. without deleting associated material. In this case, there is only one design material, Steel … which obviously can not be deleted!
  • Why is there a restriction on applying different appearances to the same material (without creating its dummy copy)? A simple real-world example would be Steel material at different temperatures affecting its 'hue'. The current F360 model is, in this regard … unreasonably cumbersome and heavy.

If I can recall, the situation is the recent one, as in the past (I don't know exactly when) I haven't experienced such problems. Is there a new elephant in a room full of china … without capable Mahout?

 

Regards

MichaelT

MichaelT
Tags (2)
8 REPLIES 8
Message 2 of 9
BrianEkins
in reply to: MichaelT_123

I'm not seeing the problem you describe when deleting the appearance. However, I'm seeing another problem that when I create a new appearance by copying one, that I don't see that appearance in the Appearance dialog. Also, the count of the Appearances collection doesn't always increment. So, there do seem to be some issues with appearances.

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

Hi Mr Ekins,

 

I hope that ... all Appearances Problems will be addressed as soon as possible.

 

Regards

MichaelT

 

MichaelT
Message 4 of 9
BrianEkins
in reply to: MichaelT_123

@MichaelT_123 Can you post your code here? I said that I found some problems, but I was experimenting in the TEXT COMMAND window, and then when I tried to create a script to reproduce the problem, I no longer can. Everything I've tried so far works as expected. You're probably doing something a little different or the file you're testing in has something mine doesn't.

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

Hi Mr Ekins,

 

Here is the code I think is suspicious, I have not tested it separately!.It is only snippet from a larger body of code.

            appearNew       = appearancesDesign.itemByName( appearNew_Name )        # Check if appearNew_Name is in appearancesDesign
            if  appearNew is None:                                                  # Add respectibe color appearance
                appearBase  = appearancesFavor.itemByName( 'Black_Reflective' )     # Based on 'Chrome'
                appearNew   = appearancesDesign.addByCopy( appearBase, appearNew_Name )
            colorProp       = appearNew.appearanceProperties.itemById( 'metal_f0' )
            colorValue      = colorProp.value
            colorResult     = colorValue.setColor( rgbColor[0], rgbColor[1], rgbColor[2],  rgbColor[3] )
            colorProp.value = colorValue  

Regards

MichaelT

MichaelT
Message 6 of 9
BrianEkins
in reply to: MichaelT_123

Here's a small script that does the typical workflow and works as expected for me. I also tried copying the appearance from favorites, as your original code does, which also worked. Does this work for you?

 

def run(context):
    app: adsk.core.Application = adsk.core.Application.get()
    ui = app.userInterface
    try:
        des: adsk.fusion.Design = app.activeProduct
        appearNew_Name = 'NewAppearance'
        appearancesDesign = des.appearances
        library = app.materialLibraries.itemByName('Fusion 360 Appearance Library')
        appearNew       = appearancesDesign.itemByName( appearNew_Name )        # Check if appearNew_Name is in appearancesDesign
        if  appearNew is None:                                                  # Add respectibe color appearance
            appearBase  = library.appearances.itemByName( 'Chrome - Black' )     # Based on 'Chrome'
            appearNew   = appearancesDesign.addByCopy( appearBase, appearNew_Name )
        colorProp       = appearNew.appearanceProperties.itemById( 'metal_f0' )
        colorValue      = colorProp.value
        rgbColor = [255,0,0,0]
        colorResult     = colorValue.setColor( rgbColor[0], rgbColor[1], rgbColor[2],  rgbColor[3] )
        colorProp.value = colorValue  

        body = des.rootComponent.bRepBodies[0]
        body.appearance = appearNew
    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 7 of 9
MichaelT_123
in reply to: BrianEkins

Hi Mr Ekins,

 

I have to admit that the problem was not too easy to spot.
As a matter of fact, it has overwhelmed my rusty nerve synopsizes, causing shortcuts and obviously, if not permanent, then long-lasting damages.

I attached the test script and associated with it the test file <AppearAssign_Test. f3d>
The script contains both the explanation and the demonstration of the problem.
As I mentioned in my previous post, it's a new/recent one, as I haven't experienced such a phenomenon before.
Does it qualify as a bug? It is not for me to decide, but I hope that TF360 will address the issue ... somehow.

#Author-BE modified by MT
#Description- Appearance Assign Test. Use with <AppearAssign_Test. f3d> test file

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

def run(context):
    app: adsk.core.Application = adsk.core.Application.get()
    ui = app.userInterface
    try:
        des: adsk.fusion.Design = app.activeProduct
        appearNew_Name = 'NewAppearance'
        appearancesDesign = des.appearances
        library = app.materialLibraries.itemByName('Fusion 360 Appearance Library')
        appearNew       = appearancesDesign.itemByName( appearNew_Name )        # Check if appearNew_Name is in appearancesDesign
        if  appearNew is None:                                                  # Add respectibe color appearance
            appearBase  = library.appearances.itemByName( 'Chrome - Black' )     # Based on 'Chrome'
            appearNew   = appearancesDesign.addByCopy( appearBase, appearNew_Name )
        colorProp       = appearNew.appearanceProperties.itemById( 'metal_f0' )
        colorValue      = colorProp.value
        rgbColor = [255,0,0,0]
        colorResult     = colorValue.setColor( rgbColor[0], rgbColor[1], rgbColor[2],  rgbColor[3] )
        colorProp.value = colorValue  
        
        # ##@@MT The explantion 'attempt'.
        # To have consistent results, run the script/cases on the 'fresh' test file <AppearAssign_Test> attached !!! 
        #
        case = 'A'                                              # Select the 'case'
        #
        if case == 'A':
            # NOTHING visually will change; in the test, file appearances are applied to the body's faces, and they have OverrideAppearanceSource property applied
            # Also, no warning will be present
            body = des.rootComponent.bRepBodies[0]
            #body.appearance = None                             ##@@ MT         # This is Mr Brian Ekins example                      
            body.appearance = appearNew
            iii = 888                                      
        elif case == 'B':
            # NOTHING visually will change; in the test, file appearances are applied to the body's faces, and they have OverrideAppearanceSource property applied
            # Also, the warning will pop up on the screen
            # Why? ... 
            # body.appearance = None  is the attempt to clear possible OverrideAppearanceSource of respective occurrence owning the body 
            # This method is stated in docs. As a side effect, the CURRENT F360 kernel code will attempt to delete the appearance 'assigned' to the body
            # but it seems without checking body.appearance.usedBy.count ... which in the case of the test file is greater than 1.
            # As some other bodies are associated with the appearance, such an attempt will fail ... generating the warning message.
            # Conclusion: Such checking should be performed BEFORE the attempt to delete the body's appearance, which perhaps is missing!!!
            body = des.rootComponent.bRepBodies[0]
            body.appearance = None                              ##@@ MT                    
            body.appearance = appearNew
            iii = 888                                      
        elif case == 'C':
            # SOMETHING visually will change, 'RED=[255,0,0,0]' appearance will be applied to all body's faces 
            # Also, the warning will pop up on the screen
            # Why? ... as above          
            body = des.rootComponent.bRepBodies[0]
            body.appearance = None                         
            body.appearance = appearNew
            for face in body.faces:
                face.appearance = None                          ##@@ MT
                face.appearance = appearNew
            iii = 888                  
    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Regards
MichaelT

MichaelT
Message 8 of 9
sophiadoan
in reply to: MichaelT_123

I tried your code. Nothing visually change, red is not shown and many warnings popped up as you said.

I then deleted all your appearances in the design and ran the script again, this time one body turned red.

I forgot to mention, I used case 'A'

 

Message 9 of 9
sophiadoan
in reply to: MichaelT_123

I did some more test using case 'B', change RGB value many times, color on body changed correctly without any warnings.

So, I think your existing appearances in the design somehow put fusion in a warning storm.

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