Tim Edelmann Posted January 31, 2018 Report Share Posted January 31, 2018 Hey there, we're currently trying to create a widget, that will list up some of our custom attributes, but for now its a struggle to get these. Maybe we just didn't look in the right place? With the python api its possible to get these values via the project: project['custom_attributes'] but with the javascript api, project don't seem to have these properties: console.info('all project properties: '); for(var key in currentProject) { console.info('project['+key+'] = ' + currentProject[key]); } gives us something like this: all project properties: index.js:62 project[context_type] = show index.js:62 project[__entity_type__] = Project index.js:62 project[id] = 19e2f1e4-01dd-11e8-ac42-7ab7a47c9dda index.js:62 project[name] = tims_test_321345 So if we cannot get the 'custom_attributes' via the project, where do we get them from? thanks an advance Tim Link to comment Share on other sites More sharing options...
Lucas Correia Posted February 1, 2018 Report Share Posted February 1, 2018 Hi Tim, In the javascript API, only attributes which you have selected using a projection will currently be available on the returned objects. In order to see what attributes are available, you need to look at the API schema (Session.schemas). Here is an example that does this using the Python API. Here is an example of how it can be used. /** Get custom attribute value for *entity* and *key*. */ function getCustomAttributeValue(entity, key) { const customAttribute = entity.custom_attributes.find( attribute => attribute.key === key ); if (!customAttribute) { console.log('Unable to find attribute', key); return null; } return customAttribute.value; } // Query custom attributes for a single Shot and print the fstart custom attribute value. session.query( 'select custom_attributes from Shot limit 1' ).then(function (response) { console.info( 'Custom attribute value:', getCustomAttributeValue(response.data[0], 'fstart') ); }); Regards, Lucas Link to comment Share on other sites More sharing options...
Tim Edelmann Posted February 1, 2018 Author Report Share Posted February 1, 2018 Hey Lucas, thank you for the fast answer! I'll give it a try and post my results here. Tim Link to comment Share on other sites More sharing options...
Tim Edelmann Posted February 1, 2018 Author Report Share Posted February 1, 2018 Hey again, now this is what I have tried. Sadly nothing worked out so far (having an example, that does something similar, but in python, didn't help me -- maybe I didn't understand your answer?) I tested getting the entity (btw. is there somewhere a documentation, that tells, what entity this is? By checking its name I got, that it might be the current project): var entity = ftrackWidget.getEntity(); But the result of getting custom_attributes is undefined: var customs = entity.custom_attributes; In your example you do this on line 3: entity.custom_attributes What entity do I have to use for this? How do I get it? And is this even possible in javascript? In your example you used a 'Shot' as basis to get the custom attributes from it. In our project we have project-wide custom attributes, so using a Shot/Sequence or any asset won't work for us. And there is more: You wrote I should ' look at the API schema '. In the javascript api the session has a method called 'getSchema', but how am I supposed to use that? Is this even what you where talking about? thanks again in advance! Link to comment Share on other sites More sharing options...
Lucas Correia Posted February 1, 2018 Report Share Posted February 1, 2018 Ah, I misunderstood the question somewhat. ftrackWidget.getEntity() will return an object as provided by the ftrack.wiget.update event. This reflects the currently selected entity in the project outliner to the left in the interface. The format is: { id: 'eb16970c-5fc6-11e2-bb9a-f23c91df25eb', type: 'TypedContext' } In order to get get an object which contains the custom attributes, you will need to use the id and type and query the API for information you are interested in. You can see an example of how this is done in ftrack-spark-base in ExampleContainer::onFtrackWidgetUpdate, which gets the name and link attributes. Here is where you would use the code in my last post to get the custom attribute value for the selected entity. Regards, Lucas Link to comment Share on other sites More sharing options...
Tim Edelmann Posted February 1, 2018 Author Report Share Posted February 1, 2018 Alright! now its working! Thanks again, that helped me alot. The only thing thats left open, is a strange warning I get for each attribute, thats inside 'custom_attributes': Key could not be determined for: { entity_id: "19e2f1e4-01dd-11e8-ac42-7ab7a47c9dda", value: "*(Software version and plugins)*", __entity_type__: "ContextCustomAttributeValue", configuration_id: "0cec668e-e3d6-11e7-90fc-7ab7a47c9dda", key: "Briefing_Workflows_06_Grading", …} configuration: config: "{"markdown": true}" core: false entity_type: "show" group_id: "5f457ef8-e3d5-11e7-93c6-7ab7a47c9dda" id: "0cec668e-e3d6-11e7-90fc-7ab7a47c9dda" is_hierarchical: false key: "Briefing_Workflows_06_Grading" label: "Grading" object_type_id: null project_id: null sort: 95 type_id: "6268aef0-381c-11e0-acff-0019bb49847a" __entity_type__: "CustomAttributeConfiguration" __proto__: Object configuration_id: "0cec668e-e3d6-11e7-90fc-7ab7a47c9dda" entity_id: "19e2f1e4-01dd-11e8-ac42-7ab7a47c9dda" key: "Briefing_Workflows_06_Grading" value: "*(Software version and plugins)*" __entity_type__: "ContextCustomAttributeValue" __proto__: Object ...} Besides this, everything seems to be working as expected. May be this gets solved along the path of completing the whole widget.. Tim Link to comment Share on other sites More sharing options...
Lucas Correia Posted February 1, 2018 Report Share Posted February 1, 2018 That is odd, it should be able to generate identifier for those. Are you using an older pre-built version of the API maybe? If so, can you test with a new version? You can download one here: ftrack.0.4.5.min.js Regards, Lucas Link to comment Share on other sites More sharing options...
Tim Edelmann Posted February 5, 2018 Author Report Share Posted February 5, 2018 heyho, back on this topic and tried to get the now api version you suggested. The given link directs to 'https://s3-eu-west-1.amazonaws.com/ftrack-deployment/temp/ftrack.0.4.5.min.js' which gives me this: This XML file does not appear to have any style information associated with it. The document tree is shown below. <Error> <Code>AccessDenied</Code> <Message>Access Denied</Message> <RequestId>A9126FFD9BE6E22F</RequestId> <HostId> HYBHrBW8iyxPuvIWp9q6DQMQTDmaBGFSIPfc4UxS44OyWZ6ZKhA+co/b2KEQ4jEZ28hmYWD3EH8= </HostId> </Error> Could you provide another link? thanks T. Link to comment Share on other sites More sharing options...
Lucas Correia Posted February 5, 2018 Report Share Posted February 5, 2018 My bad. It should be accessible now. Regards, Lucas Link to comment Share on other sites More sharing options...
Tim Edelmann Posted February 6, 2018 Author Report Share Posted February 6, 2018 OK. tried it again and with the new api-version (0.4.5) you provided, it works without any warnings! (and of course without errors ) Thanks alot for your help! Tim Link to comment Share on other sites More sharing options...
Lucas Correia Posted February 6, 2018 Report Share Posted February 6, 2018 Great, thanks for following up and let us know if you need any more assistance with building dashboard widgets using the JavaScript API. Regards, Lucas Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.