//-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "dbsymutl.h"
#include "resource.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CXrefEntityCloneApp : public AcRxArxApp {
public:
CXrefEntityCloneApp() : AcRxArxApp() {}
virtual AcRx::AppRetCode On_kInitAppMsg(void *pkt) {
AcRx::AppRetCode retCode = AcRxArxApp::On_kInitAppMsg(pkt);
return (retCode);
}
virtual AcRx::AppRetCode On_kUnloadAppMsg(void *pkt) {
AcRx::AppRetCode retCode = AcRxArxApp::On_kUnloadAppMsg(pkt);
return (retCode);
}
virtual void RegisterServerComponents() {}
static void RivilisNCopy2() {
AcDbObjectId idCurrentModelSpace =
AcDbSymbolUtilities::servicesPtr()->blockModelSpaceId(acdbCurDwg());
AcGePoint3d p; ads_name en; AcGeMatrix3d mat; resbuf *rb = nullptr;
Acad::ErrorStatus es;
if (acedNEntSelP(L"\nSelect XREF for clone: ", en, asDblArray(p), FALSE, mat.entry, &rb) == RTNORM)
{
if (!rb) {
acutPrintf(L"\nIt is not XREF!");
return;
}
AcDbObjectId idSel; acdbGetObjectId(idSel, en);
for (resbuf *rbstart = rb; rbstart->rbnext != nullptr; rbstart = rbstart->rbnext) {
acdbGetObjectId(idSel, rbstart->resval.rlname);
}
if (idSel.database() == acdbCurDwg()) {
acutPrintf(L"\nIt is not XREF!");
return;
}
AcDbObjectIdArray ids;
AcDbDatabase *pTempDb = new AcDbDatabase(false);
AcDbHandle hand = idSel.handle();
AcString filepath = idSel.database()->originalFileName();
if ((es = pTempDb->readDwgFile(filepath)) == Acad::eOk) {
if (pTempDb->getAcDbObjectId(idSel, false, hand) == Acad::eOk) {
ids.append(idSel);
}
if (ids.length() > 0) {
AcDbIdMapping idMapping;
if ((es = acdbCurDwg()->wblockCloneObjects(ids, idCurrentModelSpace, idMapping, AcDb::kDrcIgnore)) == Acad::eOk) {
AcDbIdMappingIter iter(idMapping);
for (iter.start(); !iter.done(); iter.next()) {
AcDbIdPair pair;
if (iter.getMap(pair) && pair.isPrimary()) {
AcDbEntityPointer pEnt(pair.value(), AcDb::kForWrite);
if (pEnt.openStatus() == Acad::eOk) {
pEnt->transformBy(mat);
}
}
}
}
}
}
if (pTempDb) delete pTempDb;
}
}
};
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CXrefEntityCloneApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CXrefEntityCloneApp, Rivilis, NCopy2, NCopy2, ACRX_CMD_MODAL, NULL)