newer 发表于 2021-1-17 03:18:32

用ARX增加 layer filter

Add a layer filter using ARX - access the layer table extension dictionary


问题:

Layer filters are used to hide or display layers based on certain properties
in the Layer Properties Dialog. Is there an API that will programmatically add
a layer filter?

解答:

Layer filters are stored in the extension dictionary of the LayerTable. Below
is an example that creates a layer filter named testFilter.



void ASDKtestfilter()
{

AcDbLayerTable *pLayerTbl ;
acdbHostApplicationServices()->workingDatabase()->getLayerTable (pLayerTbl, AcDb::kForRead);

AcDbObjectId extDictId = pLayerTbl->extensionDictionary();
if (AcDbObjectId::kNull == extDictId)
{
      acutPrintf("creating layerTable extension dictionary\n");
if (Acad::eOk != pLayerTbl->upgradeOpen())
      {
            pLayerTbl->close();
            acutPrintf("unable to upgradeOpen Layer table\n");
            return;
      }
      pLayerTbl->createExtensionDictionary();
      extDictId = pLayerTbl->extensionDictionary();
      if (AcDbObjectId::kNull == extDictId)
      {
            pLayerTbl->close();
            acutPrintf("unable to create Layer's Ext Dictionary\n");
            return;
      }
}
pLayerTbl->close();

AcDbDictionary *pExtDict;

Acad::ErrorStatus es;
es = acdbOpenObject(pExtDict, extDictId, AcDb::kForRead);
if (es != Acad::eOk)
{
delete pExtDict;
acutPrintf("unable to open Layer's Ext Dictionary\n");
      return;
}

// get or create the ACAD_LAYERFILTERS dictionary
AcDbDictionary *pLayerFiltersDict = NULL;
if (Acad::eOk != pExtDict->getAt( "ACAD_LAYERFILTERS", (AcDbObject*&)pLayerFiltersDict, AcDb::kForWrite ))
    {
      acutPrintf("creating ACAD_LAYERFILTERS dictionary\n");

      pExtDict->upgradeOpen();
pLayerFiltersDict = new AcDbDictionary;

AcDbObjectId new_id;
      if (Acad::eOk != pExtDict->setAt( "ACAD_LAYERFILTERS", pLayerFiltersDict, new_id ))
      {
            acutPrintf("unable to create ACAD_LAYERFILTERS dictionary\n");
   pExtDict->close();
   delete pLayerFiltersDict;
            return;
      }
}
pExtDict->close();

AcDbObjectId Objid;
AcDbXrecord *pXrec= new AcDbXrecord;
resbuf *pHead;

pHead=acutBuildList(1, "testFilter", 1, "*", 1, "*",1, "*", 70, 13, 1, "*",
       1, "*", RTNONE);

pXrec->setFromRbChain(*pHead, NULL);
pLayerFiltersDict->setAt("testFilter", pXrec, Objid);

pLayerFiltersDict->close();
pXrec->close();
acutRelRb(pHead);
}


页: [1]
查看完整版本: 用ARX增加 layer filter