0

Using a namespace instead of prefix in references

Hi.

Is it possible to use a namespace instead of a prefix when adding references to a scene? We have some in-house tools that are namespace dependent.

Thanks

댓글 1개

  • 0
    Avatar
    Manne Öhrström

    Hello Maxime!

    The default hook for loading data into Maya is super simple and is not trying to do anything special. Our sense is that clients will want to customize this behavior so we erred on the side of keeping things simple. The Loader app uses this hook by default and the Maya-specific lines to look at are 68-70:

    https://github.com/shotgunsoftware/tk-multi-loader/blob/master/hooks/multi_add_file_to_scene.py

    if ext in [".ma", ".mb"]:
            # maya file - load it as a reference
            pm.system.createReference(file_path)
    

    You can override this hook with your own desired flags (and/or additional behavior). Here are instructions on how to do that:

    https://support.shotgunsoftware.com/entries/95442818

    If you reference a file through the UI using default parameters, Maya prints this to the script editor:

    file -r -type "mayaAscii" -gl -loadReferenceDepth "all" -mergeNamespacesOnClash false -namespace "cube.origin.v001" -options "v=0;" "/tkstudio/hosted/maya01/assets/Prop/cube/Model/publish/maya/cube.origin.v001.ma";

    In addition to the file_path parameter, the hook is also passed a shotgun_data dictionary of basically all of the relevant fields from the Published File that you are loading in. I printed it within the add_file_to_scene hook and got this on my test site as an example (truncated some of the values so it would be a bit more readable):

    {
      'version_number': 2, 
      'description': 'Second publish!', 
      'created_at': datetime.datetime(2013, 9, 20, 18, 14, 7), 
      'published_file_type': {'type': 'PublishedFileType', 'id': 3, 'name': 'Maya Scene'},
      'created_by': {'type': 'HumanUser', 'id': 39, 'name': 'Ryan Mayeda'}, 
      'entity': {'type': 'Asset', 'id': 710, 'name': 'beet'}, 
      'image': 'https://...', 
      'path': {'...'}, 
      'type': 'PublishedFile', 
      'id': 41, 
      'name': 'model'
    }

    For the case you describe, you'll probably want what's in the entity key, in particular the name of it (aka the Asset name in Shotgun). So, you can update your hook to grab what the Published File you're loading is linked to in Shotgun, then pass its name to your createReference() call so it goes in as that namespace. Here is a simple example that I just tried on my side:

    if ext in [".ma", ".mb"]:
            # maya file - load it as a reference
            sg_link = shotgun_data['entity']
            pm.system.createReference(file_path, loadReferenceDepth='all', mergeNamespacesOnClash=False, namespace=sg_link['name'])
    

    You may want to have it do more stuff than that, but this will at least set the namespace as the Asset name.

    Hope this helps as a starting point!

댓글을 남기려면 로그인하세요.