VisualContainer
A VisualContainer
can be thought of as similar to a folder in a file system. Objects are stored within them. This class inherits from the Container class which is a type of container that can store objects, but not used in standard operation of the software.
When renaming or moving a container, by acting as a parent to all children under it, they will also get new paths.
Creating a visual container
A VisualContainer
can be created two ways.
Example using Project.new()
function. This approach is preferred for similarity with creation of other objects. It also conveniently handles the creation of a hierarchy defined by the given path that may not yet exist (e.g. the path '/1/2/3/4' would create 1, 2, 3, and 4):
from mapteksdk.project import Project from mapteksdk.data import VisualContainer proj = Project() # Connect to default project # Create a VisualContainer under the project root with proj.new("/my_container", VisualContainer): pass
Example using Project.create_visual_container()
function. This may be less convenient if you need to create several sub-containers and requires the first parameter to be an already existing parent container:
from mapteksdk.project import Project proj = Project() # Connect to default project # Create a VisualContainer under the project root proj.new_visual_container("/","my_container_a")
These objects can be referenced as part of a path for deleting, renaming, editing and creating objects. The root path is "/" or "". Working with objects under "my_container" would use the path "/my_container/object_name".
The following example demonstrates creation of a tree of containers:
from mapteksdk.project import Project from mapteksdk.data import VisualContainer proj = Project() # Connect to default project for i in range(4): for j in range(2): for k in range(2): with proj.new("/i_{}/j_{}/k_{}".format(i, j, k), VisualContainer): pass
Note: You do not need to create containers for new objects before creating the objects. If a path is used for a new object that would nest it in containers that don't yet exist, the SDK will manage their creation.
Other container examples
Deleting the contents of a container
Refer to example in Project Examples - Deleting contents of a container
Listing the contents of a container
Refer to example in Project Examples - Listing contents of a container
Listing all objects in all containers
Refer to example in Project Examples - Listing all objects in all containers