Hello!
Can't add AcDbMPolygon entity to the drawing, upon calling blockTableRecord->appendAcDbEntity (objId, pEnt) it throws an unhandled exception. What is wrong with my code? TIA
...
AcGePoint2dArray mpolPoints;
int arrIndex;
arrIndex = mpolPoints.append(powP1);
arrIndex = mpolPoints.append(powP2);
arrIndex = mpolPoints.append(powP3);
AcGeDoubleArray bulges;
//bulges.append(0);bulges.append(0);bulges.append(0);
AcDbMPolygon *mPol = new AcDbMPolygon();
es = mPol->appendMPolygonLoop(mpolPoints, bulges, FALSE, 10);
if (es != Acad::eOk) return (es);
AcDbObjectId objId1;
es = postToDwgAndClose(mPol, objId1, NULL, NULL);
if (es != Acad::eOk) return (es);
....
Acad::ErrorStatus postToDwgAndClose (AcDbEntity *pEnt, AcDbObjectId objId, AcDbDatabase *pDb, ACHAR *requiredSpace)
{
if (pDb == NULL) pDb = acdbCurDwg();
AcDbBlockTable *blockTable = NULL;
Acad::ErrorStatuses = pDb->getBlockTable (blockTable, AcDb::kForRead);
if (es != Acad::eOk) return (es);
AcDbBlockTableRecord *blockTableRecord = NULL;
if (requiredSpace) {
es = blockTable->getAt (requiredSpace, blockTableRecord, AcDb::kForWrite);
}
else
{
es = acdbOpenObject(blockTableRecord, pDb->currentSpaceId(), AcDb::kForWrite);
}
blockTable->close();
if (es != Acad::eOk) return (es);
es = blockTableRecord->appendAcDbEntity (objId, pEnt);//unhandled exception
if (es != Acad::eOk) return (es);
blockTableRecord->close();
pEnt->close();
return (es);
}
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Check if AcMPolygonObjNN.dbx is loaded before your's code is running (NN is 17 for AutoCAD 2007...2009, is 18 for AutoCAD 2010...2012, is 19 for AutoCAD 2013...)
If it is not loaded then load it with code such as acrxLoadModule(_T("AcMPolygonObjNN.dbx"),false);
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
What is the stack trace at the point where the exception occurs? Have you tried to simplify the code by appending an uninitialized new AcDbMPolygon? There are numerous potential memory and open object leaks in your code, so I'm suspicious that the problem is coming from somehwere else in your code, or from an earlier execution of the same code.
Loaded .dbx, now it says INTERNAL ERROR: !dbobji.cpp@6769: eNotOpenForWrite; Obviously I'm missing some code portion for opening the db object correctly. Unfortunatelly, can't find any sample dealing with AcDbMPolygon (strange enough in oarx2007 this class is not completely documented).
@dnlo wrote:
Loaded .dbx, now it says INTERNAL ERROR: !dbobji.cpp@6769: eNotOpenForWrite; Obviously I'm missing some code portion for opening the db object correctly. Unfortunatelly, can't find any sample dealing with AcDbMPolygon (strange enough in oarx2007 this class is not completely documented).
Are you trying to use AcDbMPolygon with AutoCAD 2007? As far as I remember there was a bug with that version of ObjectARX and AcDbMPolygon.
But eNotOpenForWrite means that you trying modify object that opened read-only.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Yes, I do.
This error originates from the code that follows AcDbMPolygon creation i.e. when adding hatch pattern stuff: namely somewhere in the commented block - I'm currently investigating this..
AcCmColor color;
color.setColorIndex(10);
es = mPol->setPatternAngle(45);
//es = mPol->setPatternDouble(false);
//es = mPol->setPatternScale(1.5);
//es = mPol->setPatternColor(color);
//es = mPol->setPatternSpace(1.5);
//es = mPol->setPattern(AcDbHatch::kPreDefined, _T("ANSI31"));
//es = mPol->evaluateHatch();
Generally speaking the MPolygon original issue has been resolved by loading .dbx module - Thanks Alexander. However, some odd AcGePoint2dArray behavoiur remains - it seems that the last point value is not appended to the polygon loop, at least in acad editor it marks only 3 points instead of 4. Why?
AcGePoint2dArray mpolPoints;
int arrIndex;
arrIndex = mpolPoints.append(powP1);
arrIndex = mpolPoints.append(powP2);
arrIndex = mpolPoints.append(powP3);
arrIndex = mpolPoints.append(powP4);
AcGeDoubleArray bulges;
AcDbMPolygon *mPol = newAcDbMPolygon();
es = mPol->appendMPolygonLoop(mpolPoints, bulges, FALSE, 10);
if (es != Acad::eOk) return (es);
@dnlo wrote:[...]However, some odd AcGePoint2dArray behavoiur remains - it seems that the last point value is not appended to the polygon loop, at least in acad editor it marks only 3 points instead of 4. Why?[...]
I hope all points are different... Also this may be due to errors with AcDbMPolygon in AutoCAD 2007
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Resolved: error was produced because mPol entity was closed in postToDwgWithObjId (mPol, objId1, NULL, NULL); function.
... blockTableRecord->close(); //pEnt->close(); return (es); ...
Commenting the line and closing the object after hatch pattern manipulations solved the issue.
@Alexander.Rivilis wrote:@dnlo wrote:[...]However, some odd AcGePoint2dArray behavoiur remains - it seems that the last point value is not appended to the polygon loop, at least in acad editor it marks only 3 points instead of 4. Why?[...]I hope all points are different... Also this may be due to errors with AcDbMPolygon in AutoCAD 2007
Yes, points are different. Just added some fictious point (nr 5) to the array to enable the 4th vertex.