关闭

ARX函数集

326人阅读 评论(0) 收藏 举报

选择指定图层上的所有实体

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;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1883次
    • 积分:46
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:1篇
    • 译文:1篇
    • 评论:0条
    文章分类
    文章存档