UserDataBlob.ByteArray
 
 
 

UserDataBlob.ByteArray operator

Introduced

v8.0 (2010)

Description

Sets or returns binary user data on the UserDataBlob as a SafeArray of unsigned bytes. The preferred language for working with this property is Python.

The data is copied internally and will be persisted as part of the scene. There are no limits to the size or structure of this data. Internally, the UserDataBlob.Value, UserDataBlob.Array32 and the ByteArray properties refer to the same data. However, for the sake of clarity, use only one or the other across your plug-in.

The UserDataBlob.Array32 property is an optimization of the ByteArray property and the preferred language for working with these two properties is Python.

The returned value may appear unexpected for a given scripting language. No matter what the final representation is, the returned container contains one element per stored byte, and the value is in the 0-255 range.

Warning: For clarity, the ByteArray property accepts only SafeArray objects and fails if given any other kind of data. In Python, the recommended data structure is array.array('B'). In JScript, native arrays are accepted. Python and JScript arrays are internally converted to SafeArray objects. In addition, each element of the safe array is converted to a byte internally. If such a conversion is impossible, setting the property fails and the data remains unchanged.

Note: Make sure you are setting a safe array of unsigned byte values (in the 0-255 range) in order to preserve the data appropriately.

C# Syntax

// get accessor
Object rtn = UserDataBlob.ByteArray;
// set accessor
UserDataBlob.ByteArray = Object;

Examples

Python Example

# Setting the data using UserDataBlob.ByteArray
#
import array
Application.NewScene("", False)
n = Application.GetPrim("Null", "", "", "")
Application.CreateModel("", "", "", "")
blob = n.AddProperty("UserDataBlob", False, "Bytes");
# Create an array of bytes and set it as the blob data
#
WriteArray = array.array('B', [1,3,5,7]);
blob.ByteArray = WriteArray;
# Retrieve the data. In Python, the data comes back as a tuple
#
BlobTuple = blob.ByteArray;
# Convert it back to an array
#
ReadArray = array.array('B');
ReadArray.fromlist(list(BlobTuple));
Application.LogMessage("ReadArray  = " + str(ReadArray));
# Expected results:
# INFO : ReadArray  = array('B', [1, 3, 5, 7])

See Also

UserDataBlob.Array32 UserDataBlob.Value UserDataItem.Value CustomProperty.BinaryData CustomProperty.AddParameter