tokejepsen Posted December 14, 2016 Report Share Posted December 14, 2016 Hey, I've been trying to follow the docs example of adding a location, so I can do "session.pick_location()"; http://ftrack-python-api.rtd.ftrack.com/en/latest/locations/configuring.html#configuring-automatically I can get the registration to execute, but I can't get "session.pick_location()" to return the location. I might be misunderstanding but shouldn't I be able to do "session.pick_location()" in Maya? Link to comment Share on other sites More sharing options...
tokejepsen Posted December 14, 2016 Author Report Share Posted December 14, 2016 Code Example: import os import ftrack_api import ftrack_template class Structure(ftrack_api.structure.base.Structure): def get_resource_identifier(self, entity, context=None): templates = ftrack_template.discover_templates() path = ftrack_template.format( {}, templates, entity=entity )[0].replace("\\", "/").replace("//", "/") if entity.entity_type == "SequenceComponent": padding = entity["padding"] if padding: expression = "%0{0}d".format(padding) else: expression = "%d" filetype = entity["file_type"] path = path.replace( filetype, "/{0}.{1}{2}".format( os.path.splitext(os.path.basename(path))[0], expression, filetype ) ) return path def configure_locations(event): """Configure locations for session.""" session = event["data"]["session"] # Find location(s) and customise instances. location = session.query( "Location where name is \"project.disk.root\"" ).one() ftrack_api.mixin( location, ftrack_api.entity.location.UnmanagedLocationMixin ) location.accessor = ftrack_api.accessor.disk.DiskAccessor(prefix="") location.structure = Structure() location.priority = 50 print location def register(session): # Validate that session is an instance of ftrack_api.Session. If not, # assume that register is being called from an old or incompatible API and # return without doing anything. if not isinstance(session, ftrack_api.Session): return session.event_hub.subscribe( "topic=ftrack.api.session.configure-location", configure_locations ) Link to comment Share on other sites More sharing options...
Lucas Correia Posted December 14, 2016 Report Share Posted December 14, 2016 `session.pick_location` will return the location with the highest priority (that is, the lowest numerical value). To make sure your location is returned, it should have a lower priority than the current lowest. You can check the current picked locations priority, like so: >>> location = session.pick_location() >>> location.priority 90 If you have configured a Centralized storage scenario, it will configure a location with a priority = 1, meaning it will be picked since the number is lower than 50. You can remove the scenario from system settings, or set your location's priority to 0. Regards, Lucas Link to comment Share on other sites More sharing options...
tokejepsen Posted December 15, 2016 Author Report Share Posted December 15, 2016 I've narrowed down the problem to this line; https://bitbucket.org/ftrack/ftrack-connect/src/64b062c0b6b86ba45225878f154f0e04180cbfe1/source/ftrack_connect/application.py?at=master&fileviewer=file-view-default#application.py-456 It was getting executed correctly, but ftrack-connect is removing the variable from the application environment. Currently it just says it causes problems, but what kind of problems? Also this defeats the workflow suggested in the docs when using ftrack-connect. If I manually add the variable again inside the application "session.pick_location()" works. Link to comment Share on other sites More sharing options...
Mattias Lagergren Posted December 15, 2016 Report Share Posted December 15, 2016 The removal of the FTRACK_EVENT_PLUGIN_PATH is there to ensure that all event plugins are deliberately added. If ignored and just passed on you would source and register actions, event listeners and possibly even application launchers from inside Nuke or Maya. The FTRACK_EVENT_PLUGIN_PATH is a blunt tool since the api does not understand the context of where it is used. An initial idea was to allow a context for discovering event listeners so that you could do: api.discover_plugins('nuke') or api.discover_plugins('ftrack-connect-desktop-application') But this was never realised and thus we need to manage the event plugin path environment variable. The solution is to listen to the application launch event and pass on the FTRACK_EVENT_PLUGIN_PATH / FTRACK_LOCATION_PLUGIN_PATH that you want to have. Link to comment Share on other sites More sharing options...
Mattias Lagergren Posted December 15, 2016 Report Share Posted December 15, 2016 Here is an example of adding to the application launch event: http://ftrack-connect.rtd.ftrack.com/en/stable/developing/tutorial/adding_a_location.html#developing-tutorial-adding-a-location Link to comment Share on other sites More sharing options...
tokejepsen Posted May 23, 2017 Author Report Share Posted May 23, 2017 Hey, I'm back to try and get our location plugin working with the new api. Could I get a guide as to how to register a location with the new api, so ftrack-connect is aware of it? I tried this; http://ftrack-python-api.rtd.ftrack.com/en/latest/locations/configuring.html, but it doesn't register the accessor or structure correctly in applications like Nuke. Link to comment Share on other sites More sharing options...
Lucas Correia Posted May 23, 2017 Report Share Posted May 23, 2017 Hi, There is a guide on how to add location plugins so that they are available when running ftrack-connect here. For the new API, you should add the location to the FTRACK_EVENT_PLUGIN_PATH instead of FTRACK_LOCATION_PLUGIN_PATH. Regards, Lucas Link to comment Share on other sites More sharing options...
tokejepsen Posted May 23, 2017 Author Report Share Posted May 23, 2017 Hey @Lucas Correia Maybe you help troubleshoot this. My location plugin, added to FTRACK_EVENT_PLUGIN_PATH import ftrack_api def configure_locations(event): '''Configure locations for session.''' session = event['data']['session'] location = session.query( "Location where name is \"testing.location\"" ).first() if not location: location = session.create('Location', dict(name='testing.location')) session.commit() location.accessor = ftrack_api.accessor.disk.DiskAccessor(prefix="") location.structure = ftrack_api.structure.standard.StandardStructure() def register(session): # Validate that session is an instance of ftrack_api.Session. If not,assume # that register is being called from an old or incompatible API and return # without doing anything. if not isinstance(session, ftrack_api.Session): return session.event_hub.subscribe( 'topic=ftrack.api.session.configure-location', configure_locations ) Running this in Nuke: import ftrack_api session = ftrack_api.Session() for location in session.query("Location"): print location["name"] print location.accessor Returns: ftrack.connect NOT_SET ftrack.origin <ftrack_api.accessor.disk.DiskAccessor object at 0x000000008C0E9F60> ftrack.review <ftrack_api.accessor.disk.DiskAccessor object at 0x000000008C0EC438> ftrack.server <ftrack_api.accessor.server._ServerAccessor object at 0x000000008C0EC668> ftrack.unmanaged <ftrack_api.accessor.disk.DiskAccessor object at 0x000000008C0EC208> testing.location NOT_SET Can you replicate this? Link to comment Share on other sites More sharing options...
Lucas Correia Posted May 23, 2017 Report Share Posted May 23, 2017 It doesn't look at the plugin is being registered. Can you within nuke check the contents of the `FTRACK_EVENT_PLUGIN_PATH` environment variable? If it is correct, can you add some logging/print statements to your plugin to ensure the location is being registered? Regards, Lucas Link to comment Share on other sites More sharing options...
tokejepsen Posted May 23, 2017 Author Report Share Posted May 23, 2017 You are completely right, I should have read this thread more carefully. Needed the application launch environment set. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.