Close

Relief for ODA Team in Ukraine

Learn more
ODA BimRv SDK
Create Blend Elements

Introduction

This section describes how to create blend elements. An OdBmBlendElem object is essentialy a shape that is created from two loops. The first one is a top contour and the second one is a bottom contour. To connect these contours you can use your own set of vertex connections, otherwise a default vertex mapping will be used. As an example, a blend element may look like this: a top contour is represented by a darker polygon, and a bottom contour by a lighter one. Lines between vertices are vertex connections, which can be customized.

The functionality for working with blend elements is implemented within the OdBmBlendElem class. To create a blend element, you need to use the set() method.

The workflow of creating such an element looks something like this:

  1. Get access to a database;
  2. Get a valid sketch plane from the database;
  3. Create 2 closed contours (they must belong to the same plane);
  4. Create a set of vertex connections or use an empty one (in the latter case a default vertex mapping will be used);
  5. Create a new OdBmBlendElem object;
  6. Set the BLEND_START_PARAM and BLEND_END_PARAM parameters for your OdBmBlendElem object;
  7. Open a transaction;
  8. Add the created element to the database;
  9. Commit the transaction;

Below, you can find an example with code fragments.

Access a database

First of all, you need to initialize a command context object, and then access database through it.


OdBmCommandContextPtr pDbCmdCtx(pCmdCtx);
OdBmDatabase* pDb = pDbCmdCtx->database();
        

Get a valid sketch plane from the database

In this example an active sketch plane is used.


OdSmartPtr<OdBmUserIO> pIO = pDbCmdCtx->userIO();
OdBmObjectId idSketchPlane = pDb->getActiveSketchPlaneId();
if (idSketchPlane == (OdBmObjectId)NULL) {
  pIO->putString(OD_T("Invalid sketch plane"));
  return;
}
OdBmObjectPtr pObj = idSketchPlane.safeOpenObject();
if (pObj->isA() != OdBmSketchPlane::desc()) {
  pIO->putString(OD_T("The object is not SketchPlane"));
  return;
}
         

Create a set of vertex connections or use an empty one

No custom mappings are used in this example, so the latter option is chosen.

Create two contours

In this example the curves are represented by lines that connect certain points. There are 2 loops created - the top and the bottom. Curves are formed into loops in the code section below:


OdBmCurveLoopPtr baseLoop = OdBmCurveLoop::createObject();
OdBmCurveLoopPtr topLoop = OdBmCurveLoop::createObject();
OdGePoint3d pnt1(0, 0, 0);
OdGePoint3d pnt2(0, 5, 0);
OdGePoint3d pnt3(5, 5, 0);
OdGePoint3d pnt4(5, 0, 0);
OdGePoint3d pnt5(0, 0, 0);
OdGePoint3d pnt6(0, 8, 0);
OdGePoint3d pnt7(8, 8, 0);
OdGePoint3d pnt8(8, 0, 0);
OdBmGLinePtr pBotGLine1 = OdBmGLine::createObject();
pBotGLine1->set(pnt1, pnt2);
baseLoop->append(pBotGLine1);
OdBmGLinePtr pBotGLine2 = OdBmGLine::createObject();
pBotGLine2->set(pnt2, pnt3);
baseLoop->append(pBotGLine2);
OdBmGLinePtr pBotGLine3 = OdBmGLine::createObject();
pBotGLine3->set(pnt3, pnt4);
baseLoop->append(pBotGLine3);
OdBmGLinePtr pBotGLine4 = OdBmGLine::createObject();
pBotGLine4->set(pnt4, pnt1);
baseLoop->append(pBotGLine4);
OdBmGLinePtr pTopGLine1 = OdBmGLine::createObject();
pTopGLine1->set(pnt5, pnt6);
topLoop->append(pTopGLine1);
OdBmGLinePtr pTopGLine2 = OdBmGLine::createObject();
pTopGLine2->set(pnt6, pnt7);
topLoop->append(pTopGLine2);
OdBmGLinePtr pTopGLine3 = OdBmGLine::createObject();
pTopGLine3->set(pnt7, pnt8);
topLoop->append(pTopGLine3);
OdBmGLinePtr pTopGLine4 = OdBmGLine::createObject();
pTopGLine4->set(pnt8, pnt5);
topLoop->append(pTopGLine4);
         

Create an object and add it to the database through a transaction

First of all, create a new OdBmBlendElem object and open a transaction. In an opened transaction you need to add the newly created pBlendElem to the database, set the BLEND_START_PARAM and BLEND_END_PARAM parameters and, at last, call a method to create a blend geometry. Also, in this case, a custom thickness value from a keyboard is used. After that, don't forget to commit the transaction.


OdBmBlendElemPtr pBlendElem = OdBmBlendElem::createObject();
ODBM_TRANSACTION_BEGIN(tr, pDb);
tr.start();
pDb->addElement(pBlendElem);
double thickness = pIO->getReal("Enter thickness of blend:", OdEd::kInpDefault, 30.0);
pBlendElem->set(true, baseLoop, topLoop, idSketchPlane, 0.0, thickness);
tr.commit();
ODBM_TRANSACTION_END();
         

If the transaction completed without any errors, it's safe to say that a blend element was successfully created. Now, you can save this database to a new file with any given name.

Don't forget to include all necessary header files. You can find the full source code in BimRv/Examples/TB_DevGuideCommands/BmDocCreateBlendCmd.cpp in the function _BmCreateBlendCmd_func().

See Also

Create Sweep Elements

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.