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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值