ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can i insert multiple components into a drawing of electrical CAD?

1 REPLY 1
Reply
Message 1 of 2
vudvpro
243 Views, 1 Reply

How can i insert multiple components into a drawing of electrical CAD?

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;
}
1 REPLY 1
Message 2 of 2
tbrammer
in reply to: vudvpro

Can you please exactly explain

  • What you wanted to do
  • What you expected to happen
  • What actually happened

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().

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost