文章目录

  • 关于块相关问题
    • 几个工作中常碰到的问题
      • 块的角度
      • 修改块中实体到相同图层
      • 炸块相关
      • 计算AcDbBlockReference准确的包围盒
      • 分割块
      • XClip外部参照
      • 动态块相关
      • 匿名块
      • 获取裁剪块的边界
    • 碰到的BUG

关于块相关问题

几个工作中常碰到的问题

  • 块记录AcDbBlockTableRecord和块参照AcDbBlockReference的区别
  • 裁剪块XClip
  • 外部参照块XRef
  • 动态块DynBlock

块的角度

 static void CreateAngleOfBlk(){if (m_BlockRef){delete m_BlockRef;m_BlockRef = nullptr;}m_DirPt = dir_pt;m_BlockRef = new AcDbBlockReference();m_BlockRef->setBlockTableRecord(blk_objid);// Calcualte Normal : refactor as functionAcGeVector3d vec = endPoint().asVector() - startPoint().asVector();AcGeVector3d vec1 = m_DirPt.asVector() - startPoint().asVector();AcGeVector3d vec_normal = vec.crossProduct(vec1);vec_normal.normalize();// Get UCS, refactor as a functionAcGeMatrix3d  myUCS;acdbUcsMatrix(myUCS, nullptr);AcGeVector3d  xAxis, yAxis, zAxis;AcGePoint3d   myOrigin;myUCS.getCoordSystem(myOrigin, xAxis, yAxis, zAxis);bool AngleFlip = false;if (fabs(vec_normal.dotProduct(zAxis)) < 1e-8)return;else if (vec_normal.dotProduct(zAxis) < 0)AngleFlip = true;elseAngleFlip = false;m_BlockRef->setNormal(zAxis); //(vec_normal);m_BlockRef->setPosition(ins_pt);AcGeScale3d scl;if (scale < 0)scale = 1.0;scl.set(scale, scale, scale);m_BlockRef->setScaleFactors(scl);// calculate angleads_point p_start_wcs, p_end_wcs, p_start_ucs, p_end_ucs;p_start_wcs[X] = startPoint().x; p_start_wcs[Y] = startPoint().y; p_start_wcs[Z] = startPoint().z;p_end_wcs[X] = endPoint().x; p_end_wcs[Y] = endPoint().y; p_end_wcs[Z] = endPoint().z;ConvertFromWCSToUCS(p_start_wcs, p_start_ucs);ConvertFromWCSToUCS(p_end_wcs, p_end_ucs);AcGePoint3d p_start(p_start_ucs[X], p_start_ucs[Y], p_start_ucs[Z]);AcGePoint3d p_end(p_end_ucs[X], p_end_ucs[Y], p_end_ucs[Z]);AcGeVector3d v1_ucs = p_end.asVector() - p_start.asVector();AcGeVector3d v1 = endPoint().asVector() - startPoint().asVector();AcGeVector3d ref_vector = AcGeVector3d::kZAxis;double dangle = xAxis.angleTo(v1_ucs, zAxis); // this is not what I want?double dangle1 = AcGeVector3d::kXAxis.angleTo(v1_ucs, AcGeVector3d::kZAxis);if (m_AngleFlip){dangle1 *= -1;m_FlipHandle = !m_FlipHandle;}m_BlockRef->setRotation(dangle1);}

修改块中实体到相同图层

 void ModifyEntInBlkToSameLayer(){// 得到层IDAcDbObjectId layerId;AcDbLayerTable *pLayerTbl = NULL;if (acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl, AcDb::kForRead) != Acad::eOk)return;if (pLayerTbl->getAt(L"0", layerId) != Acad::eOk){pLayerTbl->close();return;}pLayerTbl->close();// 打开块表进行操作Acad::ErrorStatus es;AcDbBlockTable *pBlockTable = NULL;es = acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead);if (es != Acad::eOk) return;AcDbBlockTableIterator *pBlkIter = NULL;if (pBlockTable->newIterator(pBlkIter) != Acad::eOk){pBlockTable->close();return;}pBlockTable->close();// 遍历所有块表记录,找出插入快,设置新层AcDbBlockTableRecord *pRecord = NULL;AcDbBlockTableRecordIterator *pRcdIter = NULL;AcDbEntity *pEnt = NULL;AcDbObjectIdArray Ids;for (; !pBlkIter->done(); pBlkIter->step()){if (pBlkIter->getRecord(pRecord, AcDb::kForWrite) != Acad::eOk){continue;}// 判断是否是插入块if (pRecord->getBlockReferenceIds(Ids) != Acad::eOk || Ids.length() == 0){pRecord->close();continue;}if (pRecord->newIterator(pRcdIter) != Acad::eOk){pRecord->close();continue;}// 遍历该块表记录,设置新层for (; !pRcdIter->done(); pRcdIter->step()){if (pRcdIter->getEntity(pEnt, AcDb::kForWrite) != Acad::eOk){continue;}pEnt->setLayer(layerId);pEnt->close();}delete pRcdIter;pRcdIter = NULL;pRecord->close();}delete pBlkIter;pBlkIter = NULL;acDocManager->sendStringToExecute(acDocManager->curDocument(), "regen ");}

炸块相关

static void explodeBlk()
{// Put your command code hereads_name ss;if (RTNORM != acedSSGet(NULL, NULL, NULL, NULL, ss)){return;}Adesk::Int32 slen;acedSSLength(ss, &slen);ads_name en;AcDbObjectId id;AcDbEntity* pEnt = NULL;Acad::ErrorStatus es;AcDbVoidPtrArray ids;for (long i = 0; i < slen; i++){acedSSName(ss, i, en);acdbGetObjectId(id, en);es = acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite);if (es == Acad::eOk);{es = pEnt->explode(ids);}if (pEnt != NULL){pEnt->close();}}if (ids.isEmpty()){return;}int j = 0;AcDbBlockTableRecordPointer btr(curDoc()->database()->currentSpaceId(), AcDb::kForWrite);if (btr.openStatus() != Acad::eOk){return;}bool flag = true;while (flag){pEnt = (AcDbEntity *)ids.at(j);if (pEnt->explode(ids) != Acad::eOk){btr->appendAcDbEntity(pEnt);pEnt->close();}j++;if (j == ids.logicalLength())flag = false;}
}

计算AcDbBlockReference准确的包围盒

AcDbExtents CEntity::GetRefBoundingBox(AcDbBlockReference *pRef, const AcGeMatrix3d & mat)
{AcDbExtents ext;AcDbExtents RetExt;AcDbObjectId recId = pRef->blockTableRecord();AcDbBlockTableRecordPointer block(recId, AcDb::kForRead);Acad::ErrorStatus es = block.openStatus();if (es == eOk){AcDbBlockTableRecordIterator *pItr = NULL;block->newIterator(pItr);AcDbObjectId id;AcDbEntity *pEnt = NULL;for (pItr->start(); !pItr->done(); pItr->step()){es = pItr->getEntity(pEnt, AcDb::kForWrite);if (es == eOk){pEnt->transformBy(mat);if (pEnt->isKindOf(AcDbBlockReference::desc())){AcGeMatrix3d blkmat = ((AcDbBlockReference*)pEnt)->blockTransform();ext = GetRefBoundingBox((AcDbBlockReference *)pEnt, blkmat);}else{pEnt->getGeomExtents(ext);}pEnt->transformBy(mat.inverse());RetExt.addExt(ext);pEnt->close();}}delete pItr;pItr = NULL;}return RetExt;
}
//eg:
AcDbObjectPointer<AcDbBlockReference> blkref(id, AcDb::kForRead);     //id块参照的id
AcDbExtents  ext = CEntity::GetRefBoundingBox(blkref.object(), blkref->blockTransform());

分割块

static Acad::ErrorStatus MoveToBlockDefinition(AcDbObjectId idBlockRef, AcDbObjectIdArray &ids)
{Acad::ErrorStatus es;AcDbObjectPointer<AcDbBlockReference> pRef(idBlockRef, AcDb::kForRead);if ((es = pRef.openStatus()) != Acad::eOk) return es;// Матрица преобразования Block Reference OCS -> WCSAcGeMatrix3d xform = pRef->blockTransform();pRef->close(); // Чтобы не мешаласьAcDbBlockTableRecordPointer pBtr(pRef->blockTableRecord(), AcDb::kForRead);if ((es = pBtr.openStatus()) != Acad::eOk) return es;AcGePoint3d pt3dBlkOrigin = pBtr->origin();// Учитываем возможность ненулевой базовой точки блока (Block Definition)if (pt3dBlkOrigin != AcGePoint3d::kOrigin) {AcGeVector3d xformOrigin = xform.translation();AcGeVector3d vectorOrigin(pt3dBlkOrigin.x, pt3dBlkOrigin.y, pt3dBlkOrigin.x);vectorOrigin.transformBy(xform);xformOrigin -= vectorOrigin;xform.setTranslation(xformOrigin);}// Инвертируем матрицу преобразования, чтобы преобразовывать// из WCS в систему координат блокаxform.invert();if ((es = pBtr->upgradeOpen()) != Acad::eOk) return es;// Перебрасываем все примитивы в блокif ((es = pBtr->assumeOwnershipOf(ids)) != Acad::eOk) return es;// Теперь выполним трансформацию всех примитивов по матрице xformfor (int i = 0; i < ids.length(); i++) {AcDbObjectPointer<AcDbEntity> pEnt(ids[i], AcDb::kForWrite);if (pEnt.openStatus() == Acad::eOk) {pEnt->transformBy(xform);}}// Обновим все вставки этого блокаAcDbObjectIdArray idRefs;pBtr->getBlockReferenceIds(idRefs);pBtr->close();for (int i = 0; i < idRefs.length(); i++) {AcDbObjectPointer<AcDbEntity> pEnt(idRefs[i], AcDb::kForWrite);if (pEnt.openStatus() == Acad::eOk) {pEnt->recordGraphicsModified();}}return es;
}
//------------------------------
//    Команда MoveToBlock
//------------------------------
static void MoveToBlock(void)
{Acad::ErrorStatus es;ads_name en, ss;ads_point p;if (acedEntSel(L"\n选择一个块实体", en, p) != RTNORM) return;acutPrintf("\nВыберите примитивы для добавления в блок: ");if (acedSSGet(NULL, NULL, NULL, NULL, ss) != RTNORM) return;AcDbObjectIdArray ids;AcDbObjectId idBlk, id;  acdbGetObjectId(idBlk, en);long nEnt = 0; acedSSLength(ss, &nEnt);if (!nEnt) return;ids.setLogicalLength(nEnt);for (int i = 0; i < nEnt; i++) {acedSSName(ss, i, en);acdbGetObjectId(id, en);ids[i] = id;}if ((es = MoveToBlockDefinition(idBlk, ids)) != Acad::eOk) {acutPrintf("\nMoveToBlockDefinition(idBlk,ids)=%s", acadErrorStatusText(es));}
}

XClip外部参照

关于这个介绍可以移步
这里讨论 ObjectARX中XClip相关用法

ACED_ARXCOMMAND_ENTRY_AUTO(CMyTestApp,MyTestApp,_MyClip, MyClip,ACRX_CMD_TRANSPARENT |ACRX_CMD_NOINTERNALLOCK,NULL)static void MyTestApp_MyClip()
{ads_point pt1, pt2;ads_name ent;if (acedEntSel(_T("Select xref:"), ent, pt1) != RTNORM)return;AcDbObjectId idXref;if (acdbGetObjectId(idXref, ent) != Acad::eOk)return;AcDbObjectPointer<AcDbBlockReference> pRef(idXref, AcDb::kForRead);if (pRef.openStatus() != Acad::eOk){acutPrintf(_T("Not an xref!\n"));return;}AcGePoint2dArray pts;if (acedGetPoint(NULL, _T("First point:"), pt1) != RTNORM)return;//the ECS of the vertices must be defined in the//coordinate system of the _block_ so let's calculate//transform all points to that coordinate systemAcGeMatrix3d mat(pRef->blockTransform());mat.invert();AcGePoint3d pt3d(asPnt3d(pt1));pt3d.transformBy(mat);pts.append(AcGePoint2d(pt3d.x, pt3d.y));while (acedGetPoint(pt1, _T("Next point:"), pt2) == RTNORM){acedGrDraw(pt1, pt2, 1, 1);pt3d = asPnt3d(pt2);pt3d.transformBy(mat);pts.append(AcGePoint2d(pt3d.x, pt3d.y));memcpy(pt1, pt2, sizeof(ads_point));}acedRedraw(NULL, 0);AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();AcGeVector3d normal;double elev;if (pDb->tilemode()){normal = pDb->ucsxdir().crossProduct(pDb->ucsydir());elev = pDb->elevation();}else{normal = pDb->pucsxdir().crossProduct(pDb->pucsydir());elev = pDb->pelevation();}normal.normalize();Acad::ErrorStatus es = pRef.object()->upgradeOpen();if (es != Acad::eOk)return;//create the filterAcDbSpatialFilter* pFilter = new AcDbSpatialFilter;if (pFilter->setDefinition(pts, normal, elev,ACDB_INFINITE_XCLIP_DEPTH, -ACDB_INFINITE_XCLIP_DEPTH, true) != Acad::eOk){delete pFilter;return;}//add it to the extension dictionary of the block reference//the AcDbIndexFilterManger class provides convenient utility functionsif (AcDbIndexFilterManager::addFilter(pRef.object(), pFilter) != Acad::eOk)delete pFilter;else{acutPrintf(_T("Filter has been succesfully added!\n"));pFilter->close();}
}

获取外部参照图块

bool getObjects(ACHAR *xRefName, ACHAR *layer, std::vector<AcDbEntity*> *objects, AcGeMatrix3d *transform)
{Acad::ErrorStatus errorStatus;AcDbDatabase *database = acdbHostApplicationServices()->workingDatabase();AcDbBlockTable *blockTable = NULL;AcDbBlockTableRecord *modelBlockTableRecord = NULL;AcDbBlockTableRecord *blockTableRecord = NULL;AcDbDatabase *xRefDatabase = NULL;const ACHAR *xRefPath = NULL;AcDbDatabase *xRefDWGDatabase = NULL;AcDbBlockTable *xRefBlockTable = NULL;AcDbBlockTableRecord *xRefBlockTableRecord = NULL;//Get the block table for our databaseerrorStatus = database->getBlockTable(blockTable, AcDb::kForRead);if (errorStatus != Acad::eOk){acutPrintf(L"\nError getting block table %s", acadErrorStatusText(errorStatus));return false;}//Get the table record in model spaceerrorStatus = blockTable->getAt(ACDB_MODEL_SPACE, modelBlockTableRecord, AcDb::kForRead);if (errorStatus != Acad::eOk){acutPrintf(L"\nError getting model space block table record %s", acadErrorStatusText(errorStatus));blockTable->close();return false;}//Get the block table record for the external referenceerrorStatus = blockTable->getAt(xRefName, blockTableRecord, AcDb::kForRead);if (errorStatus != Acad::eOk){acutPrintf(L"\nError could not get xref %s %s", xRefName, acadErrorStatusText(errorStatus));modelBlockTableRecord->close();blockTable->close();return false;}xRefDatabase = blockTableRecord->xrefDatabase(true);if (xRefDatabase == NULL){acutPrintf(L"\nCould not get external reference database");modelBlockTableRecord->close();blockTable->close();blockTableRecord->close();return false;}//Get path for external reference dwg filexRefPath = acdbOriginalXrefFullPathFor(xRefDatabase);if (xRefDatabase == NULL){acutPrintf(L"\nCould not get external reference path");modelBlockTableRecord->close();blockTable->close();blockTableRecord->close();return false;}//Get database for the external reference drawingxRefDWGDatabase = new AcDbDatabase(Adesk::kFalse);errorStatus = xRefDWGDatabase->readDwgFile(xRefPath);if (errorStatus != Acad::eOk){acutPrintf(L"\nError could not read xref file %s", acadErrorStatusText(errorStatus));modelBlockTableRecord->close();blockTable->close();blockTableRecord->close();return false;}//Get the block table for the open model reference fileerrorStatus = xRefDWGDatabase->getBlockTable(xRefBlockTable, AcDb::kForRead);if (errorStatus != Acad::eOk){acutPrintf(L"\nError could not load xref block table %s", acadErrorStatusText(errorStatus));modelBlockTableRecord->close();blockTable->close();blockTableRecord->close();return false;}//Get the definition for the block in the the external referenceerrorStatus = xRefBlockTable->getAt(L"TRINA 335W MODULE", xRefBlockTableRecord, AcDb::kForRead);if (errorStatus != Acad::eOk){acutPrintf(L"\nError could not get xref block table record %s", acadErrorStatusText(errorStatus));modelBlockTableRecord->close();blockTable->close();blockTableRecord->close();xRefBlockTable->close();return false;}AcDbObjectIdArray blockIds;errorStatus = xRefBlockTableRecord->getBlockReferenceIds(blockIds);if (errorStatus != Acad::eOk){acutPrintf(L"\nError could not get xref block ids %s", acadErrorStatusText(errorStatus));modelBlockTableRecord->close();blockTable->close();blockTableRecord->close();xRefBlockTable->close();xRefBlockTableRecord->close();return false;}for (int i = 0; i < blockIds.length(); i++){AcDbEntity *ent = NULL;acdbOpenObject(ent, blockIds.at(i), AcDb::kForRead);if (ent != NULL){objects->push_back(ent);}}modelBlockTableRecord->close();blockTable->close();blockTableRecord->close();xRefBlockTable->close();xRefBlockTableRecord->close();return true;
}

动态块相关

相关介绍
取块名称

 static void DynTest(void){ads_name en; ads_point p;if (acedEntSel(_T("\n选择一个块: "), en, p) == RTNORM){AcDbObjectId eId; acdbGetObjectId(eId, en);AcDbObjectPointer<AcDbBlockReference> pBlkRef(eId, AcDb::kForRead);if (pBlkRef.openStatus() == Acad::eOk){AcDbObjectId idBlkTblRec = pBlkRef->blockTableRecord();AcDbDynBlockReference dynBlk(eId);if (dynBlk.isDynamicBlock()){AcDbBlockTableRecordPointer pBTR(dynBlk.dynamicBlockTableRecord(), AcDb::kForRead);if (pBTR.openStatus() == Acad::eOk){const ACHAR *blkName = NULL; pBTR->getName(blkName);acutPrintf(_T("\n动态块名称: "%s""), blkName);}}else{AcDbBlockTableRecordPointer pBTR(pBlkRef->blockTableRecord(), AcDb::kForRead);const ACHAR *blkName = NULL; pBTR->getName(blkName);acutPrintf(_T("\n普通块名称: "%s""), blkName);}}}}

匿名块

class BlockDrawCar
{public:void DrawBlock(AcDbBlockTableRecord *btr){Acad::ErrorStatus es;// Draw a rectangle polylineAcDbPolyline *pline = new AcDbPolyline();AcGePoint2d p0(0.0, 0.0), p1(m_Length, 0.0);AcGePoint2d p2(m_Length, m_Width), p3(0.0, m_Width);pline->addVertexAt(0, p0);pline->addVertexAt(1, p1);pline->addVertexAt(2, p2);pline->addVertexAt(3, p3);pline->setClosed(true);pline->setDatabaseDefaults();pline->setColorIndex(m_Color);es = btr->appendAcDbEntity(pline);if (!es)pline->close();elsedelete pline;// Draw a circleAcDbCircle *circle = new AcDbCircle();AcGePoint3d center(m_Width / 2, m_Width / 2, 0.0);double radius = m_Width * 0.4;circle->setCenter(center);circle->setRadius(radius);circle->setDatabaseDefaults();circle->setColorIndex(m_Color);es = btr->appendAcDbEntity(circle);if (!es)circle->close();elsedelete circle;}public:int m_Color=7;double m_Width=200;double m_Length=340;
};AcDbObjectId CreateCarBlock(AcDbDatabase *db, LPCWSTR blockname)
{Acad::ErrorStatus es;AcDbBlockTableRecord *btr = new AcDbBlockTableRecord;BlockDrawCar *car = new BlockDrawCar;car->DrawBlock(btr);btr->setName(blockname);// Add the BTR to the Blocktable of the current drawingAcDbObjectId BtrID;AcDbBlockTable *blocktable;es = db->getBlockTable(blocktable, AcDb::kForWrite);if (!es){es = blocktable->add(BtrID, btr);if (!es)btr->close();elsedelete btr;blocktable->close();}return BtrID;
}AcDbObjectId FindBlock(AcDbDatabase *db, LPCWSTR blockname)
{AcDbObjectId BlockID;Acad::ErrorStatus es;AcDbBlockTable *blocktable;es = db->getBlockTable(blocktable, AcDb::kForRead);if (!es){es = blocktable->getAt(blockname, BlockID);blocktable->close();}return BlockID;
}Acad::ErrorStatus PostToDb(AcDbDatabase *db, AcDbObjectId& objId, AcDbEntity* pEnt)
{Acad::ErrorStatus      es;AcDbBlockTable*        blocktable = 0;AcDbBlockTableRecord*  modelspace = 0;if ((es = db->getBlockTable(blocktable, AcDb::kForRead)) != Acad::eOk)return es;if ((es = blocktable->getAt(ACDB_MODEL_SPACE, modelspace, AcDb::kForWrite)) == Acad::eOk){es = modelspace->appendAcDbEntity(objId, pEnt);modelspace->close();}blocktable->close();return es;
}void cmdDrawCar()
{Acad::ErrorStatus es;LPCWSTR blockname = L"*U"; // Blockname. This is for an unnamed block.blockname = L"car"; // And this for a named blockAcDbDatabase *db = acdbHostApplicationServices()->workingDatabase();AcDbObjectId BtrID;if (blockname[0]!=L'*') // '*' as first char means: Unnamed block. Don't search for it.BtrID = FindBlock(db, blockname); // Search for an existing named blockif (BtrID.isNull())BtrID = CreateCarBlock(db, blockname); // For "*U" AutoCAD will create unique names like "*U1", "*U2", ...if (BtrID.isNull()){acutPrintf(L"\nFailed.");return;}// Now create a block referenceAcDbBlockReference *bref = new AcDbBlockReference;bref->setDatabaseDefaults();bref->setBlockTableRecord(BtrID);AcGeVector3d insertionPoint;acedGetPoint(nullptr, L"\nInsertion point: ", asDblArray(insertionPoint));AcGeMatrix3d trans; // the transformation matrixtrans.setToTranslation(insertionPoint);bref->setBlockTransform(trans);// Append it to modelspaceAcDbObjectId BrefID;es = PostToDb(db, BrefID, bref);if (!es)bref->close();elsedelete bref;
}

eg:

lockDrawCar car;
car.DrawBlock(btr);orBlockDrawCar *car = new BlockDrawCar;
car->DrawBlock(btr);
delete car;
  • 另一种方法创建
    //待补充

  • 给块加上拓展记录XData

struct resbuf {struct resbuf *rbnext; // Allows them to be "linked"short restype;union ads_u_val resval;
};LPCWSTR myAppName = L"MYAPP";void setCarXData(AcDbBlockReference *brefCar) // brefCar must be open for write
{acdbRegApp(myAppName); // Make sure your XData appname is registeredresbuf *rb = acutBuildList(AcDb::kDxfRegAppName, myAppName,AcDb::kDxfXdAsciiString, L"Car",AcDb::kDxfXdControlString, L("{"),AcDb::kDxfXdAsciiString, L"Lamborghini", //nameAcDb::kDxfXdReal, 250.0,                                   //max speedAcDb::kDxfXdInteger16, 2,                           //number of seatsAcDb::kDxfXdControlString, L("}"),0);brefCar->setXData(rb); // this will replace the XData for myAppNameacutRelRb(rb); // release the list.
}void getCarXData(AcDbBlockReference *brefCar) // brefCar must be open for read
{resbuf *rb = brefCar->XData(myAppName);  // get XData for myAppName// -- use rb here --acutRelRb(rb); // release the list.
}

获取裁剪块的边界

bool TransModelHelper::drawAPlineWithPropertiesFromBlockRef(AcGePoint2dArray pts, AcDbBlockReference* ref, double elevation, AcGeVector3d& normal)
{AcDbPolyline *pl = new AcDbPolyline;AcDbObjectId owner;pl->setDatabaseDefaults();pl->setClosed(Adesk::kTrue);pl->setThickness(0.0);if (ref != NULL){owner = ref->ownerId();pl->setPropertiesFrom(ref);}pl->setNormal(normal);for (int i = 0; i < pts.length(); i++){pl->addVertexAt(i, pts[i]);}pl->setElevation(elevation);pl->setColorIndex(1); // RedAcDbBlockTableRecord *rec = NULL;acdbOpenObject(rec, owner, AcDb::kForWrite);if (rec != NULL){AcDbObjectId id;rec->appendAcDbEntity(id, pl);pl->close();rec->close();}else{delete pl;return false;}return true;
}bool TransModelHelper::GetBlockClippingPolyline(ads_name blk, AcGePoint3dArray& pts3d)
{BOOL ret = FALSE;AcDbBlockReference *ref = NULL;AcDbObjectId insId = AcDbObjectId::kNull;acdbGetObjectId(insId, blk);if (acdbOpenObject(ref, insId, AcDb::kForRead) != Acad::eOk)return ret;// Find the clipping object (AcDbSpatialFilter) in the ExtDict of the BlockRefAcDbObjectId extDicId = ref->extensionDictionary();if (extDicId == AcDbObjectId::kNull)return ret;AcDbDictionary *extDict = NULL, *acadFilterDict = NULL;if (acdbOpenObject(extDict, extDicId, AcDb::kForRead) != Acad::eOk)return ret;Acad::ErrorStatus err = extDict->getAt(_T("ACAD_FILTER"), (AcDbObject*&)acadFilterDict, AcDb::kForRead);extDict->close();if (err != Acad::eOk)return ret;AcDbSpatialFilter *filter = NULL;err = acadFilterDict->getAt(_T("SPATIAL"), (AcDbObject*&)filter, AcDb::kForRead);acadFilterDict->close();if (err != Acad::eOk)return ret;// Get the transform matrix stored in the XClip boundaryAcGeMatrix3d xformInBoundary = filter->getClipSpaceToWCSMatrix(xformInBoundary);// and the transform of the BlockRef at the time when the Filter was setAcGeMatrix3d xformRefOrig = filter->getOriginalInverseBlockXform(xformRefOrig);// Get the transform matrix that the current BlockRef has, so, we can find the difference// with the xformRefOrigAcGeMatrix3d refMatrix = ref->blockTransform();refMatrix = refMatrix.postMultBy(xformRefOrig);// Calculate the final transform matrix which applies to the points// returned from filter->getDefinition().AcGeMatrix3d finalMatrix = refMatrix.postMultBy(xformInBoundary);AcGePoint2dArray pts;//AcGePoint3dArray pts3d;AcGeVector3d normal;double elevation = 0, frontClip = 0, backClip = 0;Adesk::Boolean enabled = false;// Get all boundary pointsif (filter->getDefinition(pts, normal, elevation, frontClip, backClip, enabled) == Acad::eOk){// Rectanglar boundaryif (pts.length() == 2){AcGePoint2d p1(pts[1].x, pts[0].y);AcGePoint2d p3(pts[0].x, pts[1].y);pts.insertAt(1, p1);pts.insertAt(3, p3);}// Transform all points with the transform matrix we calculatedfor (int i = 0; i < pts.length(); i++){AcGePoint2d pt2d;AcGePoint3d pt3d;pt2d = pts[i];pt3d[0] = pt2d[0]; pt3d[1] = pt2d[1]; pt3d[2] = 0;pt3d.transformBy(finalMatrix);pts3d.append(pt3d);}}// Get the new normal and new ECS information for the polyline.AcGeVector3d xfnorm = normal.transformBy(finalMatrix);AcGeMatrix3d plineECS;AcDbPolyline* pline = new AcDbPolyline();pline->setNormal(xfnorm);pline->getEcs(plineECS);delete pline; pline = NULL;AcGeMatrix3d plineECSInv = plineECS.inverse();double xfelev = 0.0;for (int i = 0; i < pts.length(); i++){pts[i].x = pts3d[i].x;pts[i].y = pts3d[i].y;if (i == 0)xfelev = pts3d[i].z;// Should be identical to within roundoffassert(fabs(xfelev - pts3d[i].z) < 1.0e-10);}// Show the boundary
#ifdef _RELEASE_WITHDEBUGdrawAPlineWithPropertiesFromBlockRef(pts, ref, xfelev, xfnorm);
#endiffilter->close();ref->close();return true;
}bool TransModelHelper::GetBlockClippingPolyline(AcDbObjectId idBlkRef, AcGePoint3dArray& pts3d)
{ads_name snBlk;acdbGetAdsName(snBlk, idBlkRef);if (snBlk == NULL) return false;return GetBlockClippingPolyline(snBlk, pts3d);
}//test:
//
//ads_point pt1;
//ads_name ent;
//if (acedEntSel(_T("请选择裁剪的块:"), ent, pt1) != RTNORM)
//return;
//
//AcGePoint2dArray pts;
//if (!GetBlockClippingPolyline(ent, pts))
//return;

碰到的BUG

删掉了块参照,但我拷贝的实体却不知在哪里?

ARX关于块的相关疑难问题整理相关推荐

  1. 【python语言基础】疑难点整理2

    [python语言基础]疑难点整理1 第五章 在python语法中,循环体中的语句没有做限制,因此,可以是任何合法语句,当然也可以是循环语句.这样就形成了循环语句的嵌套. while循环语句和for循 ...

  2. 最详细的SQL注入相关的命令整理

    最详细的SQL注入相关的命令整理   QUOTE: 1.   用^转义字符来写ASP(一句话***)文件的方法: ?   http://192.168.1.5/display.asp?keyno=18 ...

  3. Octave相关学习资源整理出

    Octave相关学习资源整理 斯坦福大学机器学习公开课第五课是"Octave Tutorial",主要是机器学习公开课的编程作业需要用Octave完成,同样需要用Octave完成作 ...

  4. 推荐系统相关顶会整理

    推荐系统相关顶会整理算法工程师是否应该持续读论文?\x0d\x0a\x0d\x0a尤其是对于业务属性偏重的搜索/推荐/广告算法岗位,很多人的工作主要涉及业务理解以及数据清洗,对于模型的优化以及新模型的 ...

  5. 嵌入式相关芯片资料整理

    嵌入式相关芯片资料整理 各类芯片简介 **嵌入式相关芯片资料整理** 一.TFT_LCD芯片简介 二.M74HC688MR芯片简介 三.M74HC573M1R芯片简介 四.STM32F103RBT6芯 ...

  6. PMP报考相关详细内容整理

    PMP报考相关详细内容整理 一.考试简介 二.PMP 入门知识 三.考试报名 四.报名流程 1)PMP 英文报名 2)审核 3)中文报名 4)在线支付费用 付费实现通道 五.考试费用 六.成绩及分数 ...

  7. linux多磁盘块文件删除过程,如何整理Linux磁盘碎片

    Linux界曾经有过这样一个神话:Linux操作系统永远不需要整理磁盘碎片,相信很多人都听说过.由于Linux采用了优秀的日志文件系统(ext2.ext3.ext4,btrfs等),现在基本上不用ex ...

  8. Ksh if判断中与文件相关的选项整理

    整理了下Ksh中if判断中与文件相关的各种选项 选项 描述 -a File 如果指定的文件是指向另一个存在的文件的符号链接,则为True. -b File 如果指定的文件存在并且是块特殊文件,则为Tr ...

  9. 深度学习总结——CS231n课程深度学习(机器视觉相关)笔记整理

    深度学习笔记整理 说明 基本知识点一:模型的设置(基本) 1. 激活函数的设置 2. 损失函数的设置 (1) 分类问题 (2) 属性问题 (3) 回归问题 3. 正则化方式的设置 (1) 损失函数添加 ...

