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(\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(\内存不足\return false; }
if (spRegion2.create()!=Acad::eOk) {
acdbFail(\内存不足\return false; }
if ((spRegion1->copyFrom(pRegion1)!= Acad::eOk)|| (spRegion2->copyFrom(pRegion2)!= Acad::eOk)) {
acdbFail(\无法复制对象\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) {