Working with Containers
It is possible to have objects linked to containers or contents of containers without being part of the container content, but this is not recommended.
It is not possible to instance containers within a scene (that is to have multiple references to the same shared container), but they can be copied, and then changes to one of the copies can be saved, and all containers can be reloaded, and all copies will inherit the changes. Many containers can point to the same definition.
In addition to the content, containers also govern what users of a container are allowed to do with the content if they inherit the container. This is called the container rules. At the moment, the only options are either no access (the user can only read in the content but make no modification) or edit in-place, which allows someone inheriting the container to modify the content and save the result, overwriting the original definition.
Common Container Tasks
The following are some common tasks associated with containers:
- Creating a container - You can create a new local container using the method
IContainerManager::CreateContainer()
. - Importing a container into a scene - You can import (inherit) an existing container into a scene using the method
IContainerManager::CreateInheritedContainer()
. - Saving and loading the content - A container and its content is saved in a Max file separate from the main scene file called the container definition file. By convention definition files use a different file extension: .MAXC. This is to allow users to distinguish container definitions from regular scene files when browsing folders, and prevent mistaken edits of container definitions. It is possible to rename the container definition and open it as a MAX file. Local containers use a local definition file. Inherited containers reference a source definition file.
- Adding content to a container - Content can be added to a container using the methods:
IContainerObject::AddNodeToContent()
andIContainerObject::AddNodesToContent()
, andIContainerObject::RemoveNodeFromContent()
. Nodes added to a container should not have references to other nodes outside of the container, otherwise these references can disappear during operations performed on the container. Content nodes in containers become children of the container. - Removing content from a container - Content can be removed from a container using the method
IContainerObject::RemoveNodeFromContent()
. - Unloading of content from scene - When content is unloaded, changes are saved to the definition file, and the content is removed from the scene. See
IContainerObject::UnloadContainer()
. - Loading of content into scene - If content has been unloaded, it can be loaded back into the scene using
IContainer::LoadContainer()
. CallingIContainerObject::ReloadContent()
causes content in the scene to be updated with the contents in the definition file, and to lose local modifications. CallingIContainerObject::UpdateContent()
behaves like a merge, maintaining local modifications. This would be used if multiple users are collaborating using the same container. - Copying content - A referenced (inherited) container can be made into a local (unique) container by calling
IContainerObject::MakeUnique()
orIContainerObject::MergeSource()
. All future changes (and previously unsaved changes) to the content will not be saved to the original container definition file.IContainerObject::MakeUnique()
is recursively applied to nested containers whileIContainerObject::MergeSource()
is not. - Deleting the container from the scene - If a container is deleted from the scene all associated data is deleted.
- Querying containers for content - The
IContainerManager
interface is used to query whether a container contains a node through the methodIContainerManager::IsInContainer()
. - Saving and loading of a container - A container is saved automatically in the main 3ds Max scene file as a file asset, while the container contents are saved in the container definition file.
- Modifying container permissions - Containers can prevent or allow edits to be performed on their content. This is called 'closing' or 'opening' a container respectively. When a container is closed the content behaves like an XRef'd scene, it will be displayed and its contents rendered but it can not be selected or edited. Some methods related to container permissions are:
IContainerObject::IsOpen()
,IContainerObject::SetOpen()
,IContainerObject::IsContainerOpenableOrClosable()
.