Previous topic

oyProjectManager.core.models.Client

Next topic

oyProjectManager.core.models.Project

This Page

oyProjectManager.core.models.EnvironmentBase

Inheritance diagram of oyProjectManager.core.models.EnvironmentBase

class oyProjectManager.core.models.EnvironmentBase[source]

Bases: object

Connects the environment (the host program) to the oyProjectManager.

In oyProjectManager, 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.

Note

For now the EnvironmentBase inherits from the Python object class. There were no benefit to inherit it from the DeclarativeBase.

To create a new environment for you own program, just instantiate this class and override the methods as necessary. And call the UI with by giving an environment instance to it, so the interface can call the correct methods as needed.

Here is an example how to create an environment for a program and use the GUI:

from oyProjectManager.core import EnvironmentBase

class MyProgram(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.

Parameters:name – To initialize the class the name of the environment should be given in the name argument. It can not be skipped or None or an empty string.
__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

Methods

check_referenced_versions() Checks the referenced versions
export_as(version) Exports the contents of the open document as the given version.
getProject() returns the current project from environment
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_referenced_versions() Returns the Version instances
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 filenames extension is in the extensions
import_(asset) the import action
load_referenced_versions() loads all the references
open_(version[, force]) the open action
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

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 empth 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
getProject()[source]

returns the current project from environment

set_project(version)[source]

Sets the project to the given versions project.

Because the projects are related to the created Version instances instead of passing a Project instance it is much meaningful to pass a Version instance which will have a reference to the Project instance already.

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

Checks the referenced versions

returns list of asset objects

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 filenames 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: