Author Topic: acedVPLayer doesnt't work, and crash  (Read 105 times)

0 Members and 1 Guest are viewing this topic.

nolanjian

  • Mosquito
  • Posts: 7
acedVPLayer doesnt't work, and crash
« on: September 18, 2017, 02:28:40 am »
Hi, community,
I have two viewports A & B in a layout and multi layers. I want to only active layer A on viewport A and only active layer B on viewport B.
But, it since doen't work, viewport A freeze all, viewport B only thaw layer B, which is right. Why have this difference?
And I found that it will have a crash on exiting autocad.
 
here is my code:
Code: [Select]
void ActiveLayerOnly(const CString& strLayout, int nViewportIndex, const CString& strLayer)
{
AcDbViewport* pViewport = GetViewport(strLayout, nViewportIndex);

if (pViewport == nullptr)
{
ASSERT(pViewport != nullptr);
return;
}

int nRetActiveLayout = acedCommand(RTSTR, _T("layout"), RTSTR, _T(""), RTSTR, strLayout, 0);
ASSERT(nRetActiveLayout == RTNORM);

acedMspace();

Acad::ErrorStatus esSC = acedSetCurrentVPort(pViewport);
ASSERT(es == Acad::eOk);

AcDbLayerTable* pLayerTable = nullptr;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable, kForWrite);

AcDbObjectIdArray vlayerIDFreeze;
AcDbObjectIdArray vlayerIDThaw;

AcDbLayerTableIterator* pItrLayer = nullptr;
if (pLayerTable->newIterator(pItrLayer) == Acad::eOk && pItrLayer)
{
for (pItrLayer->start(); !pItrLayer->done(); pItrLayer->step())
{
AcDbLayerTableRecord* pRcd = nullptr;
if (pItrLayer->getRecord(pRcd, AcDb::kForRead) == Acad::eOk && pRcd)
{
AcDbObjectId id = pRcd->objectId();
const ACHAR* pName = nullptr;
pRcd->getName(pName);
if (pName && CString(pName) != strLayer)
{
vlayerIDFreeze.append(id);
}
pRcd->close();
}
}
delete pItrLayer;
}

auto idid = pViewport->objectId();
pViewport->close();

auto esse = acedVPLayer(idid, vlayerIDFreeze, AcDb::kFreeze);

pLayerTable->close();
}

pls help, thx!

nullptr

  • BricsCAD
  • Needs a day job
  • Posts: 6735
  • AKA Daniel
Re: acedVPLayer doesnt't work, and crash
« Reply #1 on: September 18, 2017, 05:05:44 am »

I didn't try your code.. but  you might try AcDbViewport::freezeLayersInViewport

nullptr

  • BricsCAD
  • Needs a day job
  • Posts: 6735
  • AKA Daniel
Re: acedVPLayer doesnt't work, and crash
« Reply #2 on: September 18, 2017, 05:23:55 am »
If I remember correctly, there may be issues dealing with layout caches.
there was some oddball function that helped, I don't remember ... acedVportTableRecords2Vports  or something  :mrgreen:



nolanjian

  • Mosquito
  • Posts: 7
Re: acedVPLayer doesnt't work, and crash
« Reply #3 on: September 19, 2017, 10:18:40 pm »