v2.0
How to work with properties

Overview

The object property mechanism available in Renga allows to attach arbitrary properties to objects. Renga itself does not interpret such properties, but stores them in the project and provides access to their values. You can learn more about object properties in Renga help.

Renga API provides two main interfaces to work with the properties. To create and manage object properties in the project use the IPropertyManager interface, available via IProject::GetPropertyManager(). To get or set property values for a given object use the IPropertyContainer interface, available via the IModelObject::GetProperties() method.

How to create and manage the properties

C++

Renga::IPropertyManagerPtr pPropertyManager = pProject->GetPropertyManager();
Renga::PropertyDescription propertyDescription;
propertyDescription.name = L"Sample property";
propertyDescription.type = Renga::PropertyType_String;
GUID attributeUuid;
::CoCreateGuid(&attributeUuid);
// Register the property in Renga:
const auto hr = pPropertyManager->RegisterProperty(attributeUuid, propertyDescription);
if (FAILED(hr))
return;
// Assign the property to the Level object type:
hr = pPropertyManager->AssignPropertyToType(attributeUuid, Renga::ObjectTypes::Level);
if (FAILED(hr))
return;
// All levels in the project now have the property named "Sample property".

C#

Renga.PropertyDescription propertyDescription = new Renga.PropertyDescription();
propertyDescription.name ="Sample property";
propertyDescription.type = Renga.PropertyType.PropertyType_String;
Guid attributeUuid = Guid.NewGuid();
// Register property in Renga:
propertyManager.RegisterProperty(attributeUuid, propertyDescription);
// Assign property to the Level object type:
propertyManager.AssignPropertyToType(attributeUuid, Renga.ObjectTypes.Level);
// All levels in the project now have the property named "Sample property".

How to set the property value

To set the value of the property use the IOperation interface. Note that Renga only allows to alter objects between calls to IOperation::Start() and IOperation::Apply().

C++

Renga::IModelPtr pModel = pProject->GetModel();
Renga::IModelObjectCollectionPtr pModelObjectCollection = pModel->GetObjects();
Renga::IOperationPtr pOperation = pModel->CreateOperation();
auto hr = pOperation->Start();
if (FAILED(hr))
return;
for (int i = 0; i < pModelObjectCollection->GetObjectCount(); ++i)
{
Renga::IModelObjectPtr pModelObject = pModelObjectCollection->GetObjectByIndex(i);
if (pModelObject->GetObjectType() == Renga::ObjectTypes::Level)
{
Renga::IPropertyContainerPtr pPropertyContainer = pModelObject->GetProperties();
pPropertyContainer->GetProperty(attributeUuid)->SetStringValue(L"Test value");
}
}
pOperation->Apply();

C#

Renga.IModel model = project.GetModel();
Renga.IModelObjectCollection modelObjectCollection = model.GetObjects();
Renga.IOperation operation = model.CreateOperation();
operation.Start();
for (int i = 0; i < modelObjectCollection.GetObjectCount(); ++i)
{
Renga.IModelObject modelObject = modelObjectCollection.GetObjectByIndex(i);
if (modelObject.GetObjectType() == Renga.ObjectTypes.Level)
{
Renga.IPropertyContainer propertyContainer = modelObject.GetProperties();
propertyContainer.GetProperty(attributeUuid).SetStringValue("Test value");
}
}
operation.Apply();

See also

Related samples

  • ObjectProperties