Sorry if this sounds as a stupid question but i’m trying to use the ‘saveas_default_name’ setting inside of ‘tk-multi-workfiles2.yml’ so that Maya automatically fills the ‘name’ field with the asset name when trying to save for the first time.
When i add that setting, the Maya reference box shows that the setting is no longer by default and displays the string i used.
But the problem is that the ‘name’ field is always automatically populated with the string ‘scene’.
What am I doing wrong here? What do I need to do to get the asset name by default when trying to save?
I just tested this, and it worked for me. If I set a value for saveas_default_name, that’s what I get in the name field when I do a Shotgun-> File Save in Maya. There are a couple things to point out here:
I suspect that you set this value in the wrong environment – when you’re saving a file, for example, to a task an a pipeline step on an Asset, you’re in the asset_step environment. So, you’ll want to make sure you’re updating the correct settings – those that config/env/asset_step.yml includes.
In the Default Config, this would be the settings.tk-multi-workfiles2.asset_step block of config/env/includes/settings/tk-multi-workfiles2.yml (as seen below), but if your pipeline configuration is set up differently, this may vary.
Having said that, I don’t believe you can set saveas_default_name to a dynamic value – you can only use it with a static string.
What you might want to do is modify your templates in config/core/templates.yml so that instead of{name}, you’re using {Asset}. Note that if you don’t have a {name} field in your template, the text field in the File Save dialog will go away, and the file path will be fully automatically generated, with no input from the user.
I know this is fairly old, but this solution works like a charm, thanks so much @blaigneau!
I had no clue you could trick string config values to be resolved with a core hook. I wonder if anyone has found a way for the hooks to not be core hooks, ie .being able to specify {engine}{config}, etc…
I wonder how this can be used to set name based on the pipeline step.
Because the bundle_obj.context has step/task/entity None when saving a new scene - there is only valid context.project.
The step/task/entity are still None regardless the selection in save dialog.
hello and thanks for the suggestion! very late in the game here and the link you provided does not seem to work anymore. any chance this is available elsewhere?
# -*- coding: utf-8 -*-
#
# Copyright (c) 2015 Mac Guff
# ----------------------------------------------------
#
# @author: Barbara Laigneau <barbara@dark-shot.com>
# @brief: Core Hook to get a name from a context
from sgtk import Hook
import os
class ProceduralNameFromContext(Hook):
"""
"""
def execute(self, setting, bundle_obj, extra_params, **kwargs):
"""
Get a name from the current context
:param setting: The name of the setting for which we are evaluating
In our example above, it would be template_snapshot.
:param bundle_obj: The app, engine or framework object that the setting
is associated with.
:param extra_params: List of options passed from the setting. If the settings
string is "hook:hook_name:foo:bar", extra_params would
be ['foo', 'bar']
returns: needs to return the name of the file, as a string
"""
resolve_mode = extra_params[0]
# the mode is basically the parameter passed from the config value - in this case task_name
if resolve_mode == "task_name":
ctx_task = bundle_obj.context.task
return ctx_task["name"] if ctx_task else "scene"
elif resolve_mode == "entity_name":
ctx_entity = bundle_obj.context.entity
return ctx_entity["name"] if ctx_entity else "scene"
else:
return "scene"