How to work with properties


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


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


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().


Renga::IModelPtr pModel = pProject->GetModel();
Renga::IModelObjectCollectionPtr pModelObjectCollection = pModel->GetObjects();
Renga::IOperationPtr pOperation = pModel->CreateOperation();
auto hr = pOperation->Start();
if (FAILED(hr))
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");


Renga.IModel model = project.Model;
Renga.IModelObjectCollection modelObjectCollection = model.GetObjects();
Renga.IOperation operation = model.CreateOperation();
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");

See also

Related samples

  • ObjectProperties
@ PropertyType_String
Property is a string.
Definition: IPropertyType.idl:20
const GUID Level
Level object type.
Definition: ObjectTypes.h:36