最新文章

  1. web前端 —— 移动端知识的一些总结
  2. GUI_PICTURE以及context_menu学习笔记
  3. 为什么要用TypeScript
  4. pythonchar中的拟合方法_在python中利用numpy求解多项式以及多项式拟合的方法
  5. 关于类、抽象类和接口的继承关系
  6. Java集合转化为数组
  7. mysql面试常问 1: 谈谈MySQL表级锁和行级锁
  8. ab 服务器压力测试工具 使用详解
  9. 程序员离不开这 7 大编程方法!
  10. 乐观锁 与 悲观锁 来解决数据库并发问题
  11. mysql system账户密码忘记了_MySQL数据库root账户密码忘记两种处理方法(保有效)...
  12. 关于一些Silverlight中常用的尺寸,慢慢记录
  13. 大数据时代下的用户洞察:用户画像建立(ppt版)
  14. mysql卸载安装pxc_PXC 5.7.14 安装部署
  15. 如何将经典算法与人工智能结合?NeurIPS 2021
  16. 小程序页面简单功能模块化之取整
  17. Android移动开发
  18. java中statistic_Java Statistic類代碼示例
  19. 做月饼-制作过程及图文笔记
  20. 一文看懂苹果WWDC20:iOS 14更好玩,可Intel要哭瞎了

热门文章

  1. 掌握三代全长转录组测序,看这一篇就够了!
  2. SD卡变成RAW格式怎么办?SD卡RAW格式的解决办法
  3. 能自由转换格式的PDF软件
  4. 日文个别难打的假名打法总结
  5. Windows、Unix、Mac不同操作系统的换行问题 回车符\r和换行符\n
  6. c语言 __at定位编译报错,david
  7. 买游戏来运营_游戏化思维帮你玩转社群运营
  8. CAD梦想画图中的“绘图工具——圆”
  9. 每天可以一看的哲理句子
  10. Linux命令行下使用飞信