Why doesn't this work? It does with other dictionaries.
There's no errors, nothing happens
static void AcRxPyApp_idoit(void)
{
AcDbDatabase* pDestDb = acdbHostApplicationServices()->workingDatabase();
std::unique_ptr<AcDbDatabase> pSrcDb(new AcDbDatabase(false, true));
if (auto es = pSrcDb->readDwgFile(_T("E://SrcTableStyle.dwg")); es != eOk)
acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));
if (auto es = pSrcDb->closeInput(true); es != eOk)
acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));
AcDbIdMapping idmap;
AcDbObjectIdArray ids;
ids.append(pSrcDb->tablestyle());
if (auto es = pDestDb->wblockCloneObjects(ids, pDestDb->tableStyleDictionaryId(), idmap, AcDb::kDrcReplace, false); es != eOk)
acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));
}
Solved! Go to Solution.
Solved by tbrammer. Go to Solution.
I tried your code. If the name of the the current tablestyle in the source DB does not exist in the target DB, it works fine. But if the tablestyle exists in the destination DB, the style is not overwritten - even though you pass
AcDb::DuplicateRecordCloning drc = AcDb::kDrcReplace. Seems to be a bug in the SDK.
Workaround: Check for existence and erase the style from the target DB if it exist.
For the sake of completeness: I replaced std::unique_ptr<AcDbDatabase> pSrcDb;
by AcDbDatabase *pSrcDb; / delete pSrcDb. But this shouldn't make any difference.
Thanks for testing this, I think it’s a bug as well, or Autodesk didn’t want to nuke existing tables that have a tablestyleid assigned. kDrcMangleName and swap id seems to work, and may be the safest approach
static void AcRxPyApp_idoit(void)
{
AcDbDatabase* pDestDb = acdbHostApplicationServices()->workingDatabase();
std::unique_ptr<AcDbDatabase> pSrcDb(new AcDbDatabase(false, true));
if (auto es = pSrcDb->readDwgFile(_T("E://SrcTableStyle.dwg")); es != eOk)
acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));
if (auto es = pSrcDb->closeInput(true); es != eOk)
acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));
AcDbIdMapping idmap;
AcDbObjectIdArray srcids;
srcids.append(pSrcDb->tablestyle());
AcDbObjectId ownerId = pDestDb->tableStyleDictionaryId();
if (auto es = pDestDb->wblockCloneObjects(srcids, ownerId, idmap, AcDb::kDrcMangleName, false); es != eOk)
acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));
AcDbIdPair idPair;
AcDbIdMappingIter iter(idmap);
for (iter.start(); !iter.done(); iter.next())
{
if(!iter.getMap(idPair))
continue;
if (idPair.key() == pSrcDb->tablestyle())
{
const auto sid = idPair.value();
{
AcDbObjectPointer<AcDbObject> newStyle(sid, AcDb::kForWrite);
newStyle->swapIdWith(pDestDb->tablestyle(), true, true);
}
{
AcDbObjectPointer<AcDbObject> oldStyle(sid, AcDb::kForWrite);
oldStyle->erase();
}
break;
}
}
}
Can't find what you're looking for? Ask the community or share your knowledge.