Autodesk ObjectARX
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Help Me Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi everyone!
I'm coding for Insert Block from file DWG to Current Drawing autocad. But error.
anyone Modify my code
Thanks
void Block()
{
ACHAR* szName = _T("luanuoc");
ACHAR *fileName = _T("C:\\procad\\dwg\\luanuoc.dwg");
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
AcDbDatabase *pBlockDb = new AcDbDatabase(false,true);
pBlockDb ->readDwgFile(fileName,_SH_DENYRW,true);
AcDbBlockTable *BlkTable;
AcDbObjectId BlkId;
//AcDbObjectIdArray Ids = new AcDbObjectIdArray();
//BlkId =pBlockDb ->blockTableId();
BlkTable ->getAt(ACDB_MODEL_SPACE,BlkId,AcDb::kForRead);
pDb->insert(BlkId,szName,pBlockDb,true);
if (BlkTable->has(BlkId))
{
ads_point p;
acedGetPoint(NULL,"Chon diem chen",p);
AcGePoint3d Inspoint(p[X],p[Y],p[Z]);
AcDbBlockReference *pBlockobj = new AcDbBlockReference;
AcDbBlockTableRecord *pBlkTablerec;
pBlockobj ->setBlockTableRecord(BlkId);
pBlockobj ->setPosition(Inspoint);
pBlockobj ->setScaleFactors(1);
BlkTable ->getAt(ACDB_MODEL_SPACE,pBlkTablerec,AcDb::kForWr
BlkTable ->close();
pBlkTablerec ->appendAcDbEntity(pBlockobj);
pBlkTablerec ->close();
pBlockobj ->close();
}
}
Solved! Go to Solution.
Re: Help Me Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
What is the error?
Owen Wengerd
ManuSoft
Re: Help Me Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Error Insert Block. Can you help me?
Re: Help Me Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Sorry, I don't understand what the problem is.
Owen Wengerd
ManuSoft
Re: Help Me Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
xuanhuynh wrote:
Error Insert Block. Can you help me?
Owen asked you about error code. IMHO it is a Fatal Error because of using non-initialize variable BlkTable in line:
BlkTable ->getAt(ACDB_MODEL_SPACE,BlkId,AcDb::kForRead);
Re: Help Me Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks, I fixed this error.
But I have this code for create Block with two Attributes. Then Insert this Block into drawing.
But erro they missing Attributes when i insertBlock:
1. I use Function TaoBLKDCC2 for create Block and add to Database( this very good)
2. Then Use function InsertKH1 for Insert Block with name DCC21 into Drawing with two Attributes( this function error, not have attributes
Can you help me? thank very much!
void
ProcadUtil::TaoBLKDCC2()
{
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase() ->getBlockTable(pBlkTbl, AcDb::kForWrite);
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTblRcd = new AcDbBlockTableRecord();
/*char blkName[40];
if (acedGetString(Adesk::kFalse, "\nNhap ten Block:", blkName) != RTNORM)
{
pBlkTbl->close();
delete pBlkTblRcd;
return;
} */
pBlkTblRcd->setName("DCC21");
AcDbObjectId blkDefId;
pBlkTbl->add(blkDefId, pBlkTblRcd);
pBlkTbl->close();
AcGePoint3d ptStart, ptEnd;
ptStart =ProcadUtil:
olarPoint(AcGePoint3d::kOrigin,3*ProcadUtil:
I()/4,1.41421);
ptEnd =ProcadUtil:
olarPoint(ptStart,0,2);
AcDbLine *pLine1 = new AcDbLine(ptStart, ptEnd);
ptStart =ProcadUtil:
olarPoint(ptEnd,3*ProcadUtil:
I()/2,2);
AcDbLine *pLine2 = new AcDbLine(ptEnd, ptStart);
ptEnd =ProcadUtil:
olarPoint(ptStart,ProcadUtil:
I(),2);
AcDbLine *pLine3 = new AcDbLine(ptStart, ptEnd);
ptStart =ProcadUtil:
olarPoint(ptEnd,ProcadUtil:
I()/2,2);
AcDbLine *pLine4 = new AcDbLine(ptEnd, ptStart);
ptStart=ProcadUtil:
olarPoint(AcGePoint3d::kOrigin,0,1);
ptEnd =ProcadUtil:
olarPoint(ptStart,0,0.68);
AcDbLine *pLine5 = new AcDbLine(ptStart, ptEnd);
ptStart=ProcadUtil:
olarPoint(AcGePoint3d::kOrigin,ProcadUtil:
I()/2,1);
ptEnd =ProcadUtil:
olarPoint(ptStart,ProcadUtil:
I()/2,0.68);
AcDbLine *pLine6 = new AcDbLine(ptStart, ptEnd);
ptStart=ProcadUtil:
olarPoint(AcGePoint3d::kOrigin,ProcadUtil:
I(),1);
ptEnd =ProcadUtil:
olarPoint(ptStart,ProcadUtil:
I(),0.68);
AcDbLine *pLine7 = new AcDbLine(ptStart, ptEnd);
ptStart=ProcadUtil:
olarPoint(AcGePoint3d::kOrigin,3*ProcadUtil:
I()/2,1);
ptEnd =ProcadUtil:
olarPoint(ptStart,3*ProcadUtil:
I()/2,0.68);
AcDbLine *pLine8 = new AcDbLine(ptStart, ptEnd);
ptStart=ProcadUtil:
olarPoint(AcGePoint3d::kOrigin,0,2.68);
ptEnd =ProcadUtil:
olarPoint(ptStart,0,8);
AcDbLine *pLine9 = new AcDbLine(ptStart, ptEnd);
AcGeVector3d vecNormal(0, 0, 1);
AcDbCircle *pCircle = new AcDbCircle(AcGePoint3d::kOrigin,vecNormal, 0.1);
AcGePoint3d BasePoint = ProcadUtil::asAc3d(ptStart);
AcDbAttributeDefinition *pAttDef1 = new AcDbAttributeDefinition;
//pAttDef1->setPosition(ProcadUtil:
olarPoint(ptStart,ProcadUtil:
I()/2,0.5));
ptStart = ProcadUtil:
olarPoint(BasePoint,ProcadUtil:
I()/2,0.5);
pAttDef1->setPosition(ptStart);
pAttDef1->setPrompt("TENDIEM");
pAttDef1->setTag("TENDIEM");
//pAttDef1->setTextStyle(_T("chudcc2"));
pAttDef1->setHeight(2);
//pAttDef1->setAlignmentPoint()
pAttDef1->setHorizontalMode(AcDb::TextHorzMode::kT
pAttDef1->setVerticalMode(AcDb::TextVertMode::kTex
pAttDef1->setLayer("TenDiem");
AcDbAttributeDefinition *pAttDef2 = AcDbAttributeDefinition::cast(pAttDef1->clone()) ;
//pAttDef1->setPosition(ProcadUtil:
olarPoint(ptStart,ProcadUtil:
I()/2,0.5));
ptStart = ProcadUtil:
olarPoint(BasePoint,3*ProcadUtil:
I()/2,2.5);
pAttDef2->setPosition(ptStart);
pAttDef2->setPrompt("DOCAO");
pAttDef2->setTag("DOCAO");
//pAttDef1->setTextStyle("chudcc2");
pAttDef2->setHeight(2);
//pAttDef1->setAlignmentPoint()
pAttDef2->setHorizontalMode(AcDb::TextHorzMode::kT
pAttDef2->setVerticalMode(AcDb::TextVertMode::kTex
pAttDef2->setLayer("DoCao");
AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId, pLine1);
pBlkTblRcd->appendAcDbEntity(entId, pLine2);
pBlkTblRcd->appendAcDbEntity(entId, pLine3);
pBlkTblRcd->appendAcDbEntity(entId, pLine4);
pBlkTblRcd->appendAcDbEntity(entId, pLine5);
pBlkTblRcd->appendAcDbEntity(entId, pLine6);
pBlkTblRcd->appendAcDbEntity(entId, pLine7);
pBlkTblRcd->appendAcDbEntity(entId, pLine8);
pBlkTblRcd->appendAcDbEntity(entId, pLine9);
pBlkTblRcd->appendAcDbEntity(entId, pCircle);
pBlkTblRcd->appendAcDbEntity(entId, pAttDef1);
pBlkTblRcd->appendAcDbEntity(entId, pAttDef2);
pLine1->close();
pLine2->close();
pLine3->close();
pLine4->close();
pLine5->close();
pLine6->close();
pLine7->close();
pLine8->close();
pLine9->close();
pCircle->close();
pAttDef1->close();
pAttDef2->close();
pBlkTblRcd->close();
}
//Ham convert diem ads_point -> AcGePoint3d
AcGePoint3d
ProcadUtil::asPnt3d(ads_point &pt)
{
AcGePoint3d pInsert;
pInsert[X] = pt[X];
pInsert[Y] = pt[Y];
pInsert[Z] = pt[Z];
return(pInsert);
}
//-------------------------
AcGePoint3d
ProcadUtil:
olarPoint(const AcGePoint3d& pt, double angle,double distance)
{
ads_point ptForm, ptTo;
ptForm[X] = pt.x;
ptForm[Y] = pt.y;
ptForm[Z] = pt.z;
acutPolar(ptForm, angle, distance, ptTo);
return ProcadUtil::asPnt3d(ptTo);
}
double
ProcadUtil:
I()
{
return 4 * atan(1.0);
}
AcGePoint3d
ProcadUtil::asAc3d(const AcGePoint3d& pt)
{
AcGePoint3d p1;
p1[X]=pt[X];
p1[Y]=pt[Y];
p1[Z]=pt[Z];
return p1 ;
}
void
ProcadUtil::InsertKH1(TCHAR *szBlock, TCHAR *szDwg, double x, double y, double elev,int stt, double Tile,double goc)
{
AcGePoint3d Inspoint(x,y,elev);
AcDbBlockTable *pBlkTable=NULL;
AcDbBlockTableRecord *pBlkTablerec;
AcDbDatabase *pCurDb = NULL;
AcGeScale3d TileScale(Tile,Tile,Tile);
pCurDb = acdbHostApplicationServices()->workingDatabase();
pCurDb ->getSymbolTable(pBlkTable,AcDb::kForRead);
AcDbObjectId BlkId;
pBlkTable ->getAt(szBlock,BlkId);
if(pBlkTable->has(szBlock))
{
AcDbBlockReference *pBlockobj = new AcDbBlockReference;
pBlockobj ->setBlockTableRecord(BlkId);
pBlockobj ->setPosition(Inspoint);
pBlockobj ->setScaleFactors(Tile);
pBlkTable ->getAt(ACDB_MODEL_SPACE,pBlkTablerec,AcDb::kForWr
pBlkTable ->close();
AcDbObjectId pEntId;
pBlkTablerec ->appendAcDbEntity(pEntId,pBlockobj);
pBlkTablerec ->close();
AcDbObjectIterator *pBlkRefAttItr=pBlockobj->attributeIterator();
for (pBlkRefAttItr->start(); !pBlkRefAttItr->done();pBlkRefAttItr->step())
{
AcDbObjectId attObjId;
attObjId = pBlkRefAttItr->objectId();
AcDbAttribute *pAtt = NULL;
Acad::ErrorStatus es = acdbOpenObject(pAtt, attObjId, AcDb::kForRead);
if (es != Acad::eOk)
{
acutPrintf(_T("\nLoi khong mo duoc attribute"));
delete pBlkRefAttItr;
continue;
}
if (strcmp(pAtt->tag(),"TENDIEM") == 0)
{
pAtt->setTextString("DC12");
}
if (strcmp(pAtt->tag(),"DOCAO:") == 0)
{
pAtt->setTextString("12.63");
}
pBlockobj->appendAttribute(pAtt);
pAtt->close();
}
delete pBlkRefAttItr;
pBlockobj->close();
}
}
Re: Help Me Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Help Me Insert Block
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I Fixed this error.
Thank you very much.



