<?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 How to iterate through object attributes? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-iterate-through-object-attributes/m-p/7880699#M26668</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Fairly new to C# .net so I am a bit lost with the flowchart below. I have blocks with custom attributes and I want to iterate through each object within the&amp;nbsp;model space ( found in the blocktablerecord?)&amp;nbsp;to find them. Then I want to access their attributes to look for the word "notes" within the Tags value. I found &lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BA69D85A-2AED-43C2-B5B7-73022B5F28F8-htm.html" target="_blank"&gt;this &lt;/A&gt;tutorial on Extract Attribute info but I don't understand how&lt;/FONT&gt; &lt;FONT face="Courier New"&gt;AttributeCollection &lt;FONT face="arial,helvetica,sans-serif"&gt;works. is it like the blocktablerecord that constains all entities?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BA69D85A-2AED-43C2-B5B7-73022B5F28F8-htm.html" target="_blank"&gt;https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BA69D85A-2AED-43C2-B5B7-73022B5F28F8-htm.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG width="283" height="186" src="http://help.autodesk.com/cloudhelp/2018/ENU/OARX-DevGuide-Managed/images/GUID-1AA8F78F-DF90-4AA4-A975-A06FBF65231C.png" border="0" /&gt;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.LayerManager;
using Autodesk.AutoCAD.Runtime;
using ACADapp = Autodesk.AutoCAD.ApplicationServices.Application;
using ATTCOL = Autodesk.AutoCAD.DatabaseServices.AttributeCollection;



namespace Get_Notes_v0._1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void FindNotes_Click(object sender, EventArgs e)
        {

            // Get the current document and database
            Document Doc = ACADapp.DocumentManager.MdiActiveDocument;
            Database DB = Doc.Database;
            Editor ED = Doc.Editor;

            // Start a transaction
            using (Transaction TRANS = DB.TransactionManager.StartTransaction())
            {
                // Open the Block table for read
                BlockTable Btable = TRANS.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord BTR = TRANS.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTableRecord;

                //look at each objects attributes for key word note or notes
                foreach (ObjectId OBJID in BTR)
                {
                    ATTCOL ATTREF = OBJID.GetObject(OBJID.Database, OpenMode.ForRead) as ATTCOL;             
                    {
                        if (ATTREF.Tag == "CONST_REMARKS")
                        {
                            if (ATTREF.Value == "NOTE" || ATTREF.Value == "NOTES")
                            {

                            }
                        }
                    }
                }
            }
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 24 Mar 2018 04:36:18 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-03-24T04:36:18Z</dc:date>
    <item>
      <title>How to iterate through object attributes?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-iterate-through-object-attributes/m-p/7880699#M26668</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Fairly new to C# .net so I am a bit lost with the flowchart below. I have blocks with custom attributes and I want to iterate through each object within the&amp;nbsp;model space ( found in the blocktablerecord?)&amp;nbsp;to find them. Then I want to access their attributes to look for the word "notes" within the Tags value. I found &lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BA69D85A-2AED-43C2-B5B7-73022B5F28F8-htm.html" target="_blank"&gt;this &lt;/A&gt;tutorial on Extract Attribute info but I don't understand how&lt;/FONT&gt; &lt;FONT face="Courier New"&gt;AttributeCollection &lt;FONT face="arial,helvetica,sans-serif"&gt;works. is it like the blocktablerecord that constains all entities?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BA69D85A-2AED-43C2-B5B7-73022B5F28F8-htm.html" target="_blank"&gt;https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BA69D85A-2AED-43C2-B5B7-73022B5F28F8-htm.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG width="283" height="186" src="http://help.autodesk.com/cloudhelp/2018/ENU/OARX-DevGuide-Managed/images/GUID-1AA8F78F-DF90-4AA4-A975-A06FBF65231C.png" border="0" /&gt;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.LayerManager;
using Autodesk.AutoCAD.Runtime;
using ACADapp = Autodesk.AutoCAD.ApplicationServices.Application;
using ATTCOL = Autodesk.AutoCAD.DatabaseServices.AttributeCollection;



namespace Get_Notes_v0._1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void FindNotes_Click(object sender, EventArgs e)
        {

            // Get the current document and database
            Document Doc = ACADapp.DocumentManager.MdiActiveDocument;
            Database DB = Doc.Database;
            Editor ED = Doc.Editor;

            // Start a transaction
            using (Transaction TRANS = DB.TransactionManager.StartTransaction())
            {
                // Open the Block table for read
                BlockTable Btable = TRANS.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord BTR = TRANS.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTableRecord;

                //look at each objects attributes for key word note or notes
                foreach (ObjectId OBJID in BTR)
                {
                    ATTCOL ATTREF = OBJID.GetObject(OBJID.Database, OpenMode.ForRead) as ATTCOL;             
                    {
                        if (ATTREF.Tag == "CONST_REMARKS")
                        {
                            if (ATTREF.Value == "NOTE" || ATTREF.Value == "NOTES")
                            {

                            }
                        }
                    }
                }
            }
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 04:36:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-iterate-through-object-attributes/m-p/7880699#M26668</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-24T04:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to iterate through object attributes?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-iterate-through-object-attributes/m-p/7880712#M26669</link>
      <description>&lt;P&gt;Here is what your FindNotes_Click() handler should look like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;   private void FindNotes_Click(object sender, EventArgs e)
   {
      Document Doc = Application.DocumentManager.MdiActiveDocument;
      Database db = Doc.Database;
      Editor ed = Doc.Editor;

      using(Transaction trans = db.TransactionManager.StartTransaction())
      {
         ObjectId modelSpace = SymbolUtilityServices.GetBlockModelSpaceId(db);
         BlockTableRecord btr = trans.GetObject(modelSpace, OpenMode.ForRead) as BlockTableRecord;

         RXClass rxclass = RXClass.GetClass(typeof(BlockReference));
         foreach(ObjectId id in btr)
         {
            if(id.ObjectClass.IsDerivedFrom(rxclass))
            {
               BlockReference blkref = (BlockReference) trans.GetObject(id, OpenMode.ForRead);
               AttributeCollection attributes = blkref.AttributeCollection;
               foreach(ObjectId attId in attributes)
               {
                  AttributeReference attref = (AttributeReference) trans.GetObject(attId, OpenMode.ForRead);
                  if(attref.Tag == "CONST_REMARKS")
                  {
                     if(attref.TextString == "NOTE" || attref.TextString == "NOTES")
                     {
                        // Or do something else with it.
                        ed.WriteMessage("\nFound attribute {0} = {1}", attref.Tag, attref.TextString);
                     }
                  }
               }
            }
            trans.Commit();
         }
      }
   }&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Visit the resources&amp;nbsp;&amp;gt;&lt;A href="http://usa.autodesk.com/adsk/servlet/index?siteID=123112&amp;amp;id=1911627" target="_blank"&gt;here&lt;/A&gt;&amp;lt; for more help and examples on using the .NET API.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, it is customary to not use all CAPS for identifiers/varaibles in C#.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymouswrote:&lt;BR /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Fairly new to C# .net so I am a bit lost with the flowchart below. I have blocks with custom attributes and I want to iterate through each object within the&amp;nbsp;model space ( found in the blocktablerecord?)&amp;nbsp;to find them. Then I want to access their attributes to look for the word "notes" within the Tags value. I found &lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BA69D85A-2AED-43C2-B5B7-73022B5F28F8-htm.html" target="_blank"&gt;this &lt;/A&gt;tutorial on Extract Attribute info but I don't understand how&lt;/FONT&gt; &lt;FONT face="Courier New"&gt;AttributeCollection &lt;FONT face="arial,helvetica,sans-serif"&gt;works. is it like the blocktablerecord that constains all entities?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BA69D85A-2AED-43C2-B5B7-73022B5F28F8-htm.html" target="_blank"&gt;https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-BA69D85A-2AED-43C2-B5B7-73022B5F28F8-htm.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://help.autodesk.com/cloudhelp/2018/ENU/OARX-DevGuide-Managed/images/GUID-1AA8F78F-DF90-4AA4-A975-A06FBF65231C.png" border="0" width="283" height="186" /&gt;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.LayerManager;
using Autodesk.AutoCAD.Runtime;
using ACADapp = Autodesk.AutoCAD.ApplicationServices.Application;
using ATTCOL = Autodesk.AutoCAD.DatabaseServices.AttributeCollection;



namespace Get_Notes_v0._1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void FindNotes_Click(object sender, EventArgs e)
        {

            // Get the current document and database
            Document Doc = ACADapp.DocumentManager.MdiActiveDocument;
            Database DB = Doc.Database;
            Editor ED = Doc.Editor;

            // Start a transaction
            using (Transaction TRANS = DB.TransactionManager.StartTransaction())
            {
                // Open the Block table for read
                BlockTable Btable = TRANS.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord BTR = TRANS.GetObject(DB.BlockTableId, OpenMode.ForRead) as BlockTableRecord;

                //look at each objects attributes for key word note or notes
                foreach (ObjectId OBJID in BTR)
                {
                    ATTCOL ATTREF = OBJID.GetObject(OBJID.Database, OpenMode.ForRead) as ATTCOL;             
                    {
                        if (ATTREF.Tag == "CONST_REMARKS")
                        {
                            if (ATTREF.Value == "NOTE" || ATTREF.Value == "NOTES")
                            {

                            }
                        }
                    }
                }
            }
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 05:27:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-iterate-through-object-attributes/m-p/7880712#M26669</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-03-24T05:27:44Z</dc:date>
    </item>
  </channel>
</rss>

