- UID
- 114481
- 积分
- 40
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-3-17
- 最后登录
- 1970-1-1
|
发表于 2004-8-13 15:33:50
|
显示全部楼层
这个可以的!
void ycreatedb()
{
AcDbDatabase *pDb = new AcDbDatabase();
AcDbBlockTable *pBtbl;
pDb->getSymbolTable(pBtbl, AcDb::kForWrite);
AcDbBlockTableRecord *pBtblRcd;
pBtbl->getAt(ACDB_MODEL_SPACE, pBtblRcd,AcDb::kForWrite);
pBtbl->close();
//--------------------------------------------------------------------------
AcGePoint3d pt,pt1,pt2,point3,point4,pointcenter;
AcGePoint3dArray ptArray;
double Par=20,height=30.0,radius=15;
double slopy , cosy , siny;
double eps=0.0001;
AcGeVector3d normal(0.0,0.0,1.0);
if(acedGetPoint(NULL,"\n请输入起点:",asDblArray(pt1))!=RTNORM)
return;
pt=pt1;
ptArray.append(pt);
for(;;)
{
if(acedGetPoint(asDblArray(pt1),"\n请输入下一点:",asDblArray(pt2))!=RTNORM)
break;
pt=pt2;
ptArray.append(pt);
acutPrintf("\np1的坐标:%f,%f,%f",pt1.x,pt1.y,pt1.z);
acutPrintf("\np1的坐标:%f,%f,%f",pt2.x,pt2.y,pt2.z);
pointcenter.x=(pt2.x+pt1.x)/2.00;
pointcenter.y=(pt2.y+pt1.y)/2.00;
pointcenter.z=0.00;
slopy = atan2( ( pt1.y-pointcenter.y ),( pt1.x - pointcenter.x ) );
cosy = cos( slopy );
siny = sin( slopy );
Acad::ErrorStatus es;
AcGePoint2d arrowpoint,arrowpoint1;
arrowpoint.x=pointcenter.x;
arrowpoint.y=pointcenter.y;
arrowpoint1.x=arrowpoint.x-20.0*cosy;
arrowpoint1.y=arrowpoint.y-20.0*siny;
point3.x=pt1.x-radius*cosy;
point3.y=pt1.y-radius*siny;
point3.z=pt1.z;
point4.x=pt2.x+radius*cosy;
point4.y=pt2.y+radius*siny;
point4.z=pt2.z;
AcDbLine *Line= new AcDbLine(point3,point4);//画线
Line->setColorIndex(7);
acedGrDraw(asDblArray(pt1),asDblArray(pt2),-1,0); //在屏幕上画出连接Ptl,Pt2的向量用来显示画线过程
pBtblRcd->appendAcDbEntity(Line);
Line->close();
AcDbPolyline * arrPLine = new AcDbPolyline(2);
es= arrPLine->addVertexAt(0,arrowpoint1,0.0,0,10);
es= arrPLine->addVertexAt(1,arrowpoint);
pBtblRcd->appendAcDbEntity(arrPLine);
arrPLine->close();
AcDbCircle *Circle = new AcDbCircle(pt1,normal,radius);
pBtblRcd->appendAcDbEntity(Circle);
Circle->close();
pt1=pt2;
}
AcDbCircle * cire = new AcDbCircle(pt2,normal,radius);
pBtblRcd->appendAcDbEntity(cire);
cire->close();
pBtblRcd->close();
pDb->saveAs("vengraph.dwg");
delete pDb;
acutPrintf("\n完成读取数据库,退出程序!");
}
// This is command 'READDB'
void yreaddb()
{
AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);
// 向AcDbDatabase 构造函数传递kFlase参数,
if(pDb->readDwgFile("vengraph.dwg")!=Acad::eOk)
{
acutPrintf("\n 不能打开指定文件,退出程序!");
return;
}
// 打开模型空间记录.
AcDbBlockTable *pBlkTbl;
pDb->getSymbolTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,AcDb::kForRead);
pBlkTbl->close();
AcDbBlockTableRecordIterator *pBlkTblRcdItr;
pBlkTblRcd->newIterator(pBlkTblRcdItr);
AcDbEntity *pEnt;
for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done();pBlkTblRcdItr->step())
{
pBlkTblRcdItr->getEntity(pEnt,
AcDb::kForRead);
acutPrintf("类名: %s\n",(pEnt->isA())->name());
pEnt->close();
}
pBlkTblRcd->close();
delete pBlkTblRcdItr;
delete pDb;
acutPrintf("\n完成读取数据库,退出程序!");
}
// This is command 'LTDB'
void yltdb()
{
CString xdbh,strSql;
int index3=0;
int p1;
double radius=15.0,spoly,siny,cosy;
double eps=0.001;
AcGePoint3d arrowpoint,textpoint1;
AcDbObjectId transId;
AcDbDatabase* pDb;
char *fname;
struct resbuf *rb;
// 获得用户需要的图形文件
rb = acutNewRb(RTSTR);
int stat = acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb);
if ((stat != RTNORM) || (rb == NULL))
{
acutPrintf("\n用户没有指定文件名,退出程序!");
return;
}
fname = (char*)acad_malloc(strlen(rb->resval.rstring) + 1);
strcpy(fname, rb->resval.rstring);
acutRelRb(rb);
// 打开指定文件.
pDb = new AcDbDatabase(Adesk::kFalse);
if (pDb->readDwgFile(fname) != Acad::eOk)
{
acutPrintf("\n文件已被其他用户打开,退出程序!");
return;
}
AcDbBlockTable *pBlockTable;
pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pOtherMsBtr;
pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb::kForRead);
pBlockTable->close();
// 创建一个迭代器.
AcDbBlockTableRecordIterator *pIter;
pOtherMsBtr->newIterator(pIter);
AcGePoint3d pt1,pt2;
// 创建一个对象ID队列,用于存储操作的ID对象.
AcDbObjectIdArray objIdArray;
//遍历块表记录找出所有直线
for (pIter->start(); !pIter->done(); pIter->step())
{
AcGePoint3d vertex;
AcDbEntity *pEntity;
pIter->getEntity(pEntity, AcDb::kForRead);
if (pEntity->isKindOf(AcDbLine::desc()))
{
index3++;
p1=index3+1;
AcDbLine *Line = (AcDbLine*&)pEntity;
pt1=Line->startPoint();
pt2=Line->endPoint();
acutPrintf("\n直线的起点是:%d,%f,%f,%f",index3,pt1.x,pt1.y,pt1.z);
acutPrintf("\n直线的终点是:%d,%f,%f,%f",p1,pt2.x,pt2.y,pt2.z);
spoly=atan2((pt1.y-pt2.y),(pt1.x-pt2.x));
siny=sin(spoly);
cosy=cos(spoly);
arrowpoint.x=(pt1.x+pt2.x)/2.0;
arrowpoint.y=(pt1.y+pt2.y)/2.0;
textpoint1.x=arrowpoint.x;
textpoint1.y=arrowpoint.y+radius;
textpoint1.z=pt1.z;
xdbh.Format("%d",index3);
AcDbObjectId text1Id;
AcDbText *jdbhText1 = new AcDbText(textpoint1,xdbh,text1Id,10,0);
postToDatabase(jdbhText1,text1Id);
AcDbObjectId text2Id;
AcDbText *jdbhText2 = new AcDbText(pt1,xdbh,text2Id,10,0);
postToDatabase(jdbhText2,text2Id);
objIdArray.append(pEntity->objectId());
}
if(pEntity->isKindOf(AcDbCircle::desc()))
{
objIdArray.append(pEntity->objectId());
}
pEntity->close();
}
delete pIter;
pOtherMsBtr->close();
if (objIdArray.isEmpty())
{
acad_free(fname);
acutPrintf("\n指定的图形文件中没有直线对象,退出程序!");
return;
}
AcDbBlockTable *pThisBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pThisBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pThisMsBtr;
pThisBlockTable->getAt(ACDB_MODEL_SPACE, pThisMsBtr, AcDb::kForWrite);
pThisBlockTable->close();
AcDbObjectId id = pThisMsBtr->objectId();
pThisMsBtr->close();
// 创建长事务管理器实例,并调出外部数据库的实体。
AcDbIdMapping errorMap;
acapLongTransactionManagerPtr()->checkOut(transId, objIdArray, id, errorMap);
//调用Zoom命令使修改的实体位于屏幕中央,便于观察。
if(acedCommand(RTSTR,"zoom",RTSTR,"e",0)!=RTNORM)
return;
// 修改调出实体的颜色。
int colorIndex;
acedGetInt("\n请输入新颜色: ", &colorIndex);
AcDbObject* pObj;
if (acdbOpenObject(pObj, transId, AcDb::kForRead) == Acad::eOk)
{
// 获得长事务指针
AcDbLongTransaction* pLongTrans = AcDbLongTransaction::cast(pObj);
if (pLongTrans != NULL)
{
// 获得长事务工作集迭代器。
AcDbLongTransWorkSetIterator* pWorkSetIter;
pLongTrans->newWorkSetIterator(pWorkSetIter);
// 遍历工作集中的实体,并修改它们的颜色。
for (pWorkSetIter->start(); !pWorkSetIter->done(); pWorkSetIter->step())
{
AcDbEntity *pEntity;
acdbOpenAcDbEntity(pEntity, pWorkSetIter->objectId(), AcDb::kForWrite);
pEntity->setColorIndex(colorIndex);
pEntity->close();
}
delete pWorkSetIter;
}
pObj->close();
}
// 暂停并观察修改后的结果。
char str[132];
acedGetString(0, "\n观察颜色。按enter键将修改后的实体写回原数据库。", str);
// 将修改后的实体写回原数据库。
acapLongTransactionManagerPtr()->checkIn(transId, errorMap);
pDb->saveAs(fname);
delete pDb;
pDb = NULL;
acad_free(fname);
} |
|