Author Topic: AcDbBlockReference and fields  (Read 2840 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
AcDbBlockReference and fields
« on: April 25, 2010, 01:36:50 AM »
I've been using a modified version of the addBlockWithAttributes sample in the docs for the longest time,
I just noticed that it doesn't copy over fields from the AcDbAttributeDefinition to the AcDbAttribute...

Anyone know how to do this?

Thanks

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: AcDbBlockReference and fields
« Reply #1 on: April 25, 2010, 09:38:01 AM »
this works...

Code: [Select]
Acad::ErrorStatus BlockWorker::CopyFields(AcDbAttributeDefinition *pAttdef, AcDbAttribute *pAtt  )
{
  Acad::ErrorStatus es = Acad::eOk;
  AcDbObjectId fieldId;
  AcDbDictionaryPointer pDict(pAttdef->getFieldDictionary(), AcDb::kForRead);
  if(pDict.openStatus() == Acad::eOk)
  {
    std::auto_ptr<AcDbDictionaryIterator> pDictIter(pDict->newIterator());
    for(;!pDictIter->done();pDictIter->next())
    {
      AcDbObjectPointer<AcDbField> pField(pDictIter->objectId(),AcDb::kForWrite);
      if( (es = pField.openStatus()) != Acad::eOk)
      {
        acutPrintf(_T("\nFailed to open Field :\nLine %ld [%s] In function %s "),
          __LINE__, acadErrorStatusText(es),_T(__FUNCTION__));
        continue;
      }

      AcDbField *pNewField = new AcDbField(
        pField->getFieldCode(AcDbField::kAddMarkers),pField->isTextField());

      if(pField == NULL)
      {
        es = Acad::eNullObjectPointer;
        acutPrintf(_T("\nFailed to create Field  :\nLine %ld [%s] In function %s "),
          __LINE__, acadErrorStatusText(es),_T(__FUNCTION__));
        continue;
      }

      if( (es = pNewField->postInDatabase(m_pDb)) != Acad::eOk)
      {
        acutPrintf(_T("\nFailed to add Field to Database :\nLine %ld [%s] In function %s "),
          __LINE__, acadErrorStatusText(es),_T(__FUNCTION__));
        delete pNewField;
        continue;
      }

      if( (es = pAtt->setField(pDictIter->name(),pNewField,fieldId)) != Acad::eOk)
      {
        acutPrintf(_T("\nFailed to set Field :\nLine %ld [%s] In function %s "),
          __LINE__, acadErrorStatusText(es),_T(__FUNCTION__));
        continue;
      }

      if( (es = pNewField->evaluate(0,0))  != Acad::eOk)
      {
        acutPrintf(_T("\nFailed to evaluate Field :\nLine %ld [%s] In function %s "),
          __LINE__, acadErrorStatusText(es),_T(__FUNCTION__));
      }

      if( (es = pNewField->close()) != Acad::eOk)
      {
        acutPrintf(_T("\nFailed to close Field :\nLine %ld [%s] In function %s "),
          __LINE__, acadErrorStatusText(es),_T(__FUNCTION__));
      }
    }
  }
  return es;
}
« Last Edit: April 25, 2010, 09:48:44 AM by Daniel »