//-----------------------------------------------------------------------------
//----- acrxEntryPoint.h
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CPolyApp : public AcRxArxApp {
public:
CPolyApp () : 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 () {
}
public:
static Acad::ErrorStatus ObjectIdArrayFromSelSet(ads_name sset, AcDbObjectIdArray &ids)
{
Acad::ErrorStatus es = Acad::eOk;
long nset = -1;
if (acedSSLength(sset,&nset) != RTNORM) return Acad::eAmbiguousInput;
ids.setLogicalLength(nset);
ads_name en;
AcDbObjectId id;
for (long i=0; i < nset; i++) {
if (acedSSName(sset,i,en) == RTNORM) {
if ((es = acdbGetObjectId(id,en)) != Acad::eOk) return es;
ids[i] = id;
}
}
return Acad::eOk;
}
static Acad::ErrorStatus postToDwgAndClose (AcDbEntity *pEnt, AcDbDatabase *pDb = NULL, ACHAR *requiredSpace = NULL)
{
// if the default database is to be used
if (pDb == NULL) {
pDb = acdbHostApplicationServices ()->workingDatabase ();
}
AcDbBlockTable *blockTable = NULL;
// get a pointer to the block table
Acad::ErrorStatus es = pDb->getBlockTable (blockTable, AcDb::kForRead);
// if it failed then abort
if (es != Acad::eOk)
return (es);
AcDbBlockTableRecord *blockTableRecord = NULL;
// now get a pointer to the model space entity records
if (requiredSpace) {
es = blockTable->getAt (requiredSpace, blockTableRecord, AcDb::kForWrite);
} else {
es = acdbOpenObject(blockTableRecord, pDb->currentSpaceId(), AcDb::kForWrite);
}
// can close the block table itself as we don't need it anymore
blockTable->close ();
// if it failed then abort
if (es != Acad::eOk)
return (es);
// otherwise put the entity into the model space
es = blockTableRecord->appendAcDbEntity (pEnt);
// now close it up
blockTableRecord->close();
// close entity
pEnt->close();
return (es);
}
// - Poly.Poly3dto2d command (do not rename)
static void PolyPoly3dto2d(void)
{
resbuf *prbGrip = NULL, *prbPick = NULL;
ads_name sset_templ = { 0, 0};
long len_templ = 0;
AcDbObjectIdArray ids_set,ids_templ;
AcDbVoidPtrArray ents_templ;
resbuf *filter = acutBuildList(-4,_T("<and"),RTDXF0,_T("POLYLINE"),-4,_T("&"),70,8,-4,_T("and>"),RTNONE);
if (acedSSGetFirst(&prbGrip, &prbPick) == RTNORM && acedSSLength(prbPick->resval.rlname, &len_templ) == RTNORM && len_templ > 0) {
ObjectIdArrayFromSelSet(prbPick->resval.rlname,ids_templ); acedSSFree(prbPick->resval.rlname);
} else {
TCHAR* promptPtrs[] = { _T("\nВыберите 3D-полилинии: "), _T("\nУдалите из выбранного: ") };
if (acedSSGet(_T(":$"),promptPtrs,NULL,filter,sset_templ) == RTNORM) {
ObjectIdArrayFromSelSet(sset_templ,ids_templ); acedSSFree(sset_templ);
}
}
acutRelRb(filter);
for (int i=0; i < ids_templ.length(); i++) {
AcDbObjectPointer<AcDb3dPolyline> poly3d(ids_templ[i],AcDb::kForWrite);
if (poly3d.openStatus() == Acad::eOk) {
AcGePoint3dArray pts; AcDbObjectIterator *pVtxIt = poly3d->vertexIterator();
if (pVtxIt) {
AcDbObjectId firstId = pVtxIt->objectId();
if(pVtxIt->objectId().isErased()) { // Пропускаем удалённые вершины
pVtxIt->step(); firstId = pVtxIt->objectId();
}
for (pVtxIt->setPosition(firstId); !pVtxIt->done(); pVtxIt->step()){
if(pVtxIt->objectId().isErased()) continue;
AcDbObjectPointer<AcDb3dPolylineVertex> pVt(pVtxIt->objectId(), AcDb::kForRead);
if (pVt.openStatus() != Acad::eOk) continue;
pts.append(pVt->position());
}
if (pts.length() > 1) {
AcDbPolyline *poly2d = new AcDbPolyline();
poly2d->setLayer(poly3d->layerId());
poly2d->setLinetype(poly3d->linetypeId());
poly2d->setLinetypeScale(poly3d->linetypeScale());
poly2d->setLineWeight(poly3d->lineWeight());
for (int iv=0; iv < pts.length(); iv++)
poly2d->addVertexAt(iv,asPnt2d(asDblArray(pts[iv])));
poly2d->setClosed(poly3d->isClosed());
postToDwgAndClose(poly2d);
poly3d->erase();
}
delete pVtxIt;
}
}
}
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CPolyApp)
ACED_ARXCOMMAND_ENTRY_AUTO(CPolyApp, Poly, Poly3dto2d, Poly3dto2d, ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, NULL)