Disable osnap points for entities residing in block drawn by custom entity

By Adam Nagy

We have a custom entity derived from AcDbEntity that draws a given block table record:

Adesk::Boolean MyBlockEnt::subWorldDraw (AcGiWorldDraw *mode) 
{
  assertReadEnabled();
 
  if (!m_blockId.isNull())
  {
    AcDbBlockTableRecordPointer ptrMB(m_blockId, AcDb::kForRead);
    mode->geometry().draw(ptrMB);
  }
 
  return (Adesk::kTrue);
}

We also implement the subGetOsnapPoints function to provide our own snap points:

Acad::ErrorStatus MyBlockEnt::subGetOsnapPoints(
  AcDb::OsnapMode osnapMode, Adesk::GsMarker gsSelectionMark,
  const AcGePoint3d& pickPoint, const AcGePoint3d& lastPoint,
  const AcGeMatrix3d& viewXform, AcGePoint3dArray& snapPoints,
  AcDbIntArray& geomIds, const AcGeMatrix3d& insertionMat) const
{
  snapPoints.append(m_snapPoint);
 
  return Acad::eOk; 
}

In 2d Wireframe mode only the point we provide can be snapped to, which is the behaviour we'd like to see in the other modes like Shaded view as well. However, there the osnap points of the entities residing in the block our entity is drawing can also be snapped to. How could we avoid that?

Solution

Your entity should also implement the AcDbEntity::subIsContentSnappable like so:

bool MyBlockEnt::subIsContentSnappable() const
{
  return false;
}

Comments

3 responses to “Disable osnap points for entities residing in block drawn by custom entity”

  1. Great job Adam.
    I have a question, how to insert the entity in right position? Because by default the position always origin.
    Thank you.

  2. Great, that’s works,thank you Adam.

Leave a Reply to EricCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading