.. _wapi_examples: ============= Wapi examples ============= ----------------------- Navigate in the project ----------------------- Here is a code example to navigate trough the assets and print all the available stages in the project. First method using strings : .. code-block:: python import wapi import logging # Get a list of the current domains domains = wapi.assets.list_domains(column='name') for domain in domains: # For each domain, list the child categories, using the domain name as parent categories = wapi.assets.list_categories(domain, column='name') for category in categories: # For each category, build the category path, using a formatted string category_path = f"{domain}/{category}" # Then list the child assets using this category path assets = wapi.assets.list_assets(category_path, column='name') for asset in assets: # For each asset, build the asset path using a formatted string asset_path = f"{domain}/{category}/{asset}" # Then list the child stages using this asset path stages = wapi.assets.list_stages(asset_path, column='name') for stage in stages: # For each stage, build the stage path using a formatted string stage_path = f"{domain}/{category}/{asset}/{stage}" logging.info(stage_path) Second method using ids: .. code-block:: python import wapi import logging # Get a list of the current domains domains_ids = wapi.assets.list_domains(column='id') for domain_id in domains_ids: # For each domain, list the child categories, using the domain name as parent categories_ids = wapi.assets.list_categories(domain_id, column='id') for category_id in categories_ids: # Then list the child assets using this category id assets_ids = wapi.assets.list_assets(category_id, column='id') for asset_id in assets_ids: # Then list the child stages using this asset id stages = wapi.assets.list_stages(asset_id) for stage_row in stages: # Log each stage name and id logging.info(stage_row['string']) logging.info(stage_row['id']) ------------- Create assets ------------- Here is a code example to create a sequence, multiple shots and multiple stages. .. code-block:: python import wapi sequence = "seq_0003" shots_list = ["sh_0001", "sh_0002", "sh_0003"] stages_list = ["layout", "animation", "cfx", "fx", "camera", "lighting", "compositing"] # First, create the sequence sequence_path = wapi.assets.create_sequence(sequence) if sequence_path: # If the sequence is successfully created, create the list of shots for shot in shots_list: asset_path = wapi.assets.create_asset(sequence_path, shot) # If the shot is successfully created, create the stages if asset_path: for stage in stages_list: wapi.assets.create_stage(asset_path, stage) # Don't forget to refresh the user's interfaces of the team wapi.team.refresh_ui() ----------------- Create references ----------------- Here is a code example to reference a rig in multiple animation scenes. .. code-block:: python import wapi # Define the target variant to reference variant_to_reference = "assets/characters/Joe/rigging/main" # Define the work environment that needs the reference destination_work_envs = ["sequences/seq_0001/sh_0001/animation/main/maya", "sequences/seq_0001/sh_0002/animation/main/maya", "sequences/seq_0001/sh_0003/animation/main/maya"] # Then, for each work environment, create the reference using wapi for destination_work_env in destination_work_envs: new_references = wapi.assets.create_reference(destination_work_env, variant_to_reference) # Finally, for each reference, apply the auto update parameter for reference in new_references: wapi.assets.modify_reference_auto_update(destination_work_env, reference, auto_update=True) # Don't forget to refresh the team user's interfaces wapi.team.refresh_ui()