Previous topic

stalker.models.entity.SimpleEntity

Next topic

stalker.models.format.ImageFormat

This Page

stalker.models.env.EnvironmentBase

Inheritance diagram of stalker.models.env.EnvironmentBase

class stalker.models.env.EnvironmentBase[source]

Bases: object

Connects the environment (the host program) to Stalker.

In Stalker, an Environment is a host application like Maya, Nuke, Houdini etc.

Generally a GUI for the end user is given an environment which helps the QtGui to be able to open, save, import or export a Version without knowing the details of the environment.

The environment object supplies methods like open, save, export, import or reference. The main duty of the Environment object is to introduce the host application (Maya, Houdini, Nuke, etc.) to Stalker and let it to open, save, export, import or reference a file.

It is the pipeline developers duty to create the environment classes for the programs used in the studio by instantiating this class and overriding the methods as necessary. You can find good examples in `Anima Tools`_ which is a Python package developed in `Anima Istanbul`_.

Here is a brief example for creating an environment for a generic program:

from Stalker import EnvironmentBase

class MyProgramEnv(EnvironmentBase):
    """This is a class which will be used by the UI
    """

    def open():
        """uses the programs own Python API to open a version of an
        asset
        """

        # do anything that needs to be done before opening the file
        my_programs_own_python_api.open(filepath=self.version.full_path)

    def save():
        """uses the programs own Python API to save the current file
        as a new version.
        """

        # do anything that needs to be done before saving the file
        my_programs_own_python_api.save(filepath=self.version.full_path)

        # do anything that needs to be done after saving the file

and that is it.

The environment class by default has a property called version. Holding the current open Version. It is None for a new scene and a Version instance in any other case.

__init__()

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Methods

check_referenced_versions() Checks the referenced versions
export_as(version) Exports the contents of the open document as the given version.
get_current_version() Returns the current Version instance from the environment.
get_fps() Returns the frame rate of this current environment
get_frame_range() Returns the frame range from the environment
get_last_version() Returns the last opened Version instance from the environment.
get_project() returns the current project from environment
get_referenced_versions() Returns the Version instances which
get_version_from_full_path(full_path) Finds the Version instance from the given full_path value.
get_versions_from_path(path) Finds Version instances from the given path value.
has_extension(filename) Returns True if the given file names extension is in the extensions
import_(asset) the import action
load_referenced_versions() loads all the references
open_(version[, force]) the open action
post_open(version) Runs after opening a file
reference(asset) the reference action
replace_external_paths([mode]) Replaces the external paths (which are not starting with the environment variable) with a proper path.
replace_version(source_version, target_version) Replaces the source_version with the target_version
save_as(version) The save as action of this environment.
set_fps([fps]) Sets the frame rate of the environment.
set_frame_range([start_frame, end_frame, ...]) Sets the frame range in the environment to the given start and end
set_project(version) Sets the project to the given Versions project.
trim_server_path(path_in) Trims the server_path value from the given path_in

Attributes

extensions Returns the valid native extensions for this environment.
name returns the environment name
version returns the current Version instance which is open in the
version[source]

returns the current Version instance which is open in the environment

name[source]

returns the environment name

save_as(version)[source]

The save as action of this environment. It should save the current scene or file to the given version.full_path

export_as(version)[source]

Exports the contents of the open document as the given version.

Parameters:version – A Version instance holding the desired version.
open_(version, force=False)[source]

the open action

post_open(version)[source]

Runs after opening a file

import_(asset)[source]

the import action

reference(asset)[source]

the reference action

trim_server_path(path_in)[source]

Trims the server_path value from the given path_in

Parameters:path_in – The path that wanted to be trimmed
Returns:str
get_versions_from_path(path)[source]

Finds Version instances from the given path value.

Finds and returns the Version instances from the given path value.

Returns an empty list if it can’t find any matching.

This method is different than get_version_from_full_path() because it returns a list of Version instances which are residing in that path. The list is ordered by the ids of the instances.

Parameters:path – A path which has possible Version instances.
Returns:A list of Version instances.
get_version_from_full_path(full_path)[source]

Finds the Version instance from the given full_path value.

Finds and returns a Version instance from the given full_path value.

Returns None if it can’t find any matching.

Parameters:full_path – The full_path of the desired Version instance.
Returns:Version
get_current_version()[source]

Returns the current Version instance from the environment.

Returns:Version instance or None
get_last_version()[source]

Returns the last opened Version instance from the environment.

  • It first looks at the current open file full path and tries to match it with a Version instance.
  • Then searches for the recent files list.
  • Still not able to find any Version instances, will return the version instance with the highest id which has the current workspace path in its path
  • Still not able to find any Version instances returns None
Returns:Version instance or None.
get_project()[source]

returns the current project from environment

set_project(version)[source]

Sets the project to the given Versions project.

Parameters:version – A Version.
check_referenced_versions()[source]

Checks the referenced versions

Returns:list of Versions
get_referenced_versions()[source]

Returns the Version instances which are referenced in to the current scene

Returns:list of Version instances.
get_frame_range()[source]

Returns the frame range from the environment

Returns:a tuple of integers containing the start and end frame numbers
set_frame_range(start_frame=1, end_frame=100, adjust_frame_range=False)[source]

Sets the frame range in the environment to the given start and end frames

get_fps()[source]

Returns the frame rate of this current environment

set_fps(fps=25)[source]

Sets the frame rate of the environment. The default value is 25.

extensions[source]

Returns the valid native extensions for this environment.

Returns:a list of strings
has_extension(filename)[source]

Returns True if the given file names extension is in the extensions list false otherwise.

accepts: * a full path with extension or not * a file name with extension or not * an extension with a dot on the start or not

Parameters:filename – A string containing the filename
load_referenced_versions()[source]

loads all the references

replace_version(source_version, target_version)[source]

Replaces the source_version with the target_version

Parameters:
  • source_version – A Version instance holding the version to be replaced
  • target_version – A Version instance holding the new version replacing the source one.
replace_external_paths(mode=0)[source]

Replaces the external paths (which are not starting with the environment variable) with a proper path. The mode controls if the resultant path should be absolute or relative to the project dir.

Parameters:mode

Controls the resultant path is absolute or relative.

mode 0: absolute (a path which starts with $REPO) mode 1: relative (to project path)

Returns: