Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Lightweight Polylines > Example of Working with the Lightweight Polyline Object
Example of Working with the Lightweight Polyline Object

This example demonstrates adding a lightweight polyline in a block table record.


void DbFiller::addPolyline(const OdDbObjectId& btrId, 
                           const int boxRow,
                           const int boxCol,
                           const OdDbObjectId& layerId,
                           const OdDbObjectId& styleId)
{
  OdDbBlockTableRecordPtr bBTR = btrId.safeOpenObject(OdDb::kForWrite);

  /* Get the Upper-left corner of the box and its size */
  
  OdGePoint3d point = m_EntityBoxes.getBox(boxRow, boxCol);
  double h = m_EntityBoxes.getHeight();
  double w = m_EntityBoxes.getWidth(boxRow, boxCol);
  
  
  /* Add the label */
  
  addTextEnt(bBTR,
    point + m_textOffset, point + m_textOffset, 
    OD_T("LWPOLYLINE"), m_textSize, OdDb::kTextLeft, OdDb::kTextTop, layerId, styleId );

  /* Get the lower-left corner of the box */

  point.y -= h;

  /* Create a polyline */

  OdDbPolylinePtr pPolyline = OdDbPolyline::createObject();
  pPolyline->setDatabaseDefaults(bBTR->database());
  bBTR->appendOdDbEntity(pPolyline);

  /* Create the vertices */

  double dx = w / 8.0;
  double dy = h / 8.0;

  OdGePoint2d point2d(point.x + 1.5*dx, point.y + 3.0*dy);

  pPolyline->addVertexAt(0, point2d);

  point2d.y -= 0.5*dy;
  pPolyline->addVertexAt(1, point2d);
  pPolyline->setBulgeAt(1, 1.0);

  point2d.x += 5.0*dx;
  pPolyline->addVertexAt(2, point2d);

  point2d.y += 4.0*dy;
  pPolyline->addVertexAt(3, point2d);

  point2d.x -= 1.0*dx;
  pPolyline->addVertexAt(4, point2d);

  point2d.y -= 4.0*dy;
  pPolyline->addVertexAt(5, point2d);
  pPolyline->setBulgeAt(5, -1.0);
  
  point2d.x -= 3.0*dx;
  pPolyline->addVertexAt(6, point2d);

  point2d.y += 0.5*dy;
  pPolyline->addVertexAt(7, point2d);

  /* Make the polyline closed */

  pPolyline->setClosed(true);
}

See Also

Working with Lightweight Polylines

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