Close

Relief for ODA Team in Ukraine

Learn more
ODA BimRv SDK
Create Sweep Elements

Introduction

This section describes how to create sweep elements. Sweep representation is based on the idea of moving a contour along some path. A relatively constrained geometry of a sweep shape means that only a small dataset is needed to specify it. An example of a sweep element is presented below.

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

The workflow of creating a sweep element looks something like this:

  1. Get access to a database;
  2. Get a valid sketch plane for a sweep path from the database;
  3. Create an array of curves for a sweep path;
  4. Create a sweep profile from one or several loops of curves;
  5. Set a profile curve index;
  6. Set a profile plane location;
  7. Start a transaction;
  8. Add the created element to the loaded 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 for a path 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 an array of curves for sweep path

A simple path with just two GLine elements is used here. You need to pay attention about these things: sweep path consists of contiguous curves, this set of curves may be closed or open, but must not have any intersections.


OdBmGCurvePtrArray path;
OdBmGLinePtr pGLine = OdBmGLine::createObject();
OdBmGLinePtr pGLine2 = OdBmGLine::createObject();
pGLine->set(OdGePoint3d(-36, 0, 0), OdGePoint3d(27, 10, 0));
pGLine2->set(OdGePoint3d(27, 10, 0), OdGePoint3d(29, 30, 0));
path.append(pGLine);
path.append(pGLine2);
        

Create a sweep profile loop

Just as for paths, there are some restrictions for profiles:

  • Curve loops must lie on a plane that is orthogonal to the path's plane;
  • A profile must have at least one outer loop (you may add inner loops) without intersections and it must be closed;

There is a specific case, when profile loops are so big you may have an error in sweep creation. This error can be easily explained: on the step of moving a profile along a path there will occur an intersection of profiles, the one that was previously moved and the one that is being moved.

Below you can find an example that should not cause any errors:


OdArray<OdBmGCurvePtrArray> profile;
//points
OdGePoint3d pnt1(0, 0, 0);
OdGePoint3d pnt2(0, 5, 0);
OdGePoint3d pnt3(5, 5, 0);
OdGePoint3d pnt4(5, 0, 0);
OdBmGCurvePtrArray arrCurvesOfLoop;
//profile loop
OdBmGLinePtr pProfileGLine1 = OdBmGLine::createObject();
pProfileGLine1->set(pnt1, pnt2);
OdBmGLinePtr pProfileGLine2 = OdBmGLine::createObject();
pProfileGLine2->set(pnt2, pnt3);
OdBmGLinePtr pProfileGLine3 = OdBmGLine::createObject();
pProfileGLine3->set(pnt3, pnt4);
OdBmGLinePtr pProfileGLine4 = OdBmGLine::createObject();
pProfileGLine4->set(pnt4, pnt1);
arrCurvesOfLoop.append(pProfileGLine1);
arrCurvesOfLoop.append(pProfileGLine2);
arrCurvesOfLoop.append(pProfileGLine3);
arrCurvesOfLoop.append(pProfileGLine4);
profile.append(arrCurvesOfLoop);
        

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

The last step of the sweep element creation is to create a new OdBmSweepElem object, add it to a database, and pass all the data created in previous steps to the set() method.


OdBmSweepElemPtr pSweep = OdBmSweepElem::createObject();
ODBM_TRANSACTION_BEGIN(t, pDb);
t.start();
pDb->addElement(pSweep);
OdResult err = pSweep->set(true, path, idSketchPlane, profile, 0, OdBm::ProfilePlaneLocation::Start);
if (eOk == err)
  t.commit();
else
  t.rollback();
ODBM_TRANSACTION_END();
        

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

The resulting object should look like the following object:

See Also

Create Blend Elements

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