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();
auto hr = pPropertyManager->RegisterProperty(attributeUuid, propertyDescription);
if (FAILED(hr))
return;
if (FAILED(hr))
return;
pOperation->Apply();
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();
propertyManager.RegisterProperty(attributeUuid, propertyDescription);
propertyManager.AssignPropertyToType(attributeUuid, Renga.ObjectTypes.Level);
operation.Apply();
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);
{
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