赞
踩
ARX函数
选择指定图层上的所有实体
Acad::ErrorStatus selectEntityInLayer(const char* nLayerName,AcDbObjectIdArray& nIDs)
{
Acad::ErrorStatus es = Acad::eOk;
ads_name ents;
struct resbuf *rb;
rb=acutNewRb(AcDb::kDxfLayerName);
rb->restype=8;
rb->resval.rstring=(char*)nLayerName;
rb->rbnext=NULL;
acedSSGet("X",NULL,NULL,rb,ents);
long entNums=0;
acedSSLength(ents,&entNums);
if (entNums == 0)
es = Acad::eInvalidInput;
else
{
for (long a = 0; a < entNums ; a ++)
{
AcDbObjectId objId;
ads_name ent;
acedSSName(ents,a,ent);
acdbGetObjectId(objId, ent);
nIDs.append(objId);
}
}
acedSSFree(ents);
acutRelRb(rb);
return es;
}
设置当前层
Acad::ErrorStatus SetCurLayer(const char* lpLayerName, AcDbDatabase* pDb/* = NULL */)
{
AcDbDatabase* pCurDb = pDb;
if (pCurDb == NULL)
pCurDb = acdbHostApplicationServices()->workingDatabase();
AcDbLayerTableRecordPointer spRecord(lpLayerName, pCurDb, AcDb::kForRead);
Acad::ErrorStatus es = spRecord.openStatus();
if (es == Acad::eOk)
{
es = pCurDb->setClayer(spRecord->objectId());
}
return es;
}
生成新组
//生成新组(sGroupName)
//追加数组中所有实体到该组中
//组名字 , Id数组
int createGroup(CString sGroupName,
const AcDbObjectIdArray *idArr)
{
AcDbGroup *pGroup = new AcDbGroup((LPSTR)(LPCTSTR)sGroupName);
AcDbObjectId groupObjectId;
AcDbDictionary *pGroupDict = NULL;
acdbHostApplicationServices()->workingDatabase()
->getGroupDictionary(pGroupDict, AcDb::kForWrite);
pGroupDict->setAt(sGroupName, pGroup, groupObjectId);
pGroupDict->close();
pGroup->close();
acdbOpenObject(pGroup, groupObjectId, AcDb::kForWrite);
for (int i = 0; i < idArr->length(); i++)
{
groupObjectId = idArr->at(i);
pGroup->append(groupObjectId);
}
pGroup->close();
return TRUE;
}
建立文本格式表函数
AcDbObjectId CreateNewTextStyle()
{
AcDbTextStyleTable *pTextStyleTable;
AcDbTextStyleTableRecord *pTextStyleTableRcd
AcDbObjectId textId;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable (pTextStyleTable,AcDb::kForWrite);
if (!pTextStyleTable->has(StyleName)
{
AcDbTextStyleTableRecord *pTSTblRcd= new AcDbTextStyleTableRecord;
pTSTblRcd->setName(StyleName);
pTSTblRcd->setFileName(fontName);
pTSTblRcd->setBigFontFileName(bigfontName);
pTSTblRcd->setTextSize(textSize);
pTSTblRcd->setXScale(xScale);
pTSTblRcd->setObliquingAngle(obliqueAngle);
pTSTblRcd->setPriorSize(trPercent);
pTextStyleTable->add(textId,pTextStyleTableRcd);
pTSTblRcd->close();
}
pTextStyleTable->close();
return textId;
}
区域在区域内
// Function name : RgnInRgn
// Descrīption : is Region1 in Region2?
// Return type : bool
// Argument : const AcDbRegion* pRegion1
// Argument : const AcDbRegion* pRegion2
bool RgnInRgn(const AcDbRegion* pRegion1,const AcDbRegion* pRegion2)
{
if (pRegion1==NULL||pRegion2==NULL) return false;
AcDbObjectPointer< AcDbRegion > spRegion1;
AcDbObjectPointer< AcDbRegion > spRegion2;
if (spRegion1.create()!=Acad::eOk)
{
acdbFail("\n内存不足");
return false;
}
if (spRegion2.create()!=Acad::eOk)
{
acdbFail("\n内存不足");
return false;
}
if ((spRegion1->copyFrom(pRegion1)!= Acad::eOk)||
(spRegion2->copyFrom(pRegion2)!= Acad::eOk))
{
acdbFail("\n无法复制对象");
return false;
}
bool bResult=false;
if(spRegion1->booleanOper(AcDb::kBoolIntersect, spRegion2.object()) == Acad::eOk)
{
if ((spRegion2->isNull()==Adesk::kTrue)&&(spRegion1->isNull()!=Adesk::kTrue)){
double area1,area0;
spRegion1->getArea(area1);
pRegion1->getArea(area0);
if ((area0 - area1) < AcGeContext::gTol.equalPoint())
bResult=true;
}
}
return bResult;
}
组旋转
void CMyDatabase::rotationGroup(CString strGroupName ,CReiPoint ptRotation,double rotationAngle)
{
AcGePoint3d pt;
AcDbDictionary *pGroupDict;
acdbCurDwg()->getGroupDictionary(pGroupDict,AcDb::kForWrite);
AcDbObjectId groupId;
AcDbGroup *pGroup;
pt.x=ptRotation.x;
pt.y=ptRotation.y;
pt.z=ptRotation.z;
if(pGroupDict->getAt(strGroupName,groupId)==Acad::eOk)
acdbOpenObject(pGroup,groupId,AcDb::kForWrite);
else
{
pGroupDict->close();
return;
}
pGroupDict->close();
AcDbGroupIterator* pIter=pGroup->newIterator();
AcDbEntity* pEnt;
AcDbObjectId objId;
pIter=pGroup->newIterator();
for(;!pIter->done();pIter->next())
{
ōbjId=pIter->objectId();
acdbOpenAcDbEntity(pEnt,objId,AcDb::kForWrite);
rotationEntity(pEnt,pt,rotationAngle);
pEnt->close();
}
delete pIter;
pGroup->close();
}
点在区域内
功能:判断点 pt 是否在区域 ptArr 内
实现:根据射线法求交点个数,偶数-区域外,奇数-区域内
变量:pt 指定点 ptArr 判断区域
返回:在区域 TRUE 不在 FALSE
code: BOOL BaseHandle::PointIsInPolygon(AcGePoint3d pt, AcGePoint3dArray ptArr)
{
int ptNum,i,interNum;
AcGePoint3d ptA,ptB;
ads_point pt0,pt1,pt2,ptIns,ptX;
interNum = 0;
pt0[X] = 0.0;
pt0[Y] = 0.0;
pt0[Z] = 0.0;
ptX[X] = pt.x;
ptX[Y] = pt.y;
ptX[Z] = pt.z;
ptNum = ptArr.length();
for (i = 0;i < ptNum - 1;i++){
ptA = ptArr.at(i);
ptB = ptArr.at(i + 1);
pt1[X] = ptA.x;
pt1[Y] = ptA.y;
pt1[Z] = 0.0;
pt2[X] = ptB.x;
pt2[Y] = ptB.y;
pt2[Z] = 0.0;
if (acdbInters(ptX,pt0,pt1,pt2,1,ptIns) == RTNORM){
interNum++;
}
}
if (interNum % 2 == 0){
return false;
}else{
return true;
}
2008-05-29 13:58
/****************************************************************** //若X坐标或Y坐标重合,判为意外,不进行SetView操作 //确保两个坐标点分别为左上角和右下角 //获取当前DwgView的尺寸 double width,height,ratio; ratio = (double)(CADrect.right-CADrect.left)/(double)(CADrect.bottom-CADrect.top); if (fabs(ratio)<1e-6) if ((Pt2.x-Pt1.x)/(Pt1.y-Pt2.y) > ratio) { //设置当前视图中心点 //改变当前视图 /// / int oxaGetVar(const CString strSym, int &vOut ) return RTNORM; / / AcDbTextStyleTableRecordPointer spRecord(lpStyleName, pCurDb, AcDb::kForRead); AcDbLayerTableRecordPointer spRecord(lpLayerName, pCurDb, AcDb::kForRead); CODE: void FEGroups::iterateDictionary() // Get a pointer to the ASDK_DICT dictionary. // Get an iterator for the ASDK_DICT dictionary. } //检测AutoCAD是否已经运行 CODE: void Autocadtest() LPDISPATCH pDisp; //计算多边形的形心坐标 if (pPline->isClosed() != Adesk::kTrue) { if (AcDbRegion::createFromCurves(curveSegments, regions) != Acad::eOk){ return FALSE; origin.set(0,0,0); //设置原点坐标 if (pRegion->getAreaProp( return TRUE; AcDbObjectId CreateHatch( objectARX 常用功能实现集合 一在ARX中禁用AutoCAD的某个命令 acedCommand(RTSTR, "undefine", RTSTR, "line",RTNONE); 下面的语句则可恢复LINE命令的定义: acedCommand(RTSTR, "redefine", RTSTR, "line",RTNONE); 二在对话框中预览DWG文件 es = acdbDisplayPreviewFromDwg(fileName, pFrame->m_hWnd); 三通过ARX更改AutoCAD窗口的标题名称 四获得当前数据库 五将一个图插入另一个图(两种方法) es=pNewDb->readDwgFile(sFileName , _SH_DENYNO,false); 这样,source.dwg以经用pNewDb来表示了. 我们用pDb来表示当前数据库 现在,我们用Insert来插入数据库. Insert有两种用法,一种是直接insert, source.dwg中的图元实体被分散地插入pDb中 另外一种插入法是要求插入后source.dwg成为一个图块,图块的attribute也要从source.dwg中得到.这种方法要做大量的工作.首先运行insert() CString pBlockName=”TestBlock”; //这里blcokId是insert运行后产生的,它代表的是一个块表记录AcDbBlockRecord的ID. pBlockName是记录名,要在insert运行前设定其值. AcDbBlockTable *pBlockTable; AcDbBlockTableRecord *pBlockTableRecord; 如果我们在这里结束程序,我们将看到当前图形中source.dwg已经被作为图块插入.但是图块中没有source.dwg所定义的Attibute. 因此我们还要做工作.后面的事情就简单了. AcDbBlockTableRecord *pBlockDef; AcDbBlockTableRecordIterator *pIterator; AcDbObjectId attId; pBlkRef->appendAttribute(attId, pAtt);
用户可以在AutoCAD“选项”对话框的“系统”选项卡中进行设置,或者在主函数中添加下面的语句: //加载模板文件 #ifndef _ACAD2000 如果在多文档模式下,下面的方法可以在执行时弹出“选择文件”对话框,用户选择所要打开的文件后,在图形窗口中显示该图形。 下面的方法则打开指定位置的DWG文件。 // This is command 'OPEN1' |
如何获得程序路径 char sTemp[1024],*str; ads_getvar("acadprefix",&rb); strcpy(sTemp,rb.resval.string); acad_free(rb.resval.rstring); str=strchr(sTemp,';'); *str='\0'; str=strrchr(sTemp,'\\'); *str='\0'; 上段程序中,sTemp中存储了安装CAD的目录 dwgprefix 当前dwg图形存储的目录 acadprefix acad环境变量存储的目录 dwgname 当前dwg文件名 savefile 当前自动存储文件名
//return acdbGetRGB(nColor); 获取AcDbDimension里的属性信息 id =pDim->dimBlockId (); |
插入定义的属性块
2007-08-16 09:19
CString blockname; ///获得要插入的块名 //寻找是否已经定义 if(!pBlkTable->has(blockname)) //杳找块是否存在 pDwg->readDwgFile (blockname) ; //读入块定义 Acad::ErrorStatus es = pCurDb->insert (blockId, "blockname", pDwg);//, Adesk::kFalse) ; // delete pDwg ; BeginEditorCommand(); double m_angle=0;
AcDbBlockTableRecordIterator *pIterator; for(pIterator->start(); !pIterator->done();pIterator->step()) //遍历块的属性 if(pAttDef != NULL && !pAttDef->isConstant()) pAtt->setHorizontalMode(pAttDef->horizontalMode()); pAtt->setHeight(pAttDef->height()); pAtt->setTag(pAttDef->tag());
pBlkDefRecord->close(); pBlockTableRecord->close(); |
设置当前的layer和textstyle
// Function name : SetCurTextStyle
// Description : 设置当前TextStyle
// Return type : Acad::ErrorStatus
// Argument : const char* lpStyleName
// Argument : AcDbDatabase* pDb/* = NULL */
Acad::ErrorStatus SetCurTextStyle( const char * lpStyleName, AcDbDatabase * pDb /* = NULL */ )
{
AcDbDatabase * pCurDb = pDb;
if (pCurDb == NULL)
pCurDb = acdbHostApplicationServices() -> workingDatabase();
AcDbTextStyleTableRecordPointer spRecord(lpStyleName, pCurDb, AcDb::kForRead);
Acad::ErrorStatus es = spRecord.openStatus();
if (es == Acad::eOk)
{
es = pCurDb -> setTextstyle(spRecord -> objectId());
}
return es;
}
// Function name : SetCurLayer
// Description : 设置当前层
// Return type : Acad::ErrorStatus
// Argument : const char* lpLayerName
// Argument : AcDbDatabase* pDb/* = NULL */
Acad::ErrorStatus SetCurLayer( const char * lpLayerName, AcDbDatabase * pDb /* = NULL */ )
{
AcDbDatabase * pCurDb = pDb;
if (pCurDb == NULL)
pCurDb = acdbHostApplicationServices() -> workingDatabase();
AcDbLayerTableRecordPointer spRecord(lpLayerName, pCurDb, AcDb::kForRead);
Acad::ErrorStatus es = spRecord.openStatus();
if (es == Acad::eOk)
{
es = pCurDb -> setClayer(spRecord -> objectId());
}
return es;
}
//功能描述:选择指定图层上的所有实体!
// ************************************************************************
// 函数名称:selectEntityInLayer
// 函数类型:Acad::ErrorStatus
// 返回值: 正常:Acad::eOk
// 功能描述:选择指定图层上的所有实体!
// 函数作者:Darcy
// 创建日期:200X-XX-XX
// 参数列表:
// 变量名:nLayerName 变量类型:const char* 变量说明:(输入)图层名
// 变量名:nIDs 变量类型:AcDbObjectIdArray& 变量说明:(输出)图层中实体的对象标识符集合
// ************************************************************************
Acad::ErrorStatus selectEntityInLayer( const char * nLayerName,AcDbObjectIdArray & nIDs)
{
Acad::ErrorStatus es = Acad::eOk;
ads_name ents;
struct resbuf * rb;
rb = acutNewRb(AcDb::kDxfLayerName);
rb -> restype = 8 ;
rb -> resval.rstring = ( char * )nLayerName;
rb -> rbnext = NULL;
acedSSGet( " X " ,NULL,NULL,rb,ents);
long entNums = 0 ;
acedSSLength(ents, & entNums);
if (entNums == 0 )
es = Acad::eInvalidInput;
else
{
for ( long a = 0 ; a < entNums ; a ++ )
{
AcDbObjectId objId;
ads_name ent;
acedSSName(ents,a,ent);
acdbGetObjectId(objId, ent);
nIDs.append(objId);
}
}
acedSSFree(ents);
acutRelRb(rb);
return es;
}
另一种实现
//************************************************************************
//函数名称:selectEntityInLayer
//函数类型:Acad::ErrorStatus
//返回值:
//功能描述:选择指定层上的实体,得到其对象属性标识符!
//函数作者:Darcy
//创建日期:200X-XX-XX
//参数列表:
//变量名:nLayerName 变量类型:CString 变量说明:
//变量名:nIDs 变量类型:AcDbObjectIdArray& 变量说明:
//变量名:nModelSpace 变量类型:bool 变量说明:
//************************************************************************
Acad::ErrorStatus selectEntityInLayer(
CString nLayerName,
AcDbObjectIdArray& nIDs,
bool nModelSpace
)
{
Acad::ErrorStatus es=Acad::eOk;
AcDbBlockTable* pBlockTable=NULL;
AcDbBlockTableRecord* pSpaceRecord=NULL;
if (acdbHostApplicationServices()->workingDatabase()==NULL)
return Acad::eNoDatabase;
if ((es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead))==Acad::eOk)
{
char entryName[13];
if (nModelSpace)
strcpy(entryName,ACDB_MODEL_SPACE);
else
strcpy(entryName,ACDB_PAPER_SPACE);
//Get the Model or Paper Space record and open it for read:
if ((es = pBlockTable->getAt((const char*)entryName, pSpaceRecord, AcDb::kForRead))==Acad::eOk)
{
AcDbBlockTableRecordIterator* pIter;
if (pSpaceRecord->newIterator(pIter)==Acad::eOk)
{
for (pIter->start();!pIter->done();pIter->step())
{
char *name=NULL;
AcDbEntity* pEntity;
if (pIter->getEntity(pEntity,AcDb::kForRead)==Acad::eOk)
{
name=pEntity->layer();
if (nLayerName.CompareNoCase(name)==0)
nIDs.append(pEntity->objectId());
pEntity->close();
acutDelString(name);
}
}
delete pIter;
}
pSpaceRecord->close();
}
pBlockTable->close();
}
return es;
}
生成新组
//生成新组(sGroupName)
//追加数组中所有实体到该组中
//组名字 , Id数组
int createGroup(CString sGroupName,
const AcDbObjectIdArray *idArr)
{
AcDbGroup *pGroup = new AcDbGroup((LPSTR)(LPCTSTR)sGroupName);
AcDbObjectId groupObjectId;
AcDbDictionary *pGroupDict = NULL;
acdbHostApplicationServices()->workingDatabase()
->getGroupDictionary(pGroupDict, AcDb::kForWrite);
pGroupDict->setAt(sGroupName, pGroup, groupObjectId);
pGroupDict->close();
pGroup->close();
acdbOpenObject(pGroup, groupObjectId, AcDb::kForWrite);
for (int i = 0; i < idArr->length(); i++)
{
groupObjectId = idArr->at(i);
pGroup->append(groupObjectId);
}
pGroup->close();
return TRUE;
}
另一个
Acad::ErrorStatus CDrawFunction::createGroup(CString groupname,AcDbObjectIdArray IdArray)
{
Acad::ErrorStatus es=Acad::eOk;
AcDbDictionary *pGroupDict=NULL;
AcDbGroup *pGroup=NULL;
if((es=acdbHostApplicationServices()->workingDatabase()->getGroupDictionary(pGroupDict,AcDb::kForWrite))!=Acad::eOk)
{
return es;
}
AcDbObjectId groupId;
es=pGroupDict->getAt(groupname,groupId);
if(es==Acad::eInvalidKey)
{
acutPrintf("\n输入的词典名无效!");
pGroupDict->close();
return es;
}
else if(es==Acad::eKeyNotFound)
{
pGroup=new AcDbGroup("GroupDiscription");
if((es=pGroupDict->setAt(groupname,pGroup,groupId))!=Acad::eOk)
{
pGroup->close();pGroupDict->close();return es;
}
}
else if(es==Acad::eOk )
{
if((es=acdbOpenObject(pGroup,groupId,AcDb::kForWrite))!=Acad::eOk)
{
pGroupDict->close();return es;
}
}
for(int i=0;i pGroup->append(IdArray[i]);
pGroup->setSelectable(FALSE);
pGroupDict->close();
pGroup->close();
return es;
}
旋转整个group
void CMyDatabase::rotationGroup(CString strGroupName ,CReiPoint ptRotation,double rotationAngle)
{
AcGePoint3d pt;
AcDbDictionary *pGroupDict;
acdbCurDwg()->getGroupDictionary(pGroupDict,AcDb::kForWrite);
AcDbObjectId groupId;
AcDbGroup *pGroup;
pt.x=ptRotation.x;
pt.y=ptRotation.y;
pt.z=ptRotation.z;
if(pGroupDict->getAt(strGroupName,groupId)==Acad::eOk)
acdbOpenObject(pGroup,groupId,AcDb::kForWrite);
else
{
pGroupDict->close();
return;
}
pGroupDict->close();
AcDbGroupIterator* pIter=pGroup->newIterator();
AcDbEntity* pEnt;
AcDbObjectId objId;
pIter=pGroup->newIterator();
for(;!pIter->done();pIter->next())
{
objId=pIter->objectId();
acdbOpenAcDbEntity(pEnt,objId,AcDb::kForWrite);
rotationEntity(pEnt,pt,rotationAngle);
pEnt->close();
}
delete pIter;
pGroup->close();
}
新建一个图层
//==========================================================
功能:新建一个图层
参数:LayerName -- 图层名,LayerColor -- 颜色名
返回:图层ID
//==========================================================
AcDbObjectId CreateNewLayer(CString LayerName, AcCmColor LayerColor)
{
// 获得当前图形数据库的符号表
AcDbLayerTable *pLayerTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTable,
AcDb::kForWrite);
// 生成新的图层表记录
AcDbLayerTableRecord *pLayerTableRecord = new AcDbLayerTableRecord;
pLayerTableRecord->setName(LayerName); // 设置图层名
pLayerTableRecord->setColor(LayerColor); // 设置图层颜色
AcDbObjectId layerId;
pLayerTable->add(layerId,pLayerTableRecord);
// 关闭图层表和图层表记录
pLayerTable->close();
pLayerTableRecord->close();
return layerId;
}
//==========================================================
功能:在指定图层上新建一条直线
参数:见注释
返回:直线ID
//==========================================================
AcDbObjectId CreateLine( double x1,double y1,double z1, // 起点坐标
double x2,double y2,double z2, // 终点坐标
AcDbObjectId layer) // 直线所在图层
{
AcGePoint3d StartPt(x1,y1,z1); // 起点
AcGePoint3d EndPt(x2,y2,z2); // 终点
AcDbLine *pLine = new AcDbLine(StartPt,EndPt);
// 获得当前图形数据库的符号表
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,
AcDb::kForRead);
// 获得符号表中的模型空间块表记录指针,用于添加对象
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
// 将直线添加到模型空间块表记录中
AcDbObjectId lineId;
pLine->setLayer(layer,Adesk::kTrue); // 设置直线所在图层
pBlockTableRecord->appendAcDbEntity(lineId,pLine);
// 关闭块表记录指针和直线指针
pBlockTableRecord->close();
pLine->close();
// 返回直线ID号
return lineId;
}
不太常用的啊
已知一段弧的起点和终点以及其凸度,求其圆心
int getCenter(ads_point startPoint,ads_point endPoint,double bulge,ads_point& center)
{
if (bulge==0.0)
{
ads_point_set(startPoint,center);
return 0;
}
ads_point startPt,endPt;
if (bulge<0.0)
{
ads_point_set(endPoint,startPt);
ads_point_set(startPoint,endPt);
bulge=bulge*(-1.0);
}
else
{
ads_point_set(startPoint,startPt);
ads_point_set(endPoint,endPt);
}
double distStartToEnd,distX,distY,radius;
distStartToEnd=ads_distance(startPt,endPt);
distX=distStartToEnd/2.0;
distY=bulge*distX;
radius=((distX*distX)+(distY*distY))/(2.0*distY);
double tmpAng;
ads_point tmpPt;
tmpAng=ads_angle(startPt,endPt);
ads_polar(startPt,tmpAng,distX,tmpPt);
ads_polar(tmpPt,(tmpAng+(_PI/2.0)),(radius-distY),center);
return 1;
};
create hatch的
AcDbObjectId CreateHatch(
AcDbObjectId dbOId,
char cLayer[],
char cPattern[] = "SOLID",
int nColor = 256,
double dAngle = 0.0,
double dScale = 1.0,
AcDbDatabase * pDbDatab = acdbHostApplicationServices()->workingDatabase())
{
AcCmColor CmC;
AcDbObjectId DbOId;
AcDbObjectIdArray DbOIdA(0, 2);
AcDbBlockTable * pDbBT;
AcDbBlockTableRecord * pDbBTR;
AcGeVector3d normal(0.0, 0.0, 1.0);
DbOIdA.append(dbOId);
AcDbHatch* pDbHat = new AcDbHatch();
pDbHat->setDatabaseDefaults();
pDbHat->setAssociative(Adesk::kTrue); // BUG: doesn't do squat! have to set the reactor yourself to get associativity!
pDbHat->appendLoop(AcDbHatch::kExternal, DbOIdA);
pDbHat->setPatternScale(dScale);
pDbHat->setPatternAngle(dAngle);
pDbHat->setPattern(AcDbHatch::kPreDefined, cPattern);
pDbHat->setNormal(normal);
pDbHat->evaluateHatch(); // crucial call or nothing gets displayed!
pDbDatab->getSymbolTable(pDbBT, AcDb::kForRead);
pDbBT->getAt(ACDB_MODEL_SPACE, pDbBTR, AcDb::kForWrite);
pDbBTR->appendAcDbEntity(DbOId, pDbHat);
pDbHat->setLayer(cLayer);
CmC.setColorIndex(nColor);
((AcDbEntity *)pDbHat)->setColor(CmC);
pDbBT->close();
pDbBTR->close();
pDbHat->close();
return DbOId;
}
前阵困扰我的问题解决了,现在共享给大家:
//************************************************************************
//函数名称:getPointAtDistInGeCurve
//函数类型:Acad::ErrorStatus
//返回值:
//功能描述:返回曲线上距起点某距离值处的点。
//函数作者:Darcy
//创建日期:2003-XX-XX
//参数列表:
//变量名:pGeCurve 变量类型:const AcGeCurve3d * 变量说明:
//变量名:dist 变量类型:double 变量说明:
//变量名:point 变量类型:AcGePoint3d& 变量说明:
//备 注:
//************************************************************************
Acad::ErrorStatus getPointAtDistInGeCurve(const AcGeCurve3d * pGeCurve,double dist,AcGePoint3d& point)
{
Acad::ErrorStatus es = Acad::eOk;
if ( pGeCurve != NULL )
{
AcGePoint3d spt;
double pa=0.,datumParam=0.;
//距离从起点起算!
Adesk::Boolean posParamDir=Adesk::kTrue;
pGeCurve->hasStartPoint(spt);
datumParam = pGeCurve->paramOf(spt);;
pa = pGeCurve->paramAtLength(
datumParam,
dist,
posParamDir
);
point=pGeCurve->evalPoint(pa);
}
else
es = Acad::eInvalidInput;
return es;
}
判断点是否在圆弧上
/*****************************************************/
BOOL
IsAtArc(CAD_POINT firstPt,CAD_POINT secondPt,
double radius,double direct,int More,CAD_POINT thePt)
/* 判断某点是否在圆弧上
firstPt 圆弧起点
secondPt 圆弧终点
radius 半径
direct 偏向( >=0__左偏 <0__右偏 )
More (More<0__小圆弧,More>0__大圆弧)
thePt 判断点
返回:TRUE__在圆弧上 FALSE__不在圆弧上
*/
{
CAD_POINT centerPt,sectionPt;
CAD_POINT startPt,endPt;
double startAngle,endAngle,chordAngle,vertAngle;
double intLine,chordLine;
/* centerPt 圆弧圆心
sectionPt 弦线中心点
startAngle 圆弧起点切线角度(弧度)
endAngle 圆弧终点切线角度(弧度)
chordAngle 弦线角度(弧度)
vertAngle 与弦线垂直的垂线角度(弧度)
intLine 弦线中心至圆心距离
chordLine 弦线长度
*/
sectionPt.x = (firstPt.x + secondPt.x)/2;
sectionPt.y = (firstPt.y + secondPt.y)/2;
chordLine = sqrt( pow( (secondPt.x-firstPt.x),2 ) + pow( (secondPt.y-firstPt.y),2 ) );
intLine = sqrt((radius*radius-chordLine*chordLine/4) );
chordAngle = ads_angle(asDblArray(firstPt),asDblArray(secondPt)); //弦线的角度
if(direct>=0)//左偏
{
startPt=firstPt;
endPt=secondPt;
vertAngle=chordAngle+Pai/2;
}
else if(direct<0)//右偏
{
startPt=secondPt;
endPt=firstPt;
vertAngle=chordAngle-Pai/2;
}
if(More<=0)//小圆弧
{
centerPt.x=sectionPt.x+intLine*cos(vertAngle);
centerPt.y=sectionPt.y+intLine*sin(vertAngle);
}
else//大圆弧
{
centerPt.x=sectionPt.x-intLine*cos(vertAngle);
centerPt.y=sectionPt.y-intLine*sin(vertAngle);
}
if(fabs(centerPt.distanceTo(thePt)-radius)>1.0E-8)
return FALSE;
startAngle = ads_angle(asDblArray(centerPt),asDblArray(startPt));
endAngle = ads_angle(asDblArray(centerPt),asDblArray(endPt));
AcDbArc *pArc=new AcDbArc(centerPt,radius,startAngle,endAngle);
AcDbLine *pLine=new AcDbLine(centerPt,thePt);
AcGePoint3dArray Points;
pLine->intersectWith(pArc,AcDb::kOnBothOperands,Points);
if(Points.isEmpty()) return FALSE;
return TRUE;
}
相object加xdata
void affixXdata(char *appName, char *xData, AcDbObject *pObj)
{
//向AcDbObject添加扩展数据Xdata
struct resbuf *pRb, *pTemp;
acdbRegApp(appName);
pRb = acutNewRb(AcDb::kDxfRegAppName);
pTemp = pRb;
pTemp->resval.rstring = new char[strlen(appName)+1];
strcpy(pTemp->resval.rstring, appName);
pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);
pTemp = pTemp->rbnext;
pTemp->resval.rstring = new char[strlen(xData)+1];
strcpy(pTemp->resval.rstring, xData);
pObj->setXData(pRb);
acutRelRb(pRb);
}
//添加扩展数据
//实体添加扩展数据(字符串)
bool AddXData(CString appName, AcDbObjectId entId,CString data)
{
//open entity for read
AcDbEntity*pEnt;
Acad::ErrorStatus es=acdbOpenAcDbEntity(pEnt,entId,AcDb::kForRead);
if(es!=Acad::eOk)
{
ads_printf("error in open entity\n");
return false;
}
//get XData buffer
struct resbuf*pRb,*pTemp;
pRb=pEnt->xData(appName);
if(pRb!=NULL)//have XData
{
//pTemp移到表尾
pTemp=pRb;
for(pTemp=pRb;pTemp->rbnext!=NULL;pTemp=pTemp->rbnext){;}
}
else//NOT have XData
{
//create new xData
ads_regapp(appName);
pRb=ads_newrb(AcDb::kDxfRegAppName);
pRb->resval.rstring=(char*)malloc(appName.GetLength()+1);
strcpy(pRb->resval.rstring,appName);
pTemp=pRb;
}
//fill xData string
pTemp->rbnext=ads_newrb(AcDb::kDxfXdAsciiString);
pTemp=pTemp->rbnext;
pTemp->resval.rstring=(char*)malloc(data.GetLength()+1);
strcpy(pTemp->resval.rstring,data);
//add xData
es=pEnt->upgradeOpen();
if(es!=Acad::eOk)
{
ads_printf("\nError occur in updateOpen.");
pEnt->close();
ads_relrb(pRb);
return false;
}
es=pEnt->setXData(pRb);
if(es!=Acad::eOk)
{
ads_printf("\nError occur in setXData.");
pEnt->close();
ads_relrb(pRb);
return false;
}
//
pEnt->close();
ads_relrb(pRb);
return true;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。