Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

API: Query workfiles for an asset #3389

Closed
BigRoy opened this issue Jun 22, 2022 · 5 comments
Closed

API: Query workfiles for an asset #3389

BigRoy opened this issue Jun 22, 2022 · 5 comments

Comments

@BigRoy
Copy link
Collaborator

BigRoy commented Jun 22, 2022

Is your feature request related to a problem? Please describe.

I'd like to easily query the existing workfiles for an asset. Or at least have a clear cut way to find the workfiles for an asset.
The implementation would be used to batch detect the latest workfiles and do automation with that, things like:

  • After Maya render automatically open last related Comp to automatically render it out with the updates.
  • Detect newer workfiles than latest publishes for the shot to do a quick check whether publishes are potentially out of date (to be updated)
  • Check latest workfiles whether they contain all the latest publishes (e.g. do all comps currently have the latest renders in the comp files)?

I couldn't find anything that resembled a stable solution that worked out of the box.

Describe the solution you'd like

  • Should allow to query (all) workfiles for a specific asset, task, application/host
  • Should support AVALON_SCENEDIR
  • Should have a simple way to from the list of files get what OpenPype assumes is the last version. (based on name template + version, like workfiles tool does?)

I'd like to be able to do:

get_workfiles(asset, task="compositing", application="maya")

Potentially this is fine too if it could find the correct workdir including the applications' expected AVALON_SCENEDIR.

asset = get_asset_by_name("hero")
workdir = get_workfiles_dir(asset, task="compositing", application="maya")

Describe alternatives you've considered

Draft implementation I had set up:

def get_last_workfile(asset_doc, task_name, host_name, anatomy, extensions, project_settings):

    workdir_data = avalon_context.get_workdir_data(project, asset, task_name=task_name, host_name=host_name)
    workdir = avalon_context.get_workdir_with_workdir_data(workdir_data, anatomy=anatomy)
    workdir = os.path.join(workdir, "scenes")  # I had to HACK this in since code didn't support the `AVALON_SCENEDIR` for a host
    task_type = workdir_data["task"]["type"]
    template_key = avalon_context.get_workfile_template_key(
        task_type, host_name, project_settings=project_settings
    )
    
    # Find last workfile
    file_template = str(anatomy.templates[template_key]["file"])
    workdir_data.update({
        "version": 1,
        "user": get_openpype_username(),
        "ext": extensions[0]
    })

    last_workfile_path = avalon_context.get_last_workfile(
        workdir, file_template, workdir_data, extensions, True
    )
    
    if os.path.exists(last_workfile_path):
        return last_workfile_path
    else:
        print(f"No workfile exists for: {asset['name']}")

Additional context

This might already be solved with a clear example on how to approach this best.

[cuID:OP-3439]

@iLLiCiTiT
Copy link
Member

I had to HACK this in since code didn't support the AVALON_SCENEDIR for a host

I would say that AVALON_SCENEDIR is reason why this can't be added otherwise it's just "hacking", thus not good idea to have it as public function which "sometimes work".

First must be handled how to define scene directory.

  • Right now we consider workdir as directory where workfile is located and kept usage of AVALON_SCENEDIR for you.
  • With more features and requests related to workfiles is scene dir more and more complicated to be able handle it when it;s host based.

If scene dir is considered as it should stay, then it require to separate it to something like "workarea", "workdir" and "workfile" and all of them must be defined in some predictable way not based on environment variables or unreachable in-host implementation (not use work_root function at all). When that is done, we can consider this function.

We plan that host will have public class (like modules) where some public functions could be. There could be variant of work_root function. So that could be possible option.

Note:
Isn't Maya only host where scene dir is actually used?

@BigRoy
Copy link
Collaborator Author

BigRoy commented Jun 29, 2022

I would say that AVALON_SCENEDIR is reason why this can't be added otherwise it's just "hacking", thus not good idea to have it as public function which "sometimes work".

For me it doesn't technically need to be the environment variable. But we would however prefer to set a specific subfolder within the application's directory per application. So that e.g. maya has scenes directory with the scene files next to renders directory, etc.

Would love to see this solved in a way that works completely with OpenPype and then remove the AVALON_SCENEDIR variable support.

We are using AVALON_SCENEDIR in both Maya and Fusion currently.

@iLLiCiTiT
Copy link
Member

I see 2 possible ways:

  1. We define that globally and have ability to tell host so he can handle it (e.g. Maya mel is changed in workdir).
  2. Host will define it in a way we can get that information at any point (so this function is possible).

Option 2 seems better and probably with less changes. Both would require that there is some host public function that would handle it (replacement of work_root), at least before host addons are implemented (that will take some time).

@BigRoy
Copy link
Collaborator Author

BigRoy commented Jun 29, 2022

Number 2) sounds the best way to do it. It'd just be a global template setting in the project for the application to have that extra 'scenes' folder.

Actually thinking about it now... this could already be managed potentially with workfile templates completely if those can be defined per project per application (as long as the maya workspace (the task root directory in the app) can be the folder without that extra 'template folder'. Like if the Work template could have a "scenes dir" entry as well and how it could potentially be customizable per application as is also done for Unreal?

Bonus points at least if the workdir setting can be set per project per application.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Jul 29, 2024

With the dropped support for SCENEDIR in Ayon I believe this is somewhat more accessible already in AYON.

@BigRoy BigRoy closed this as completed Jul 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants