<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Iterating attributes of a block reference in ObjectARX Forum</title>
    <link>https://forums.autodesk.com/t5/objectarx-forum/iterating-attributes-of-a-block-reference/m-p/3646788#M14314</link>
    <description>&lt;P&gt;By design, attributes (except for constant attributes)&amp;nbsp;can have different values&amp;nbsp;for each instance of a block, so they need to belong to the block reference. The block definition can contain AcDbAttributeDefinition objects, which are used like templates by the INSERT command to create the new AcDbAttribute objects.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Oct 2012 15:52:53 GMT</pubDate>
    <dc:creator>owenwengerd</dc:creator>
    <dc:date>2012-10-04T15:52:53Z</dc:date>
    <item>
      <title>Iterating attributes of a block reference</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/iterating-attributes-of-a-block-reference/m-p/3622524#M14311</link>
      <description>&lt;P&gt;Can anyone answer the following?&lt;/P&gt;&lt;P&gt;1.&amp;nbsp;Why will this code not enter the for loop? It inserts the block, but leaves the attributes blank. Stepping through, it never enters the loop.&lt;/P&gt;&lt;P&gt;2. Is it necessary to add&amp;nbsp;the block reference&amp;nbsp;to the drawing database prior to getting the attributes? I did this in the hopes that it would solve the attribute access problem, to no avail. Not sure if there is some refresh method I am missing that will require the block to be in the drawing. Not sure why, but other examples seem to add the entities last, and I have been doing the same so far.&lt;/P&gt;&lt;P&gt;3. If/when I can get it to enter the for loop, is it better to get the attribute using the entity() function of the iterator as commented out, or the objectId() as I have currently?&lt;/P&gt;&lt;P&gt;4. Finally, is this the way to even do this? I intend to access the individual attributes of a newly inserted block and fill each of them out with passed in values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've stripped out as much code as I could to try and make it more to the point. I can repost if the problem does not lie in what is posted below.&lt;/P&gt;&lt;P&gt;Thanks for any help,&lt;/P&gt;&lt;P&gt;Ralph Gaston&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Acad::ErrorStatus insertPointLoad(	AcGePoint3d isp, int load)
{
	Acad::ErrorStatus es = Acad::eOk;
	AcDbBlockTable *pBlkTbl = NULL;
	acdbHostApplicationServices()-&amp;gt;workingDatabase()-&amp;gt;getBlockTable(pBlkTbl, AcDb::kForRead);

	AcDbBlockTableRecord *pPL = NULL;
	pBlkTbl-&amp;gt;getAt(_T("LOAD"), pPL, AcDb::kForRead);
	pBlkTbl-&amp;gt;close(); pBlkTbl = NULL;

	AcDbBlockReference *pPLBlkRef = new AcDbBlockReference;
	pPLBlkRef-&amp;gt;setBlockTableRecord(pPL-&amp;gt;objectId());
	pPL-&amp;gt;close(); pPL = NULL;
	pPLBlkRef-&amp;gt;setPosition(isp);
	AcDbObjectId PLBlkRefId = AcDbObjectId::kNull;
	PLBlkRefId = addToModelSpace(pPLBlkRef);

	//fill out the attribute values
	AcDbObjectIterator *pPLIter;
	pPLIter = pPLBlkRef-&amp;gt;attributeIterator();
	AcDbAttribute *pAtt = NULL;
	for(pPLIter-&amp;gt;start(); !pPLIter-&amp;gt;done(); pPLIter-&amp;gt;step())
	{
		//pAtt = (AcDbAttribute*)pPLIter-&amp;gt;entity();

		AcDbObjectId pAttId = AcDbObjectId::kNull;
		pAttId = pPLIter-&amp;gt;objectId();
		acdbOpenObject(pAtt, pAttId, AcDb::kForWrite);

		TCHAR *value = NULL;
		if(!_tcscmp(_T("LIVE"), pAtt-&amp;gt;tag()))
		{
			_stprintf(value, _T("%d"), load);
			pAtt-&amp;gt;setTextString(value);
			pAtt-&amp;gt;close(); pAtt = NULL;
			pAtt = NULL;
			continue;
		}
	}//for
	delete pPLIter;
	pPLBlkRef-&amp;gt;close(); pPLBlkRef = NULL;
	return es;
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2012 14:44:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/iterating-attributes-of-a-block-reference/m-p/3622524#M14311</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-09-17T14:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating attributes of a block reference</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/iterating-attributes-of-a-block-reference/m-p/3622714#M14312</link>
      <description>&lt;P&gt;1) You haven't added any attributes, so there are none to iterate.&lt;/P&gt;&lt;P&gt;2) No.&lt;/P&gt;&lt;P&gt;3) You can only use one or the other depending on whether the attributes are database resident.&lt;/P&gt;&lt;P&gt;4) Except for failing to add the attributes, your code should work.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2012 16:38:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/iterating-attributes-of-a-block-reference/m-p/3622714#M14312</guid>
      <dc:creator>owenwengerd</dc:creator>
      <dc:date>2012-09-17T16:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating attributes of a block reference</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/iterating-attributes-of-a-block-reference/m-p/3646520#M14313</link>
      <description>&lt;P&gt;Thanks Owen, I added the attributes to each insert and it now enters the loop and works fine. I still don't completely understand the solution. Previously I believed that both the geometry AND the attributes were part of the block table record, and I'm not sure why I have to add them to the block reference when it is set to the block table record that I thought already contained the attributes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your solution.&lt;/P&gt;&lt;P&gt;Ralph&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2012 14:16:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/iterating-attributes-of-a-block-reference/m-p/3646520#M14313</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-10-04T14:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating attributes of a block reference</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/iterating-attributes-of-a-block-reference/m-p/3646788#M14314</link>
      <description>&lt;P&gt;By design, attributes (except for constant attributes)&amp;nbsp;can have different values&amp;nbsp;for each instance of a block, so they need to belong to the block reference. The block definition can contain AcDbAttributeDefinition objects, which are used like templates by the INSERT command to create the new AcDbAttribute objects.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2012 15:52:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/iterating-attributes-of-a-block-reference/m-p/3646788#M14314</guid>
      <dc:creator>owenwengerd</dc:creator>
      <dc:date>2012-10-04T15:52:53Z</dc:date>
    </item>
  </channel>
</rss>

