c4d.BaseContainer
¶
A container is a collection of individual values. Each value has its own ID and type. Container can also carry any number of child containers. There is no guarantee that a value is there in the container.
Keep in mind that there is no guarantee for a value to be in the container. Use default values whenever possible when accessing the values. Maybe your plugin won’t be able to change some values, but it will work anyway.
It is recommended that you use the available containers to store your own values as well. That way they will be automatically saved. However, if you want to store values in the top level of for example an object container, you’ll have to use a unique id. You can use a plugin id from PluginCafe for this. A good way is to store a sub-container with this id. Inside this sub-container you can use whatever ids you want.
Once you’ve set a container value using one type you must neither try to access it using another type, nor overwrite it with a value of another type! Using the wrong access will not crash, but it is illegal.
c4d.
BaseContainer
¶
BaseContainer.InsData()
BaseContainer.InsDataAfter()
BaseContainer.SetData()
BaseContainer.GetData()
BaseContainer.GetDataPointer()
BaseContainer.GetBool()
BaseContainer.GetLong()
BaseContainer.GetInt32()
BaseContainer.GetLLong()
BaseContainer.GetInt64()
BaseContainer.GetReal()
BaseContainer.GetFloat()
BaseContainer.GetVector()
BaseContainer.GetMatrix()
BaseContainer.GetString()
BaseContainer.GetFilename()
BaseContainer.GetUuid()
BaseContainer.GetTime()
BaseContainer.GetContainer()
BaseContainer.GetContainerInstance()
BaseContainer.GetLink()
BaseContainer.GetObjectLink()
BaseContainer.GetMaterialLink()
BaseContainer.GetCustomDataType()
BaseContainer.SetBool()
BaseContainer.SetLong()
BaseContainer.SetInt32()
BaseContainer.SetLLong()
BaseContainer.SetInt64()
BaseContainer.SetReal()
BaseContainer.SetFloat()
BaseContainer.SetVector()
BaseContainer.SetMatrix()
BaseContainer.SetString()
BaseContainer.SetFilename()
BaseContainer.SetUuid()
BaseContainer.SetTime()
BaseContainer.SetContainer()
BaseContainer.SetLink()
BaseContainer.
__init__
(
[
n
]
)
¶
Initializes a new container.
Parameters: | n ( c4d.BaseContainer , int or None ) – Use int if you just want to set the ID of the container. Pass a container if you want to clone it, or None to use a standard empty container. |
---|---|
Return type: | c4d.BaseContainer |
Returns: | The new container. |
BaseContainer.
__iter__
(
)
¶
The BaseContainer is iteratable so just use it like in the following example:
def iter_container(bc): for index, value in bc: print "Index: %i, Value: %s" % (index, str(value))
BaseContainer.
__getitem__
(
self
,
key
)
¶
Returns a value with the specified ID.
Parameters: | key ( int ) – Index of the value. |
---|---|
Return type: | any |
Returns: | Any value. |
BaseContainer.
__setitem__
(
self
,
key
,
value
)
¶
Automatically redirect the value to the corresponding Set* method. Its recommended to use the original Set* method to avoid type problems.
Warning
This method can replace types. Please check the types before when a special key is associated with a special type.
To delete a key, call
del(bc[i])
or
RemoveData()
.
Parameters: |
|
---|
BaseContainer.
__ne__
(
self
,
other
)
¶
BaseContainer.
__eq__
(
self
,
other
)
¶
Check if the compared containers have the same ID, have the same values, and all values are equal.
Parameters: | other ( c4d.BaseContainer ) – Returns True if the compared containers are equal. |
---|
BaseContainer.
GetClone
(
flags
[
,
trans=None
]
)
¶
Returns a copy of the container including all values.
Parameters: |
|
||||||
---|---|---|---|---|---|---|---|
Return type: | |||||||
Returns: |
The cloned container. |
BaseContainer.
CopyTo
(
dst
,
flags
[
,
trans=None
]
)
¶
Copies all values to dst .
Parameters: |
|
---|
BaseContainer.
FlushAll
(
)
¶
Clears all values in the container. The container ID is not changed.
BaseContainer.
GetId
(
)
¶
Returns the ID of the container.
Return type: | int |
---|---|
Returns: | The container ID. |
BaseContainer.
SetId
(
id
)
¶
Sets the ID of the container.
Parameters: | id ( int ) – The container ID. |
---|
BaseContainer.
GetDirty
(
)
¶
Returns the dirty count. Can be used to check if the container has changed.
Return type: | int |
---|---|
Returns: | Dirty counter. It is incremented when the container changes. |
BaseContainer.
RemoveData
(
id
)
¶
Removes the first data item with the specified ID.
Parameters: | id ( int ) – The container ID. |
---|---|
Return type: | bool |
Returns: | True if any value was removed, otherwise False . |
BaseContainer.
RemoveIndex
(
i
)
¶
Removes the data item at the specified index i .
Parameters: | i ( int ) – The index of the value to be removed. |
---|---|
Return type: | bool |
Returns: | True if any value was removed, otherwise False . |
BaseContainer.
FindIndex
(
i
)
¶
Returns the index for the value with the specified ID, or -1 if no such value exists.
Parameters: | id ( int ) – The ID of the value. |
---|---|
Return type: | bool |
Returns: | The index of the value, or -1. |
BaseContainer.
GetIndexId
(
index
)
¶
Returns the ID of the element at the specified index, or NOTOK if it doesn’t exist. Used to browse through the container.
Parameters: | index ( int ) – The index of the value. |
---|---|
Return type: | bool |
Returns: | The ID of the value, or NOTOK . |
BaseContainer.
GetType
(
id
)
¶
Returns the type of a container element by ID.
Parameters: | id ( int ) – The ID of the element. | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Return type: | int | ||||||||||||||||||||||||||||||
Returns: |
The type:
|
BaseContainer.
InsData
(
id
,
n
)
¶
Inserts an arbitrary data at the specified id .
Warning
This function does not check if the ID already exists in the container!
Parameters: |
|
---|---|
Return type: |
any |
Returns: |
The inserted data. |
BaseContainer.
InsDataAfter
(
id
,
n
,
last
)
¶
Inserts an arbitrary data at the specified id after last .
Warning
This function does not check if the ID already exists in the container!
Parameters: |
|
---|---|
Return type: |
any |
Returns: |
The inserted data. |
BaseContainer.
SetData
(
id
,
n
)
¶
Sets an arbitrary data value at the specified ID. If a value exists under the same ID, its content will be changed.
Parameters: |
|
---|
BaseContainer.
GetData
(
id
)
¶
Returns the data for an element by ID.
Parameters: | id ( int ) – The ID of the element. |
---|---|
Return type: | any |
Returns: | The data or None if it wasn’t found. |
BaseContainer.
GetDataPointer
(
id
)
¶
New in version R17.053.
Retrieves a pointer to directly access the data.
For example:
import c4d bc = c4d.BaseContainer() bc[1000] = "hello" bc[2000] = "world" # Print content print "Original:" for dataid, data in bc: print data, print dataptr = bc.GetDataPointer(1000) bc.InsDataAfter(3000, "beautiful", dataptr) # Print content print "Changed:" for dataid, data in bc: print data, print
Parameters: | id ( int ) – The ID of the element. |
---|---|
Return type: | PyCObject |
Returns: | A pointer to the data. |
BaseContainer.
GetBool
(
id
[
,
preset=False
]
)
¶
Returns a bool value with the specified ID, or preset if it doesn’t exist.
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
The value. |
BaseContainer.
GetLong
(
id
[
,
preset=0
]
)
¶
Deprecated since version R15:
Use
GetInt32()
instead.
Returns a int value with the specified ID, or preset if it doesn’t exist.
Parameters: |
|
---|---|
Return type: |
int |
Returns: |
The value. |
BaseContainer.
GetInt32
(
id
[
,
preset=0
]
)
¶
New in version R15.037.
Returns a int value with the specified ID, or preset if it doesn’t exist.
Parameters: |
|
---|---|
Return type: |
int |
Returns: |
The value. |
BaseContainer.
GetLLong
(
id
[
,
preset=0L
]
)
¶
Deprecated since version R15:
Use
GetInt64()
instead.
Returns a long value with the specified ID, or preset if it doesn’t exist.
Parameters: |
|
---|---|
Return type: |
long |
Returns: |
The value. |
BaseContainer.
GetInt64
(
id
[
,
preset=0L
]
)
¶
New in version R15.037.
Returns a long value with the specified ID, or preset if it doesn’t exist.
Parameters: |
|
---|---|
Return type: |
long |
Returns: |
The value. |
BaseContainer.
GetReal
(
id
[
,
preset=0.0
]
)
¶
Deprecated since version R15:
Use
GetFloat()
instead.
Returns a float value with the specified ID, or preset if it doesn’t exist.
Parameters: |
|
---|---|
Return type: |
float |
Returns: |
The value. |
BaseContainer.
GetFloat
(
id
[
,
preset=0.0
]
)
¶
New in version R15.037.
Returns a float value with the specified ID, or preset if it doesn’t exist.
Parameters: |
|
---|---|
Return type: |
float |
Returns: |
The value. |
BaseContainer.
GetVector
(
id
[
,
preset=c4d.Vector()
]
)
¶
Returns a
Vector
value with the specified ID, or
preset
if it doesn’t exist.
Parameters: |
|
---|---|
Return type: | |
Returns: |
The value. |
BaseContainer.
GetMatrix
(
id
[
,
preset=c4d.Matrix()
]
)
¶
Returns a
Matrix
value with the specified ID, or
preset
if it doesn’t exist.
Parameters: |
|
---|---|
Return type: | |
Returns: |
The value. |
BaseContainer.
GetString
(
id
[
,
preset=”“
]
)
¶
Returns a string value with the specified ID, or preset if it doesn’t exist.
Parameters: |
|
---|---|
Return type: |
str |
Returns: |
The value. |
BaseContainer.
GetFilename
(
id
[
,
preset=”“
]
)
¶
Returns a string value with the specified ID, or preset if it doesn’t exist.
Parameters: |
|
---|---|
Return type: |
str |
Returns: |
The value. |
BaseContainer.
GetUuid
(
id
[
,
preset
]
)
¶
New in version R16.021.
Returns a uuid value with the specified ID, or preset if it doesn’t exist.
Parameters: |
|
---|---|
Return type: | |
Returns: |
The value. |
BaseContainer.
GetTime
(
id
[
,
preset=c4d.BaseTime()
]
)
¶
Returns a
BaseTime
value with the specified ID, or
preset
if it doesn’t exist.
Parameters: |
|
---|---|
Return type: | |
Returns: |
The value. |
BaseContainer.
GetContainer
(
id
)
¶
Returns a copy of the sub-container with the specified ID, or an empty container if it doesn’t exist.
Parameters: | id ( int ) – The ID of the requested sub-container. |
---|---|
Return type: | c4d.BaseContainer |
Returns: | The Sub-container. |
BaseContainer.
GetContainerInstance
(
id
)
¶
Returns the sub-container with the specified ID, or None if it doesn’t exist. Changes to the container are reflected in the stored sub-container.
Parameters: | id ( int ) – The ID of the requested sub-container. |
---|---|
Return type: | c4d.BaseContainer |
Returns: | The sub-container, or None . |
BaseContainer.
GetLink
(
id[, doc=None][, isinstanceof=0]
)
¶
Returns a linked object, evaluated in the attached document. If instanceof is specified, None is returned if the object is not of this type.
Parameters: |
|
---|---|
Return type: | |
Returns: |
The linked object, or None if the link is broken. |
BaseContainer.
GetObjectLink
(
id
[
,
doc=None
]
)
¶
Returns a linked base object, evaluated in the attached document. Returns None if the link doesn’t point to a base object.
Parameters: |
|
---|---|
Return type: | |
Returns: |
The linked base object, or None if the link is broken. |
BaseContainer.
GetMaterialLink
(
id
[
,
doc=None
]
)
¶
Returns a linked material object, evaluated in the attached document. Returns None if the link doesn’t point to a base object.
Parameters: |
|
---|---|
Return type: | |
Returns: |
The linked material object, or None if the link is broken. |
BaseContainer.
GetCustomDataType
(
id
)
¶
Returns a copy of the custom data type or None if it doesn’t exist.
Parameters: | id ( int ) – The ID of the requested sub-container. |
---|---|
Returns: | The custom data type. |
BaseContainer.
SetBool
(
id
,
b
)
¶
Sets a bool value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetLong
(
id
,
l
)
¶
Deprecated since version R15:
Use
SetInt32()
instead.
Sets an int value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetInt32
(
id
,
l
)
¶
New in version R15.037.
Sets an int value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetLLong
(
id
,
l
)
¶
Deprecated since version R15:
Use
SetInt64()
instead.
Sets a long value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetInt64
(
id
,
l
)
¶
New in version R15.037.
Sets a long value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetReal
(
id
,
v
)
¶
Deprecated since version R15:
Use
SetFloat()
instead.
Sets a float value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetFloat
(
id
,
v
)
¶
New in version R15.037.
Sets a float value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetVector
(
id
,
v
)
¶
Sets a
Vector
value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetMatrix
(
id
,
m
)
¶
Sets a
Matrix
value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetString
(
id
,
s
)
¶
Sets a string value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetFilename
(
id
,
f
)
¶
Sets a new string value with the specified ID to s as a filepath, or inserts it if it didn’t exist.
Parameters: |
|
---|
BaseContainer.
SetUuid
(
id
,
u
)
¶
New in version R16.021.
Sets a uuid value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetTime
(
id
,
b
)
¶
Sets a
BaseTime
value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetContainer
(
id
,
s
)
¶
Sets a
BaseContainer
value and changes the data type accordingly.
Parameters: |
|
---|
BaseContainer.
SetLink
(
id
,
link
)
¶
Stores a link to an atom object with the specified ID.
Parameters: |
|
---|
BaseContainer.
GetIndexData
(
index
)
¶
New in version R16.038.
Retrieves the data for the element at index .
Parameters: | index ( int ) – The index of the element. |
---|---|
Return type: | any |
Returns: | The data, or None if no data was found. |
BaseContainer.
SetIndexData
(
index
,
data
)
¶
New in version R16.038.
Sets the data for the element at index .
Parameters: |
|
---|---|
Return type: |
bool |
Returns: |
True if the data was set, otherwise False . |
BaseContainer.
IsInstance
(
)
¶
Checks if the container is an instance.
Return type: | bool |
---|---|
Returns: | True if the container is an instance, otherwise False . |
BaseContainer.
MergeContainer
(
src
)
¶
Stores the values in src in this container, overwriting any elements with colliding IDs and keeping the rest.
Parameters: | src ( c4d.BaseContainer ) – The source container. |
---|
BaseContainer.
Sort
(
)
¶
Sorts the container entries by ID.