天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 69|回复: 0

文件DWG到当前图形autocad的插入块

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
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::PolarPoint(AcGePoint3d::kOrigin,3*ProcadUtil::PI()/4,1.41421);
ptEnd =ProcadUtil::PolarPoint(ptStart,0,2);
AcDbLine *pLine1 = new AcDbLine(ptStart, ptEnd);

ptStart =ProcadUtil::PolarPoint(ptEnd,3*ProcadUtil::PI()/2,2);
AcDbLine *pLine2 = new AcDbLine(ptEnd, ptStart);

ptEnd =ProcadUtil::PolarPoint(ptStart,ProcadUtil::PI(),2);
AcDbLine *pLine3 = new AcDbLine(ptStart, ptEnd);

ptStart =ProcadUtil::PolarPoint(ptEnd,ProcadUtil::PI()/2,2);
AcDbLine *pLine4 = new AcDbLine(ptEnd, ptStart);

ptStart=ProcadUtil::PolarPoint(AcGePoint3d::kOrigin,0,1);
ptEnd =ProcadUtil::PolarPoint(ptStart,0,0.68);
AcDbLine *pLine5 = new AcDbLine(ptStart, ptEnd);

ptStart=ProcadUtil::PolarPoint(AcGePoint3d::kOrigin,ProcadUtil::PI()/2,1);
ptEnd =ProcadUtil::PolarPoint(ptStart,ProcadUtil::PI()/2,0.68);
AcDbLine *pLine6 = new AcDbLine(ptStart, ptEnd);

ptStart=ProcadUtil::PolarPoint(AcGePoint3d::kOrigin,ProcadUtil::PI(),1);
ptEnd =ProcadUtil::PolarPoint(ptStart,ProcadUtil::PI(),0.68);
AcDbLine *pLine7 = new AcDbLine(ptStart, ptEnd);

ptStart=ProcadUtil::PolarPoint(AcGePoint3d::kOrigin,3*ProcadUtil::PI()/2,1);
ptEnd =ProcadUtil::PolarPoint(ptStart,3*ProcadUtil::PI()/2,0.68);
AcDbLine *pLine8 = new AcDbLine(ptStart, ptEnd);

ptStart=ProcadUtil::PolarPoint(AcGePoint3d::kOrigin,0,2.68);
ptEnd =ProcadUtil::PolarPoint(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::PolarPoint(ptStart,ProcadUtil::PI()/2,0.5));
ptStart = ProcadUtil::PolarPoint(BasePoint,ProcadUtil::PI()/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::kTextLeft);
pAttDef1->setVerticalMode(AcDb::TextVertMode::kTextBase);
pAttDef1->setLayer("TenDiem");

AcDbAttributeDefinition *pAttDef2 = AcDbAttributeDefinition::cast(pAttDef1->clone()) ;
//pAttDef1->setPosition(ProcadUtil::PolarPoint(ptStart,ProcadUtil::PI()/2,0.5));
ptStart = ProcadUtil::PolarPoint(BasePoint,3*ProcadUtil::PI()/2,2.5);
pAttDef2->setPosition(ptStart);
pAttDef2->setPrompt("DOCAO");
pAttDef2->setTag("DOCAO");
//pAttDef1->setTextStyle("chudcc2");
pAttDef2->setHeight(2);
//pAttDef1->setAlignmentPoint()
pAttDef2->setHorizontalMode(AcDb::TextHorzMode::kTextLeft);
pAttDef2->setVerticalMode(AcDb::TextVertMode::kTextBase);
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::PolarPoint(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::PI()
{
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::kForWrite);
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();
}
}

 

 

 

 

文件DWG到当前图形autocad的插入块
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 12:35 , Processed in 0.131766 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表