v2.36
 
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++

auto pPropertyManager = pProject->GetPropertyManager();
Renga::PropertyDescription propertyDescription;
propertyDescription.Name = L"Sample property";
propertyDescription.Type = Renga::PropertyType_String;
GUID attributeUuid;
::CoCreateGuid(&attributeUuid);
auto pOperation = pProject->CreateOperation();
pOperation->Start();
// Register the property in Renga:
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;
pOperation->Apply();
// All levels in the project now have the property named "Sample property".
const GUID Level
Level object type.
Definition ObjectTypes.h:36

C#

Renga.PropertyDescription propertyDescription = new Renga.PropertyDescription();
propertyDescription.Name = "Sample property";
propertyDescription.Type = Renga.PropertyType.PropertyType_String;
Guid attributeUuid = Guid.NewGuid();
Renga.IOperation operation = project.CreateOperation();
operation.Start();
// Register property in Renga:
propertyManager.RegisterProperty(attributeUuid, propertyDescription);
// Assign property to the Level object type:
propertyManager.AssignPropertyToType(attributeUuid, Renga.ObjectTypes.Level);
operation.Apply();
// 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();
auto pOperation = pProject->CreateOperation();
pOperation->Start();
for (int i = 0; i < pModelObjectCollection->Count; ++i)
{
Renga::IModelObjectPtr pModelObject = pModelObjectCollection->GetByIndex(i);
if (pModelObject->GetObjectType() == Renga::ObjectTypes::Level)
{
Renga::IPropertyContainerPtr pPropertyContainer = pModelObject->GetProperties();
pPropertyContainer->Get(attributeUuid)->SetStringValue(L"Test value");
}
}
pOperation->Apply();

C#

Renga.IModel model = project.Model;
Renga.IModelObjectCollection modelObjectCollection = model.GetObjects();
Renga.IOperation operation = project.CreateOperation();
operation.Start();
for (int i = 0; i < modelObjectCollection.Count; ++i)
{
Renga.IModelObject modelObject = modelObjectCollection.GetByIndex(i);
if (modelObject.ObjectType == Renga.ObjectTypes.Level)
{
Renga.IPropertyContainer propertyContainer = modelObject.GetProperties();
propertyContainer.Get(attributeUuid).SetStringValue("Test value");
}
}
operation.Apply();

See also

Related samples

  • ObjectProperties