v2.44
 
How to create and delete object

How to create object

The object can be created with IModel::CreateObject() method and INewEntityArgs interface. The INewEntityArgs interface contains a set of all the necessary arguments that may be required to create various object types. For example, to create a Column on a level, you need to set the INewEntityArgs::TypeId field equal to the column type, and the INewEntityArgs::HostObjectId equal to the level where you want to place the object. You can read more about it in the description of the INewEntityArgs interface.

Additionally, you can:

Example code for creating an object

C++

// With Building or Assembly model
auto pArgs = pModel->CreateNewEntityArgs();
pArgs->HostObjectId = AnyLevelId;
// Optional: set a style for stylable objects
// pArgs->StyleId = AnyStyleId;
// Optional: create a linked object by specifying an absolute file path
// pArgs->TypeId = Renga::EntityTypes::LinkedImage;
// pArgs->FilePath = L"D:\\assets\\logo.png";
auto pOperation = m_pApp->Project->StartOperation();
auto pNewObject = pModel->CreateObject(pArgs);
pOperation->Apply();
const GUID Column
Column object type.
Definition EntityTypes.h:154

C#

// With Building or Assembly model
var args = model.CreateNewEntityArgs();
args.TypeId = Renga.EntityTypes.Column;
args.HostObjectId = AnyLevelId;
// Optional: set a style for stylable objects
// args.StyleId = anyStyleId;
// Optional: create a linked object by specifying an absolute file path
// args.TypeId = Renga.EntityTypes.LinkedImage;
// args.FilePath = "D:\\assets\\logo.png";
var operation = m_app.Project.StartOperation();
var newObject = model.CreateObject(args);
operation.Apply();

How to delete object

The object can be deleted with IModel::DeleteObjectById() or IModel::DeleteObjectByUniqueId() method. Note that if the object being deleted has dependent objects, they will be deleted along with it.

Example code for deleting an object

C++

// With any model
auto pOperation = m_pApp->Project->CreateOperation();
pOperation->Start();
pModel->DeleteObjectById(objectForDeletionId);
pModel->DeleteObjectByUniqueId(objectForDeletionUniqueId);
pOperation->Apply();

C#

// With any model
var operation = m_app.Project.CreateOperation();
operation.Start();
model.DeleteObjectById(objectForDeletionId);
model.DeleteObjectByUniqueId(objectForDeletionUniqueId);
operation.Apply();

See also

Related samples

  • ObjectCreation
  • ObjectDeletion