Announcements

We are currently experiencing an issue impacting some Autodesk Products and Services - please refer to the Autodesk Health Dashboard for updates.

Associative hatch

Associative hatch

karl.sch1983
Advocate Advocate
234 Views
2 Replies
Message 1 of 3

Associative hatch

karl.sch1983
Advocate
Advocate

I have spent all day trying to make an associative hatch and it just doesn't work. It says it is associative in properties panel but doesn't behave as one. I came across this but have not tried it yet. I think it should be possible to make associative hatch without involving reactors. Can anyone point me in the right direction. I am not sure what I am doing wrong. Please help. Note that the boundary is a simple close polyline.

bool AssociativeHatch(const AcDbObjectId& bdryId)
{
	AcDbHatch* pHatch = new AcDbHatch();
	pHatch->setDatabaseDefaults();
	pHatch->setAssociative(Adesk::kTrue);
	
	AcDbObjectIdArray boundaryIds;
	boundaryIds.append(bdryId);

	pHatch->appendLoop(AcDbHatch::kExternal, boundaryIds);
	pHatch->setPattern(AcDbHatch::kPreDefined, _T("_SOLID"));
	pHatch->evaluateHatch();

	AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
	AcDbBlockTable* pBlockTable = NULL;
	AcDbBlockTableRecord* pMSpaceRecord = NULL;
	pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
	pBlockTable->getAt(ACDB_MODEL_SPACE, pMSpaceRecord, AcDb::kForWrite);

	AcDbObjectId hatchId;
	pMSpaceRecord->appendAcDbEntity(hatchId, pHatch);
	pMSpaceRecord->close();

	pHatch->close();
	return true;
}

 

0 Likes
Accepted solutions (1)
235 Views
2 Replies
Replies (2)
Message 2 of 3

daniel_cadext
Advisor
Advisor
Accepted solution

AcDbHatch doc show to use addPersistentReactor

https://help.autodesk.com/view/OARX/2024/ENU/?guid=OARX-RefGuide-AcDbHatch

 

  static void createHatch(void)
  {
      auto ERR = [](Acad::ErrorStatus es)
          {
              if (es != Acad::eOk)
                  acutPrintf(_T("Error: %ls"), acadErrorStatusText(es));
          };

      ads_name ename;
      ads_point point;
      if (RTNORM != acedEntSel(_T("\nSelect rec: "), ename, point))
          return;

      AcDbObjectId objId;
      ERR(acdbGetObjectId(objId, ename));
      AcDbObjectIdArray dbObjIds;
      AcDbEntityPointer pEnt(objId);
      dbObjIds.append(pEnt->objectId());
      AcDbBlockTableRecordPointer pBtr(ACDB_MODEL_SPACE, curDoc()->database(), AcDb::kForWrite);
      ERR(pBtr.openStatus());
      AcDbObjectPointer<AcDbHatch> pHatch;
      ERR(pHatch.create());
      pHatch->setDatabaseDefaults();
      ERR(pHatch->setAssociative(Adesk::kTrue));
      ERR(pHatch->setPattern(AcDbHatch::kPreDefined, _T("_SOLID")));
      ERR(pHatch->setHatchStyle(AcDbHatch::kNormal));
      AcDbObjectId hatchId;
      ERR(pBtr->appendAcDbEntity(hatchId, pHatch));
      ERR(pHatch->appendLoop(AcDbHatch::kExternal, dbObjIds));
      ERR(pHatch->evaluateHatch());
      ERR(pEnt->upgradeOpen());
      ERR(pEnt->addPersistentReactor(hatchId));
  }
Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 3 of 3

karl.sch1983
Advocate
Advocate

Thanks Daniel. That worked. I just wasn't sure if there was a different approach available other than the persistent reactor route. Thanks again.

0 Likes