Isotropix Forums

Custom attributes attached to contexts are not being saved

Clarisse Scripting related topics

Custom attributes attached to contexts are not being saved

Unread postby bvz2000 » Mon Sep 19, 2016 11:24 pm

I have a script that puts some important custom attributes onto a context (I am localizing the context via my script and I have to retain the path to the original project on disk.)

I have been using the following code to add this attribute (it is based off of the code in clarisse_helper.py):

Code: Select all
def setCustomAttribute(sel, section, key, value, attrType="string"):
    '''
    Adds a custom attribute to the passed node. The custom attribute will be in the section defined
    by 'section'. The type is assumed to be string unless otherwise specified. If, for example, a
    color needs to be passed, then it should be passed as a list or tuple of length 3. Other
    multi-value values should be passed in the same manner. Returns the attribute added.
    '''

    attr = None

    if  attrType == "bool":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_BOOL, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_DEFAULT, section)
        attr.set_bool(bool(value))

    if attrType == "long":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_LONG, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_DEFAULT, section)
        attr.set_long(int(value))

    if attrType == "double":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_DEFAULT, section)
        attr.set_long(float(value))

    if attrType == "string":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_STRING, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_DEFAULT, section)
        attr.set_string(str(value))

    if attrType == "reference":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_REFERENCE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_DEFAULT, section)
        attr.set_long(value) # TODO: Broken, cannot figure out how to set a reference

    if attrType == "percentage":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_PERCENTAGE, section)
        attr.set_double(float(value))

    if attrType == "distance":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_DISTANCE, section)
        attr.set_double(float(value))

    if attrType == "angle":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_ANGLE, section)
        attr.set_double(float(value))

    if attrType == "scale":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_SCALE, section)
        attr.set_double(float(value))

    if attrType == "frame":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_LONG, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_FRAME, section)
        attr.set_long(int(value))

    if attrType == "subframe":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_SUBFRAME, section)
        attr.set_double(float(value))

    if attrType == "l":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_L, section)
        attr.set_double(float(value))

    if attrType == "la":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_LA, section)
        attr.set_value_count(2)
        attr.set_double(float(value[0]), 0)
        attr.set_double(float(value[1]), 1)

    if attrType == "rgb":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_RGB, section)
        attr.set_value_count(3)
        attr.set_double(float(value[0]), 0)
        attr.set_double(float(value[1]), 1)
        attr.set_double(float(value[2]), 2)

    if attrType == "rgba":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_RGBA, section)
        attr.set_value_count(4)
        attr.set_double(float(value[0]), 0)
        attr.set_double(float(value[1]), 1)
        attr.set_double(float(value[2]), 2)
        attr.set_double(float(value[3]), 3)

    if attrType == "filein":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_FILE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_FILENAME_OPEN, section)
        attr.set_long(value) # TODO: what format (set_long is wrong)

    if attrType == "fileout":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_FILE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_FILENAME_SAVE, section)
        attr.set_long(value) # TODO: what format (set_long is wrong)

    if attrType == "pixel":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_PIXEL, section)
        attr.set_double(float(value))

    if attrType == "subpixel":
        attr = sel.add_attribute(key, ix.api.OfAttr.TYPE_DOUBLE, ix.api.OfAttr.CONTAINER_SINGLE,
                                 ix.api.OfAttr.VISUAL_HINT_SUBPIXEL, section)
        attr.set_double(float(value))

    return attr



This works and as I look through my project I am getting the attributes properly attached to the contexts that I have localized. But when I save, these attributes are not stored in the project file. In other words, as long as I don't close the clarisse session, I can clearly store and access custom attributes on a context. But once I save and re-open the project, ALL of this information is gone. What's more, I cannot seem to add a custom attribute to a context via the GUI. And if I try to manually edit the project file to add, say, the following to a context:

Code: Select all
#Isotropix_Serial_Version 1.1

#Isotropix_Clarisse_Version 3
#Isotropix_Clarisse_Project_Version 0.92
Context "veg_huangshanPineHigh_A" {
    #created 1474319609
    custom_attributes {
        attribute_group "NotWorking" {
            distance "Broken" {
                value 0.0
            }
        }
    }
}


It gets ignored on open.



Please tell me that I am doing something wrong. Clearly I can create them, but I need to save them as well. If not, is that something we can add to a service pack fix?

Thanks
bvz2000
 
Posts: 329
Joined: Thu Nov 13, 2014 7:05 pm

Re: Custom attributes attached to contexts are not being sav

Unread postby julien » Wed Sep 28, 2016 10:40 am

Hi,
Context custom attributes are not saved. If you want your custom attributes to be saved you need to add them to an OfObject. In your case you could create a container object in the contexts on which you want to add attributes and you will find them back after reloading your project.

Would this solution be fine for you?

Regards
User avatar
julien
 
Posts: 270
Joined: Mon Nov 18, 2013 7:30 pm

Re: Custom attributes attached to contexts are not being sav

Unread postby janoshunyadi » Wed Sep 28, 2016 4:56 pm

Perfect! Thank you!
janoshunyadi
 
Posts: 93
Joined: Tue Dec 01, 2015 2:51 pm

Re: Custom attributes attached to contexts are not being sav

Unread postby bvz2000 » Wed Sep 28, 2016 6:39 pm

julien wrote:Hi,
Context custom attributes are not saved. If you want your custom attributes to be saved you need to add them to an OfObject. In your case you could create a container object in the contexts on which you want to add attributes and you will find them back after reloading your project.

Would this solution be fine for you?

Regards


That is what I am doing at the moment and that works. Thanks.

That said, I would prefer it if the custom attributes were saved with contexts in the future. Having a generic object floating around in the context is messy and only complicates the code reading and writing it as well. Contexts are actually a very important notion for us (they represent entire assets with a specific structure underneath them) and so we are likely to want to add all kinds of metadata to them, and they are the most logical place for it. You already have the code to put the custom attributes on these contexts (as well as read them). The next step of saving them in the project should be doable, right?

Thanks!
bvz2000
 
Posts: 329
Joined: Thu Nov 13, 2014 7:05 pm

Re: Custom attributes attached to contexts are not being sav

Unread postby stheroux » Tue Apr 04, 2017 5:01 pm

I'm curious as well to know if there is any plan for custom attributes on contexts to be saveable eventually.
Thanks
Sylvain
stheroux
 
Posts: 38
Joined: Thu Jan 15, 2015 10:23 pm

Re: Custom attributes attached to contexts are not being sav

Unread postby julien » Tue Apr 11, 2017 2:33 pm

Hi,
This is something that we need to implement for 4.0 but we still don't know if that will be in the incoming 3.5 or not. I will come back to this once we have more information on this.

Thanks!
Regards
User avatar
julien
 
Posts: 270
Joined: Mon Nov 18, 2013 7:30 pm

Re: Custom attributes attached to contexts are not being sav

Unread postby luke » Thu Jun 15, 2017 5:30 pm

I'm totally new to Clarisse scripting. Can you provide example code for the proposed solution above? Specifically I am not sure how to create a container object in the context.

Thanks
luke
 
Posts: 19
Joined: Fri Jan 27, 2017 11:51 pm


Return to Scripting