v2.0
How to obtain object quantities

Overview

A quantity is a derived measure of a model object's physical property. To get quantities of an object use the IQuantityContainer interface, available via the IModelObject::GetQuantities() and ILayer::GetQuantities() methods. A quantity can be obtained via IQuantityContainer::GetQuantity(). To check if a quantity is available for an object use the IQuantityContainer::HasQuantity() method.

How to obtain the quantities

The code below demonstrates how to obtain the net volume quantity from an arbitrary model object.

C++

void obtainQuantityContainer(Renga::IModelObjectPtr pModelObject)
{
Renga::IQuantityContainerPtr pQuantityContainer = pModelObject->GetQuantities();
Renga::IQuantityPtr pQuantity = pQuantityContainer->GetQuantity(Renga::QuantityIds::NetVolume);
if (pQuantity)
{
if (pQuantity->GetType() == Renga::QuantityType_Volume)
{
const double volume = pQuantity->AsVolume(Renga::VolumeUnit_Meters3);
// TODO: Some actions based on the volume.
}
else
{
// The object does support the NetVolume quantity, but the quantity value could not be calculated.
}
}
else
{
// The object does not support the NetVolume quantity.
}
}

C#

public void obtainQuantityContainer(Renga.IModelObject modelObject)
{
Renga.IQuantityContainer quantityContainer = modelObject.GetQuantities();
Renga.IQuantity quantity = quantityContainer.GetQuantity(Renga.QuantityIds.NetVolume);
if (quantity != null)
{
if (quantity.GetType() == Renga.QuantityType.QuantityType_Volume)
{
const double volume = quantity.AsVolume(Renga.VolumeUnit.VolumeUnit_Meters3);
// TODO: Some actions based on the volume.
}
else
{
// The object does support the NetVolume quantity, but the quantity value could not be calculated.
}
}
else
{
// The object does not support the NetVolume quantity.
}
}

How to work with quantities

The code below demonstrates how to obtain the net cross section area quantity from beam model objects.

C++

Renga::IApplicationPtr pApplication = Renga::CreateApplication();
if (!pApplication)
return;
Renga::IProjectPtr pProject = pApplication->GetProject();
Renga::IModelPtr pModel = pProject->GetModel();
Renga::IModelObjectCollectionPtr pModelObjectCollection = pModel->GetObjects();
for (int i = 0; i < pModelObjectCollection->GetObjectCount(); ++i)
{
Renga::IModelObjectPtr pModelObject = pModelObjectCollection->GetObjectByIndex(i);
const GUID type = pModelObject->GetObjectType();
continue;
Renga::IQuantityContainerPtr pQuantityContainer = pModelObject->GetQuantities();
Renga::IQuantityPtr pQuantity = pQuantityContainer->GetQuantity(Renga::QuantityIds::CrossSectionArea);
const double crossSectionAreaValueInMeters2 = pQuantity->AsArea(Renga::AreaUnit_Meters2);
// TODO: work with the value
}

C#

Renga.IApplication application = new Renga.Application();
Renga.IProject project = application.GetProject();
Renga.IModel model = project.GetModel();
Renga.IModelObjectCollection modelObjectCollection = model.GetObjects();
for (int i = 0; i < modelObjectCollection.GetObjectCount(); ++i)
{
Renga.IModelObject modelObject = modelObjectCollection.GetObjectByIndex(i);
Guid type = modelObject.GetObjectType();
if (type != Renga.ObjectTypes.Beam)
continue;
Renga.IQuantityContainer quantityContainer = modelObject.GetQuantities();
Renga.IQuantity quantity = quantityContainer.GetQuantity(Renga.QuantityIds.CrossSectionArea);
double crossSectionAreaValueInMeters2 = quantity.AsArea(Renga.AreaUnit.AreaUnit_Meters2);
// TODO: work with the value
}

See also

Related samples

  • ModelObjectQuantities