这有效...
- 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 pDictIter(pDict->newIterator());
- for(;!pDictIter->done();pDictIter->next())
- {
- AcDbObjectPointer 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;
- }
|