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: 

Getting appearance data from API

14 REPLIES 14
Reply
Message 1 of 15
grzyboo
998 Views, 14 Replies

Getting appearance data from API

Hi,

 

I have problem with getting color information for materials.
I'm trying to read transmittance color for glass type material (interior_desing=3) this way:

body.appearance.appearanceProperties.itemById('transparent_color')

The problem is that it gives me weird rgb values. If any of rgb values is 255 then it returns this but values lower than 255 are returned as 0. So if I have color set in Fusion to i.e. (12,255,35) I got (0,255,0)

The same problem is when I try to read surface_albedo property.

I've tried to use getColor but then I got another error:

 

c.value.getColor(r,g,b,a)

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/grzybu/Library/Application Support/Autodesk/webdeploy/production/7a7e9c62480d5fc85b3d64d9f19bed096a977eb7/Api/Python/packages/adsk/core.py", line 2294, in getColor
    return _core.Color_getColor(self, *args)
TypeError: in method 'Color_getColor', argument 2 of type 'short &'

 

 

All other values (ior, roughness, transparent_distance) are returned properly.

 

So the question is how to correctly read color data?

 
Another question is about getting full path for textures.
Is there any way to get full path of textures? 
Texture path field contains only part of the path relative to appearance library, but I didn't found any API method to get appearance library path.
I guess it may differ on different machines so it's bad idea to hardcode this. 
 
14 REPLIES 14
Message 2 of 15
zhijie.li
in reply to: grzyboo

For getColor method, it is not correct way to use it in python. Please refer to the following code for how to use it:

results = c.value.getColor()

if results[0]:
    (retVal, r, g, b, a) = results
    print( "x = {0}, y = {1}, z = {2}".format(r, g, b, a) )

 

For details about it, please refer to section "Programming Interface>Fusion 360 API User's Manual>Python Specific Issues"  in Fusion Help (http://fusion360.autodesk.com/resources)

 

We will continue to investigate other issues you mentioned and will reply to you soon.

Message 3 of 15
grzyboo
in reply to: grzyboo

Thanks,

 

Still not working. When I try getColor I got error:

result = c.value.getColor()
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:/Users/xxxx/AppData/Local/Autodesk/webdeploy/production/bd4c089f43b372d7d340ccab8bdbc0eb06c9b2a6/Api/Python/packages\adsk\core.py", line 2396, in getColor
    return _core.Color_getColor(self, *args)
TypeError: Color_getColor() takes exactly 5 arguments (1 given)

 

Message 4 of 15
zhijie.li
in reply to: grzyboo

Sorry, there was a defect with python script about this in our last release. And it is already fixed which will be included in our latest release (coming soon).

Instead you can use JS script to get color from the property. Please refer to the following sample code:

 

//Author-
//Description-

function run(context) {

    "use strict";
    if (adsk.debug === true) {
        /*jslint debug: true*/
        debugger;
        /*jslint debug: false*/
    }
 
    var ui;
    try {
        var app = adsk.core.Application.get();
        ui = app.userInterface;
       
        var body = ui.activeSelections.item(0).entity;
        var colorProperty = body.appearance.appearanceProperties.itemById('surface_albedo');
        var r = {}, g = {}, b = {}, a = {};
        colorProperty.value.getColor(r, g, b, a);
        ui.messageBox(r.value + ', ' + g.value + ', ' + b.value + ', ' + a.value);
    }
    catch (e) {
        if (ui) {
            ui.messageBox('Failed : ' + (e.description ? e.description : e));
        }
    }

    adsk.terminate();
}

Message 5 of 15
grzyboo
in reply to: zhijie.li

OK, I think I'll wait for new release instead of mixing JavaScript and Python.

BTW. Is there any documentation about material properties describing which properties are used by particular material models?

Message 6 of 15
zhijie.li
in reply to: grzyboo

I am afraid that there is no documentation describing the properties of particular material yet. However you can find the properties by editing a material in which its properties will display.

 

Besides, for the former question, another way to get color value in python is like this:

r =  c.value.red

g = c.value.green

b = c.value.blue

a = c.value.opacity

And it will work in this way.

 

Unfortunately, the weird rgb values was confirmed as an issue with ColorProperty. It has been fixed immediately and will be included in the latest release.

 

And for the paths of textures, we will consider to return the full path through API. This needs more investigation before making a decision.

 

Thank you for the questions. They are helpful for us to improve the product. Please feel free to ask, if you have any question.

Message 7 of 15
grzyboo
in reply to: zhijie.li

It will be best to have option to get full path instead of relative to library.

Do you have release date for fixed version? 

Message 8 of 15
grzyboo
in reply to: grzyboo

BTW, can you check if vertex normal values will be fixed too in next release? 

I know meshCalculator will be fixed in next release so I suspect it will also return correct number of normals, am I right?

Message 9 of 15
zhijie.li
in reply to: grzyboo

I am afraid that I have no idea about the exact release date. But it will probably come in early June

Message 10 of 15
zhijie.li
in reply to: grzyboo

Sorry, I have no idea about this question. I will looking for other engineers who is familiar with it.

Message 11 of 15
grzyboo
in reply to: zhijie.li

Hi,

Javascript example works fine so my next question is: can I run JS script from another script/addin? 

Maybe this could be a temporary workaround until it's fixed in python API?

Message 12 of 15
zhijie.li
in reply to: grzyboo

Do you mean calling the JS script from python script/addin? I am afraid it will not work in this way.

 

However there is another way you can try, and it doesn't need to switch to JS. Please try to use the following code in python instead of "getColor" method:

r =  c.value.red

g = c.value.green

b = c.value.blue

a = c.value.opacity

ui.messageBox( "r = {}, g = {}, b = {}, a = {}".format(r, g, b, a) )

 

It works fine in this way.

 

Regards,

Zhijie

Message 13 of 15
grzyboo
in reply to: zhijie.li

Hi,

 

It works without error, but gives wrong values. 

I.e. if I try it with Glass (Green) appearance and transparent_color property I got 0,0,0,255 values while it should be 68,150,71,255

What I see if color component value has 255 then it's returned as 255, otherwise it's always 0. So we have only two values: 0 and 255.

Bit low for color properties 😉

Message 14 of 15
zhijie.li
in reply to: grzyboo

There is an issue with ColorProperty which will cause the incorrect value of color. And It is already fixed and will be included in the latest release (probably in early June). Sorry for inconvenient.

Message 15 of 15
grzyboo
in reply to: zhijie.li

OK, so I'll have to wait till new release.
I already have the code so I hope it will just work when it will be fixed.

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