In this code I remove the existing symbol check but it doesn't work! "DoesBlockExist(szBlock)"
Thanks for help!
int InsertBlock(AcGePoint3d Pos, CString strFilePath, CString sBlock)
{
Acad::ErrorStatus err;
TCHAR* szBlock;// = (TCHAR *)(LPCTSTR)Blockname;
//if(Blockname.Compare(_T("LS_VINA_TB")) !=0 && Blockname.Compare(_T("LSRP")) != 0)
//_tcscpy(szBlock, Blockname);
szBlock = sBlock.GetBuffer(0);
if (DoesBlockExist(szBlock))
{
/*CString str;
str.Format(_T("%s Already Exists, Please erase and purge if you want to re-add."), sBlock);
if (!sBlock.IsEmpty())
MessageBox(AfxGetApp()->m_pMainWnd->m_hWnd, str, _T("ERROR"), MB_OK);*/
return(-1);
}
AcDbDatabase* pDwg = new AcDbDatabase(Adesk::kFalse);
if ((err = pDwg->readDwgFile(strFilePath)) != Acad::eOk)
{
delete pDwg;
return false; // Somehting went wrong
}
//----- Put it into a block table record of the current database
AcDbObjectId id;
Acad::ErrorStatus es = acdbHostApplicationServices()->
workingDatabase()->insert(id, sBlock, pDwg, Adesk::kFalse);
if (es != Acad::eOk)
acutPrintf(_T("\nError inserting a block."));
delete pDwg;
if (!id.isNull())
addBlockWithAttributes(id, Pos);
return TRUE;
}
Can you please exactly explain
Please rather add a DWG than a screenshot. What do we see here? Three BREFs to the same block with different Attributes?
Just guessing:
Do you want to insert a 4. BREF to the same block?
In this case you should have a function similiar to DoesBlockExist(name) that returnes the AcDbObjectId of the the block name. If it exists you can simply create a new AcDbBlockReference to this block id. You don't have to read the external DWG.
Regarding the code: The call sBlock.GetBuffer(0); should always be paired with a sBlock.ReleaseBuffer().