- UID
- 34921
- 积分
- 99
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-3-11
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2003-4-21 21:34:10
|
显示全部楼层
我写的是由建筑平面图纸,生成三维实体的arx程序,自己写了1500行左右,各个小程序都写好了,但是将小的程序连成大的程序的过成中,毛病多多阿,下面是一些小的函数,不介意就那去看看:
Adesk::Boolean myslope(char *lyrWall,char *lyrWindo, float &wid)//有个问题,门窗都在lyrWindo中
{
int i,j;
int irc;
float firstY,firstX,secondY,secondX,thirdY,thirdX,fourY,fourX;//xy坐标的差
long lenSS = 0, lenWindo = 0;
//float wid = 180.0;
ads_name ssEntName, sel, en;
AcGePoint2d firstPoint,secondPoint,thirdPoint,fourPoint;
// AcGePoint2d st2Point, ed2Point;
ads_point pt1,pt2,pt3,pt4;//与firstPoint,thirdPoint对应
ads_name selPoint;//作测试用
long lenPoint;//作测试用
struct resbuf *pointList;
//作测试用
AcGePoint2d windoPoint1,windoPoint2;
char *layerWindo = "lyrWindo";//要新建的图层
char *layerDoor = "lyrDoor";//要新建的图层
AcGePoint2dArray splineArray;
irc = getLine(sel, lenSS, lyrWall, wid);//得到180的线段,如果有180的直线没有对应的怎么办,没有这一点的容错
if(irc != Adesk::kTrue)
{
acutPrintf("\n 取得的180的线段不成功");
}
for(i = 0; i<lenSS-1; i++) //取第一条直线
{
if(acedSSName(sel, i, ssEntName) != RTNORM)
{
acutPrintf("\n no acedSSName");
}
irc = getLineStEdPoint(ssEntName);//得到起点和终点
if(irc != Adesk::kTrue)
{
acutPrintf("\n no getLineStEdPoint");
}
//下面是对这两点排序
if(ed2Point.x - st2Point.x >=0)//是secondPoint总是出现在右边或者上面
{
secondPoint = ed2Point;
firstPoint = st2Point;
}
else
{
secondPoint = st2Point;
firstPoint = ed2Point;
}
firstY = secondPoint.y - firstPoint.y;
firstX = secondPoint.x - firstPoint.x;
// acutPrintf("\n success1");
for(j = i+1; j<lenSS; j++) //去第二条直线
{
//取得第三点和第四点的坐标
acedSSName(sel, j, ssEntName);
irc = getLineStEdPoint(ssEntName);
if(irc != Adesk::kTrue)
{
acutPrintf("\n no getLineStEdPoint2");
}
if(ed2Point.x - st2Point.x >=0)//是secondPoint总是出现在右边或者上面
{
fourPoint = ed2Point;
thirdPoint = st2Point;
}
else
{
fourPoint = st2Point;
thirdPoint = ed2Point;
}
secondY = fourPoint.y - thirdPoint.y;
secondX = fourPoint.x - thirdPoint.x;
if((fabs(firstY - secondY) >1.0)||(fabs(secondX - firstX) > 1.0)) //判断两条直线是否平行,
{
}
// 如果不平行就继续在for循环中找出平行的
else//在上面就判断它是平行的了,在这要判断它是否两两垂直,只要判断两条直线垂直就行了
{
thirdX = firstPoint.x - thirdPoint.x;
thirdY = firstPoint.y - thirdPoint.y;
fourX = secondPoint.x - firstPoint.x;
fourY = secondPoint.y - firstPoint.y;
if((fabs(thirdX * fourX + thirdY * fourY)) > 1.0)
{
}
else//这上面就判断了垂直,
{
//lin(firstPoint,thirdPoint);
pt1[X] = firstPoint.x;
pt1[Y] = firstPoint.y;
pt1[Z] = 0;
pt2[X] = thirdPoint.x;
pt2[Y] = thirdPoint.y;
pt2[Z] = 0;
pt3[X] = secondPoint.x ;
pt3[Y] = secondPoint.y ;
pt3[Z] = 0;
pt4[X] = fourPoint.x ;
pt4[Y] = fourPoint.y ;
pt4[Z] = 0;
pointList = acutBuildList(RTPOINT,pt1,RTPOINT,pt2,RTPOINT,pt3,RTPOINT,pt4,0);
acedSSGet("F",pointList,NULL,NULL,selPoint); //与直线相交的实体,
////////////要将其它的图层关调的
acedSSLength(selPoint,&lenPoint);
acedSSFree(selPoint);
//acutPrintf("\n lenPont:%d",lenPoint);
if(lenPoint != 6.0)//排除的debug
{
//acutPrintf("\n sdk");
}
else//确定在哪个选择集中selWall,selWindo//已经定出了firstPoint和thirdPoint
{
splineArray.append(firstPoint);
splineArray.append(thirdPoint);
splineArray.append(fourPoint);
splineArray.append(secondPoint);
if(!drawSpline(splineArray))
{
acutPrintf("\nError drawing ");
}
splineArray.setLogicalLength(0);
acdbEntLast(en);
irc = chgEntToLayer(layerDoor, en);
if(irc != Adesk::kTrue)
{
acutPrintf("\n no chgEntToLayer");
}
}//else,画出多线段
}//else,垂直,画线
}//else,平行
}//for
}//for,将窗和门都放到lyrWindo中
/*
irc = chgToDoor(layerDoor,layerWindo, lyrWindo); //将layerWindo中满足条件的放入到layerDoor中
if(irc != Adesk::kTrue)
{
acutPrintf("\n no chToDoor");
}
*/
//并且得到现在layerWindo和layerDoor中的线条的数目
acedSSFree(sel);
//acutPrintf("\n sucess");
// copyCurLayer(layerDoor, layerWindo);
return Adesk::kTrue;
}//void
/*
Adesk::Boolean chgToDoor(char *layerDoor,char *layerWindo, char *lyrWindo)
{
assert(layerDoor != NULL);
assert(layerWindo != NULL);
ads_name selDoor,selWindo;
ads_name ssNameDoor,ssNameWindo;
long lenDoor,lenWindo;
int i, j,num,k;
int irc;
//char *lyrWindo = "window";///////在该程序的时候,这是重点
AcDbObjectId entId;
AcDbPolyline *pEnt;//要close
AcGePoint2dArray pointArray;
AcGePoint3d point3d;
AcGePoint2d point2d;
//AcGePolyline2d acgePlyLine;
AcGePoint2d stPoint,edPoint;
// AcGePoint2d st2Point,ed2Point;
AcGePolyline2d acgePlyLine;
AcGeTol tol ;
getSelSet(selDoor, lenDoor, layerDoor);//取得door土层的线条,是AcDbPolyline对象
for(i = 0; i<lenDoor; i++)//要判断点是否在一条线上
{
if(acedSSName(selDoor, i, ssNameDoor) != RTNORM)
{
acutPrintf("\n no get ssName");
}//取得selDoor中的第i各实体,将ssNameDoor变为指针
//getLineStEdPoint(ssNameDoor);//这里也不能,,why 这是因为,getLineStEdPoint是对直线来的,而ssNameDoor是pline线
Acad::ErrorStatus es = acdbGetObjectId(entId, ssNameDoor);
if(es != Acad::eOk)
{
acutPrintf("\n no get entId");
}
es = acdbOpenObject(pEnt,entId,AcDb::kForRead);//这是得到AcDb对象,但是我要的是AcGe对象
if(es != Acad::eOk)
{
acutPrintf("\n no openobjectid");
}
//acdbOpenObject和 acdbOpenAcDbEntity
num = pEnt->numVerts();
for(k = 0; k<num; k++)//构造出一条多线段 问题:中间会有no point出现
{
es = pEnt->getPointAt(k,point2d);
if(es != Acad::eOk)
{
acutPrintf("\n no getPointAt");
}
pointArray.append(point2d);
}
AcGePolyline2d acgePlyLine(pointArray);//这是构造函数
pointArray.setLogicalLength(0);
pEnt->close();
//acutPrintf("\n acgePlyLine的点个数为:%d",acgePlyLine.numFitPoints());
getSelSet(selWindo, lenWindo, lyrWindo);
for(j = 0; j<lenWindo; j++)//对点进行判断
{
if(acedSSName(selWindo, j, ssNameWindo) != RTNORM)
{
acutPrintf("\n no acedSSName");
}
irc = getLineStEdPoint(ssNameWindo);
if(irc != Adesk::kTrue)
{
acutPrintf("\n no getLineStEdPoint");
}
//问题出在这里 why 因为 ssNameWindo中有的不是直线
stPoint = st2Point;
edPoint = ed2Point;//判断这两点是否在acgePlyLine上
if((acgePlyLine.isOn(stPoint,tol))&&(acgePlyLine.isOn(edPoint,tol)))
{
//acutPrintf("\n stpoint:%f",stPoint.x);
irc = chgEntToLayer(layerWindo,ssNameDoor);
if(irc != Adesk::kTrue)
{
acutPrintf("n no change entity to newLayer");
}
break;
}
}//for
acedSSFree(selWindo);
}//for
acedSSFree(selDoor);
return Adesk::kTrue;
}//void
*/
//调用了getLineStEdPoint()和getSelSet()
Adesk::Boolean getLine(ads_name selSetName, long &selSetLen, char *lpszSelLayer, float &fWid)
{
assert(lpszSelLayer != NULL);
ads_name ssEntName;
int rc,i;
float fDistance;
// AcGePoint2d st2Point;
// AcGePoint2d ed2Point;
getSelSet(selSetName, selSetLen, lpszSelLayer);//有numline输出
for (i=0;i<selSetLen;i++)
{
AcDbObjectId entityId;
rc = acedSSName(selSetName, i, ssEntName);
if(rc != RTNORM)
{
break;
}
rc= getLineStEdPoint(ssEntName);
if(rc != Adesk::kTrue)
{
acutPrintf("\n no getLineStEdPoint");
}
fDistance = st2Point.distanceTo(ed2Point);
if(fabs(fDistance-fWid) > 1.0)
{
if(acedSSDel(ssEntName,selSetName) != RTNORM)
{
acutPrintf("\n 失败 in 去掉线条上");
}
i = i - 1;
selSetLen = selSetLen - 1;
}
}
if(acedSSLength(selSetName,&selSetLen) != RTNORM)
{
acutPrintf("\n fail to get length");
}//取得线条的个数
acutPrintf("\n selSelLen:%d", selSetLen);
return Adesk::kTrue;
}
Adesk::Boolean getLineStEdPoint(ads_name ssEntName)//由选择集的名字来获得每条直线的起点和终点
{
int rc;
AcDbObjectId entityId;
AcGePoint3d ed3Point;
AcGePoint3d st3Point;
AcDbCurve *pEnt;//初始化指针
rc = acdbGetObjectId(entityId, ssEntName);//这是重点,与参考有出入
if(rc != Acad::eOk)
{
acutPrintf("\n no entityId");
}
rc = acdbOpenObject(pEnt,entityId,AcDb::kForRead);//得到了ssEntName的指针pEnt
if(rc != Acad::eOk)
{
acutPrintf("\n no open entity");
}
rc = pEnt->getEndPoint(ed3Point);
if(rc != Acad::eOk)
{
acutPrintf("\n no ed3Point");
}
rc = pEnt->getStartPoint(st3Point);//要将3dPoint转化为2dPoint
if(rc != Acad::eOk)
{
acutPrintf("\n no st3Point");
}
st2Point.set(st3Point.x,st3Point.y);
ed2Point.set(ed3Point.x,ed3Point.y);
pEnt->close();//AcDbLine *pEnt = NULL;//初始化指针
return Adesk::kTrue;
}
Acad::ErrorStatus AddEntityToAds(AcDbEntity *pEntity)
{
AcDbDatabase *pCurDb;// dbmain.h
Acad::ErrorStatus es;
pCurDb = acdbHostApplicationServices()->workingDatabase();// 数据库
AcDbBlockTable *pBlkTable;// dbsymtb.h 块表
es = pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("\nFailed to open Block Table for a read operation.");
return es;
}
AcDbBlockTableRecord *pBlkTblRecord;//*&可以改变地址 块表记录
es = pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTblRecord, AcDb::kForWrite);
if(es != Acad::eOk)
{
acutPrintf("\nFailed to open MODEL SPACE for a write operation.");
pBlkTable->close();
return es;
}
pBlkTable->close();
AcDbObjectId entityId; // 将实体对象写入块表记录
es = pBlkTblRecord->appendAcDbEntity(entityId,pEntity);
if(es != Acad::eOk)
{
acutPrintf("\n 没有加入");
return es;
}
pBlkTblRecord->close();
pEntity->close();
return es;
}
//以写的方式打开数据库,在这里没有关闭快表记录
Adesk::Boolean getModelSpaceRecord(AcDbBlockTableRecord*& pBlkTableRecord)
{
AcDbDatabase *pCurDb;
AcDbBlockTable *pBlkTable;
Acad::ErrorStatus es;
pCurDb = acdbHostApplicationServices()->workingDatabase();
es = pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("\nFailed to open Block Table for a read operation.");
return Adesk::kFalse;
}
es = pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTableRecord, AcDb::kForWrite);
if(es != Acad::eOk)
{
acutPrintf("\nFailed to open MODEL SPACE for a write operation.");
pBlkTable->close();
return Adesk::kFalse;
}
// We don't need the block table anymore so we can close it.
pBlkTable->close();
return Adesk::kTrue;
}
//在后面要释放调选择集 没有问题
Adesk::Boolean getSelSet(ads_name selSetName, long &selSetLen, char *lpszSelLayer)
{
assert(lpszSelLayer != NULL);
struct resbuf rbSSEnt;
char charLyrName[20];
int irc;
rbSSEnt.restype = 8;
strcpy(charLyrName, lpszSelLayer);
rbSSEnt.resval.rstring = charLyrName;
rbSSEnt.rbnext = NULL;
irc = acedSSGet("X", NULL, NULL, &rbSSEnt, selSetName);
if(irc != RTNORM)
{
acutPrintf("\n no entity 1");
return Adesk::kFalse;
}
acutRelRb(&rbSSEnt);
irc = acedSSLength(selSetName,&selSetLen);
if(irc != RTNORM)
{
acutPrintf("\n no selection length");
return Adesk::kFalse;
}
acutPrintf("\n selection set length:%d",selSetLen);
return Adesk::kTrue;
}
Adesk::Boolean drawSpline(AcGePoint2dArray splineArray)
{
AcDbPolyline *pSpline;
AcGePoint2d vrtxPt;
AcDbObjectId splineId;
Acad::ErrorStatus es;
AcDbBlockTableRecord *pBlkTblRecord;
pSpline = new AcDbPolyline(splineArray.length());
for(int count = 0; count < splineArray.length(); count++)
{
vrtxPt = splineArray.at(count);
pSpline->addVertexAt(count, vrtxPt);
}
pSpline->setClosed(Adesk::kTrue);
getModelSpaceRecord(pBlkTblRecord);
es = pBlkTblRecord->appendAcDbEntity(splineId, pSpline);
if(es != Acad::eOk)
{
acutPrintf("\nError in drawing frame member. ");
if(pSpline != NULL)
{
delete pSpline;
}
return Adesk::kFalse;
}
pSpline->close();
pBlkTblRecord->close();
return Adesk::kTrue;
}
//将en放到newlyrName中//lpszLyrName是新的图层,这有些局限性,最好能将en方入到已经有的图层中
Adesk::Boolean chgEntToLayer(char *lpszLyrName, ads_name en)
{
struct resbuf *ed,*cb;
//acdbEntLast(en);
ed=acdbEntGet(en);
for( cb=ed;cb!=NULL;cb=cb->rbnext)
if(cb->restype==8)
{
strcpy(cb->resval.rstring,lpszLyrName);
if(acdbEntMod(ed)!=RTNORM)
{
acutRelRb(ed);
return Adesk::kFalse;
}
break;
}
acutRelRb(ed);
return Adesk::kTrue;
}
Adesk::Boolean setCurLayer(char *lpszLyrName)//设置当前层
{
assert(lpszLyrName != NULL);//防错
//将lpszlyrName设为当前层,并且将其他的层关闭
AcDbLayerTable *pLyrTable;//不用释放,要关闭
AcDbLayerTableRecord *pLyrTblRecord;//不用释放,要关闭
AcDbObjectId lyrId;
Acad::ErrorStatus es;
AcDbDatabase *pCurDb;
pCurDb = acdbHostApplicationServices()->workingDatabase();
es = pCurDb->getLayerTable(pLyrTable, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("\n fail to open layer table for a read operation");
return Adesk::kFalse;
}
if(pLyrTable->has(lpszLyrName))
{
es = pLyrTable->getAt(lpszLyrName, pLyrTblRecord, AcDb::kForWrite, Adesk::kFalse);
if(es != Acad::eOk)
{
acutPrintf("\n fail to open layer table record");
return Adesk::kFalse;
}
}
else
{
acutPrintf("\n 没有这样的图层");
return Adesk::kFalse;
}
lyrId = pLyrTblRecord->objectId();//取得图层的Id
pLyrTblRecord->close();
pLyrTable->close();
//要将快表和快表记录关闭后才能将此层设为当前的层
es = pCurDb->setClayer(lyrId);
if(es != Acad::eOk)
{
acutPrintf("\n 没有设为当前图层");
return Adesk::kFalse;
}
return Adesk::kTrue;
}
Adesk::Boolean openLyrName(char *lpszLyrName)
{
assert(lpszLyrName != NULL);//防错
//将lpszlyrName设为当前层,并且将其他的层关闭
AcDbLayerTable *pLyrTable;//不用释放,要关闭
AcDbLayerTableRecord *pLyrTblRecord;//不用释放,要关闭
AcDbObjectId lyrId;
Acad::ErrorStatus es;
AcDbDatabase *pCurDb;
//关闭其他的层
es = pCurDb->getSymbolTable(pLyrTable, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("\n fail to open layer table for a read operation");
return Adesk::kFalse;
}
AcDbLayerTableIterator *pLyrIterator;//要释放
es = pLyrTable->newIterator(pLyrIterator);
if(es != Acad::eOk)
{
acutPrintf("\n 没有创建一个新");
return Adesk::kFalse;
}
char *lpszTempLyrName;
for(; !pLyrIterator->done(); pLyrIterator->step())//关闭图层
{
es = pLyrIterator->getRecord(pLyrTblRecord, AcDb::kForWrite);
if(es != Acad::eOk)
{
acutPrintf("\n 没有打开图层表记录");
continue;
//return Adesk::kFalse;
}
es = pLyrTblRecord->getName(lpszTempLyrName);
if(es != Acad::eOk)
{
acutPrintf("\n 没有取得层的名字");
continue;
//return Adesk::kFalse;
}
int rc;
rc = stricmp(lpszLyrName,lpszTempLyrName);
if(rc = 0)
{
pLyrTblRecord->setIsFrozen(false);
}
pLyrTblRecord->close();
//free(lpszTempLyrName);
//lpszTempLyrName = NULL;
}
delete pLyrIterator;
pLyrIterator = NULL;
pLyrTable->close();
//free(lpszLyrName);///没有给他空间,所以不用free,free 是对动态的分配内存来说的
//free(pCurDb);///pCurDb不能释放
return Adesk::kTrue;
}
Adesk::Boolean closeLyrName(char *lpszLyrName)//关闭lpszLyrName
{
assert(lpszLyrName != NULL);//防错
//将lpszlyrName设为当前层,并且将其他的层关闭
AcDbLayerTable *pLyrTable;//不用释放,要关闭
AcDbLayerTableRecord *pLyrTblRecord;//不用释放,要关闭
AcDbObjectId lyrId;
Acad::ErrorStatus es;
AcDbDatabase *pCurDb;
//关闭其他的层
es = pCurDb->getSymbolTable(pLyrTable, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("\n fail to open layer table for a read operation");
return Adesk::kFalse;
}
AcDbLayerTableIterator *pLyrIterator;//要释放
es = pLyrTable->newIterator(pLyrIterator);
if(es != Acad::eOk)
{
acutPrintf("\n 没有创建一个新");
return Adesk::kFalse;
}
char *lpszTempLyrName;
for(; !pLyrIterator->done(); pLyrIterator->step())//关闭图层
{
es = pLyrIterator->getRecord(pLyrTblRecord, AcDb::kForWrite);
if(es != Acad::eOk)
{
acutPrintf("\n 没有打开图层表记录");
continue;
//return Adesk::kFalse;
}
es = pLyrTblRecord->getName(lpszTempLyrName);
if(es != Acad::eOk)
{
acutPrintf("\n 没有取得层的名字");
continue;
//return Adesk::kFalse;
}
int rc;
rc = stricmp(lpszLyrName,lpszTempLyrName);
if(rc = 0)
{
pLyrTblRecord->setIsFrozen(TRUE);
}
pLyrTblRecord->close();
//free(lpszTempLyrName);
//lpszTempLyrName = NULL;
}
delete pLyrIterator;
pLyrIterator = NULL;
pLyrTable->close();
//free(lpszLyrName);///没有给他空间,所以不用free,free 是对动态的分配内存来说的
//free(pCurDb);///pCurDb不能释放
return Adesk::kTrue;
}
Adesk::Boolean iterateLyrName(char *lpszLyrName)//将除wall的都关调并且将wall图层作为当前层
{
assert(lpszLyrName != NULL);//防错
//将lpszlyrName设为当前层,并且将其他的层关闭
AcDbLayerTable *pLyrTable;//不用释放,要关闭
AcDbLayerTableRecord *pLyrTblRecord;//不用释放,要关闭
AcDbObjectId lyrId;
Acad::ErrorStatus es;
AcDbDatabase *pCurDb;
pCurDb = acdbHostApplicationServices()->workingDatabase();
es = pCurDb->getLayerTable(pLyrTable, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("\n fail to open layer table for a read operation");
return Adesk::kFalse;
}
if(pLyrTable->has(lpszLyrName))
{
es = pLyrTable->getAt(lpszLyrName, pLyrTblRecord, AcDb::kForWrite, Adesk::kFalse);
if(es != Acad::eOk)
{
acutPrintf("\n fail to open layer table record");
return Adesk::kFalse;
}
}
else
{
acutPrintf("\n 没有这样的图层");
return Adesk::kFalse;
}
lyrId = pLyrTblRecord->objectId();//取得图层的Id
pLyrTblRecord->close();
pLyrTable->close();
//要将快表和快表记录关闭后才能将此层设为当前的层
es = pCurDb->setClayer(lyrId);
if(es != Acad::eOk)
{
acutPrintf("\n 没有设为当前图层");
return Adesk::kFalse;
}
//关闭其他的层
es = pCurDb->getSymbolTable(pLyrTable, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("\n fail to open layer table for a read operation");
return Adesk::kFalse;
}
AcDbLayerTableIterator *pLyrIterator;//要释放
es = pLyrTable->newIterator(pLyrIterator);
if(es != Acad::eOk)
{
acutPrintf("\n 没有创建一个新");
return Adesk::kFalse;
}
char *lpszTempLyrName;
for(; !pLyrIterator->done(); pLyrIterator->step())//关闭图层
{
es = pLyrIterator->getRecord(pLyrTblRecord, AcDb::kForWrite);
if(es != Acad::eOk)
{
acutPrintf("\n 没有打开图层表记录");
continue;
//return Adesk::kFalse;
}
es = pLyrTblRecord->getName(lpszTempLyrName);
if(es != Acad::eOk)
{
acutPrintf("\n 没有取得层的名字");
continue;
//return Adesk::kFalse;
}
int rc;
rc = stricmp(lpszLyrName,lpszTempLyrName);
if(rc != 0)
{
pLyrTblRecord->setIsFrozen(TRUE);
}
pLyrTblRecord->close();
//free(lpszTempLyrName);
//lpszTempLyrName = NULL;
}
delete pLyrIterator;
pLyrIterator = NULL;
pLyrTable->close();
//free(lpszLyrName);///没有给他空间,所以不用free,free 是对动态的分配内存来说的
//free(pCurDb);///pCurDb不能释放
return Adesk::kTrue;
}
Adesk::Boolean copyEntity(ads_name en)
{
int irc;
Acad::ErrorStatus es;
AcDbObjectId entityId;
irc = acdbGetObjectId(entityId, en);//这是重点,与参考有出入
if(irc != Acad::eOk)
{
acutPrintf("\n no entityId");
}
AcDbEntity *pObj;
es = acdbOpenAcDbEntity(pObj, entityId, AcDb::kForRead);
if(es != Acad::eOk)
{
acutPrintf("\n can't open pObj");
return Adesk::kFalse;
}
AcDbEntity *pClone = AcDbEntity::cast(pObj->clone());
if(pClone == NULL)
{
acutPrintf("\n on clone");
}
AddEntityToAds(pClone);
pObj->close();
return Adesk::kTrue;
}
Adesk::Boolean copyCurLayer(char *lpszNewLayer, char *lpszCopyLayer)
{
assert(lpszNewLayer != NULL);
assert(lpszCopyLayer != NULL);
ads_name ssEntName, enName;
long ssLen;
int irc, i;
AcDbObjectId lyrId;
AcDbObjectId copyId;
irc = getSelSet(ssEntName, ssLen, lpszNewLayer);//取得选择集copyWindo
if(irc != Adesk::kTrue)
{
acutPrintf("\n no contain selection set");
return irc;
}
for(i=0; i<ssLen; i++)
{
if(acedSSName(ssEntName, i, enName) != RTNORM)
{
acutPrintf("\n no entity");
return Adesk::kFalse;
}
irc = copyEntity(enName);
if(irc != Adesk::kTrue)
{
acutPrintf("\n no copy");
return Adesk::kFalse;
}
irc = chgEntToLayer(lpszCopyLayer, enName);
if(irc != Adesk::kTrue)
{
acutPrintf("\n no change layer");
return Adesk::kFalse;
}
}
return Adesk::kTrue;
}
Adesk::Boolean myextrude(char *lpszLyrName, char *lpszName, long &lHeigh)//将lpszLyrName中的实体拉伸lHeigh
//还需要将物体方入到图层中,前面的已经有方入到新建的图层中,要将拉伸的物体方入
//
{
assert(lpszLyrName != NULL);
assert(lpszName != NULL);
int irc, i;
ads_name extEntity;
AcDbObjectId entityId;
AcDb3dSolid *p3dObj;
ads_name ssName;
long lenSS;
irc = getSelSet(ssName,lenSS,lpszLyrName);
if(irc != Adesk::kTrue)
{
acutPrintf("\n no selection");
return Adesk::kFalse;
}
AcDbRegion *pEnt ;//初始化指针
for(i=0; i<lenSS; i++)
{
acedSSName(ssName, i, extEntity);
irc = acdbGetObjectId(entityId, extEntity);//这是重点,与参考有出入
if(irc != Acad::eOk)
{
acutPrintf("\n no entityId");
continue;
//return Adesk::kFalse;
}
irc = acdbOpenObject(pEnt,entityId,AcDb::kForWrite);//得到了ssEntName的指针pEnt
if(irc != Acad::eOk)
{
acutPrintf("\n no open entity");
continue;
//return Adesk::kFalse;
}
p3dObj = new AcDb3dSolid;
Acad::ErrorStatus es = p3dObj->extrude(pEnt,lHeigh,0);
if(es != Acad::eOk)
{
acutPrintf("\n no extrude");
delete p3dObj;
pEnt->close();
continue;
//return Adesk::kFalse;
}
es = AddEntityToAds(p3dObj);
if(es != Acad::eOk)
{
acutPrintf("\n no enter database");
delete p3dObj;
pEnt->close();
continue;
//return Adesk::kFalse;
}
pEnt->close();
p3dObj->close();
acdbEntLast(extEntity);
chgEntToLayer(lpszName,extEntity);
}
acedSSFree(ssName);
return Adesk::kTrue;
} |
|