Issue getting correct appearance in API from assembly imported from STEP

Issue getting correct appearance in API from assembly imported from STEP

tim.claridgeNN5S4
Explorer Explorer
1,034 Views
6 Replies
Message 1 of 7

Issue getting correct appearance in API from assembly imported from STEP

tim.claridgeNN5S4
Explorer
Explorer

Hi,

I have an issue getting the correct appearance from the API for an assembly that has been imported from STEP (I'm not sure if this is a general issue). To illustrate the problem I include TestColour.step.

 

To repeat issue:

1. Open the attached 'TestColour.step' in Fusion

2. Run the following python code as a script..

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        doc = app.activeDocument
        des = adsk.fusion.Design.cast(app.activeProduct)             
        root = des.rootComponent
		# red box
        red_box_occ = root.occurrences.item(0)
		# blue cyl
        blue_cyl_occ = root.occurrences.item(1)
		
		#red box body
        red_box_body = red_box_occ.bRepBodies.item(0)
        blue_cyl_body = blue_cyl_occ.bRepBodies.item(0)

        ui.messageBox(red_box_occ.name + ' Appearance Name:' + red_box_body.appearance.name +"\n" +
                    blue_cyl_occ.name + ' Appearance Name:' + blue_cyl_body.appearance.name)
        
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

It appears the api returns the same appearance for both the box and the cylinder, when obviously one is red (Opaque(247,66,66)) and one is blue (Opaque(97,122,201)). Their appearance names in Fusion are in brackets which I guess are auto generated.

 

The message box generated by the code shows that the api returns that they are both the same colour (Opaque(247,66,66)).

 

Please see attached screenshot at the foot of this message, and any advice would be appreciated as I need to get the colours of items that have been imported into Fusion via step files.

 

Thanks,

Tim.

 

2 appearances.png

 

 

 

0 Likes
1,035 Views
6 Replies
Replies (6)
Message 2 of 7

kandennti
Mentor
Mentor

Hi @tim.claridgeNN5S4 .

 

I had a similar problem the other day.
The conclusion is unresolved. (I gave up)

I loaded that data and examined the appearance of the design using this script.
import adsk.core, adsk.fusion, traceback

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

        print('name1:{}  name2:{}  Is Equal?:{}'.format(
            des.appearances[0].name,
            des.appearances[1].name,
            des.appearances[0] == des.appearances[1]))

        for (prop1, prop2) in zip(
            des.appearances[0].appearanceProperties,
            des.appearances[1].appearanceProperties):

            print('ID:{} *** Is Equal?:{}'.format(prop1.id, prop1 == prop2))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Looking at the results, it feels like they're referring to the same look.
 
In addition, it is very anxious that Appearance.appearanceProperties.count is different between the imported data and the data whose appearance is set in Fusion360.
0 Likes
Message 3 of 7

tim.claridgeNN5S4
Explorer
Explorer

Thanks for having a look at this, I guess there is a problem with the api, because obviously Fusion knows what appearances are there and what they should be. 

 

Anyone at Autodesk > Is there any chance of a fix for this (or at least a workaround)?

 

0 Likes
Message 4 of 7

BrianEkins
Mentor
Mentor

I looked at this and there's not an obvious workaround to me.  I think we'll need to wait for a fix.  Whether the problem is in the API or the STEP translator, I don't know.

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

tim.claridgeNN5S4
Explorer
Explorer

I have found a kind of workaround, which is by no means perfect but does appear to get the api to play ball. I wonder if this might help get to the bottom of the main issue...

 

If you go through all the colours in the 'In this design' section and rename (in this case to 'Blue', and 'Red'), it will then work. If there was a way in the api to do this that would be great, but I suspect that we cannot get access via the api due to the problem we had in the first place.

 

color_change.png

Thanks,

Tim.

Message 6 of 7

kandennti
Mentor
Mentor

I tried it in the range that came to my mind.

As far as I know, there are two ways to open a Step file in Fusion 360 with the GUI.

One is to open it locally (Shape Manager?) And to upload it to the cloud and open it (Forge?).
However, I couldn't find any difference.

 

Then, when I "Duplicate" the two in the GUI, I noticed that the API treats the Appearance as different.

1.png
The code looks like this.

import adsk.core, adsk.fusion, traceback

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

        # Import the STEP file in advance.
        appes = des.appearances
        appe1 :adsk.core.Appearance = appes[0]
        appe2 :adsk.core.Appearance = appes[1]
        print('appe1:{}  appe2:{}  Is Equal?:{}'.format(
            appe1.name,
            appe2.name,
            appe1 == appe2))

        # clone appearances
        clone1 :adsk.core.Appearance = appes.addByCopy(appe1, 'clone1')
        clone2 :adsk.core.Appearance = appes.addByCopy(appe2, 'clone2')
        print('clone1:{}  clone2:{}  Is Equal?:{}'.format(
            clone1.name,
            clone2.name,
            clone1 == clone2))


        for (prop1, prop2) in zip(
            clone1.appearanceProperties,
            clone2.appearanceProperties):

            print('ID:{} *** Is Equal?:{}'.format(prop1.id, prop1 == prop2))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


Given this, it feels like there's a problem with the converter, not the API.

0 Likes
Message 7 of 7

kandennti
Mentor
Mentor

Only Appearance Name, but I found a way to get it correctly.

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        doc = app.activeDocument
        des = adsk.fusion.Design.cast(app.activeProduct)             
        root = des.rootComponent
		# red box
        red_box_occ = root.occurrences.item(0)
		# blue cyl
        blue_cyl_occ = root.occurrences.item(1)
		
		#red box body
        red_box_body = red_box_occ.bRepBodies.item(0)
        blue_cyl_body = blue_cyl_occ.bRepBodies.item(0)

        ui.messageBox(red_box_occ.name + ' Appearance Name:' + getAppearanceName(red_box_body) +"\n" 
            + blue_cyl_occ.name + ' Appearance Name:' + getAppearanceName(blue_cyl_body))
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def getAppearanceName(body):

    app = adsk.core.Application.get()
    ui :adsk.core.UserInterface = app.userInterface
    actSels :adsk.core.Selections = ui.activeSelections

    actSels.clear()
    actSels.add(body)

    txtCmd = 'Component.BodyMaterial'
    tmp = app.executeTextCommand(txtCmd)

    actSels.clear()

    appe = tmp.split('[')

    return appe[0]

 

0 Likes