<?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 : Change attribute color/layer per one block only in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303444#M49038</link>
    <description>&lt;P&gt;I think you misunderstood me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me explain. Below code works fine - change the colors of all entities expect entities which are inside blocks:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; if (rbtSelection.Checked)
            {
                Autodesk.AutoCAD.ApplicationServices.DocumentLock dl = doc.LockDocument(Autodesk.AutoCAD.ApplicationServices.DocumentLockMode.ProtectedAutoWrite, null, null, true);
                using (dl)
                {
                    ObjectId msId = ObjectId.Null;

                    short colorIndex = (short)colorValue.Value;

                    LineWeight lineweight = (LineWeight)cmboxThick.SelectedValue;

                    ObjectId layerId = Layers.GetDrawingLayerObjectId(cmboxLayer.SelectedValue.ToString());

                    bool changeLineWeight = chckBoxThick.Checked;
                    bool changeLayer = chckBoxLayer.Checked;

                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        BlockTableRecord btRecord = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                        foreach (ObjectId id in btRecord)
                        {
                            Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
                            ent.UpgradeOpen();
                            ent.ColorIndex = 6;
                            ent.DowngradeOpen();
                        }

                        tr.Commit();
                    }
                }
            }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;If I go and iterate through the attributes references and change their color, any next new block which I add into my drawing, will have this color.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;That's what I don't want.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;&lt;BR /&gt;I want something like we have "Edit attribute" per block in model space. I can set then color for this one block and any next new block will have standard color.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;I hope, now it's more clearly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jun 2013 18:14:33 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-06-19T18:14:33Z</dc:date>
    <item>
      <title>Change attribute color/layer per one block only</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303197#M49036</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've read this post:&lt;/P&gt;&lt;P&gt;&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2007/02/changing_the_co.html" target="_blank"&gt;http://through-the-interface.typepad.com/through_the_interface/2007/02/changing_the_co.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Everything works fine, but I have one problem.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I just want to change colors for all objects in current model space. But this command also changes attributes/blocks definitions (I mean, any new block which I insert has the color that I specified previous).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why? Where I have to change the code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2013 15:49:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303197#M49036</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-06-19T15:49:02Z</dc:date>
    </item>
    <item>
      <title>Re : Change attribute color/layer per one block only</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303344#M49037</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to change the color of "all objects in current model space", you have to set the color of all block definitions components to ByBlock and change the color of all entities (block references too) in model space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To set the block definitions components to ByBlock, you can use the way showned in Kean's routine.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2013 16:59:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303344#M49037</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2013-06-19T16:59:53Z</dc:date>
    </item>
    <item>
      <title>Re : Change attribute color/layer per one block only</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303444#M49038</link>
      <description>&lt;P&gt;I think you misunderstood me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me explain. Below code works fine - change the colors of all entities expect entities which are inside blocks:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; if (rbtSelection.Checked)
            {
                Autodesk.AutoCAD.ApplicationServices.DocumentLock dl = doc.LockDocument(Autodesk.AutoCAD.ApplicationServices.DocumentLockMode.ProtectedAutoWrite, null, null, true);
                using (dl)
                {
                    ObjectId msId = ObjectId.Null;

                    short colorIndex = (short)colorValue.Value;

                    LineWeight lineweight = (LineWeight)cmboxThick.SelectedValue;

                    ObjectId layerId = Layers.GetDrawingLayerObjectId(cmboxLayer.SelectedValue.ToString());

                    bool changeLineWeight = chckBoxThick.Checked;
                    bool changeLayer = chckBoxLayer.Checked;

                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        BlockTableRecord btRecord = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                        foreach (ObjectId id in btRecord)
                        {
                            Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
                            ent.UpgradeOpen();
                            ent.ColorIndex = 6;
                            ent.DowngradeOpen();
                        }

                        tr.Commit();
                    }
                }
            }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;If I go and iterate through the attributes references and change their color, any next new block which I add into my drawing, will have this color.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;That's what I don't want.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;&lt;BR /&gt;I want something like we have "Edit attribute" per block in model space. I can set then color for this one block and any next new block will have standard color.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 14px;"&gt;I hope, now it's more clearly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2013 18:14:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303444#M49038</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-06-19T18:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Re : Change attribute color/layer per one block only</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303510#M49039</link>
      <description>&lt;P&gt;Maybe my english isn't so good, but I think I clearly understood what you want to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If my C# is better than my English, here's a little sample to change the color of all entities in model space. Maybe you'd have some issues with MText which color is overwriten or with dimension and tables (which inherits from BlockReference).&lt;/P&gt;
&lt;PRE&gt;        private void ChangeEntitesColorInModelSpace(short colorIndex)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            using (doc.LockDocument())
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                // Set the color of all entities within block definition to ByBlock
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                foreach (ObjectId btrId in bt)
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
                    if (!btr.IsLayout)
                    {
                        foreach (ObjectId id in btr)
                        {
                            Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
                            ent.ColorIndex = 0;
                        }
                    }
                }

                // Set the color of all entities within model space to the specified color
                BlockTableRecord modelSpace =
                    (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                foreach (ObjectId id in modelSpace)
                {
                    Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
                    ent.ColorIndex = colorIndex;
                    // Sychronize attributes
                    if (ent is BlockReference)
                    {
                        BlockReference br = (BlockReference)ent;
                        foreach (ObjectId attId in br.AttributeCollection)
                        {
                            AttributeReference att = (AttributeReference)tr.GetObject(attId, OpenMode.ForWrite);
                            att.ColorIndex = 0;
                        }
                    }
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I still misundertand you, here's another snippet to change the selected attribute references color:&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("AttColor", CommandFlags.Modal)]
        public void ChangeAttributeColor()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            RXClass rxc = RXClass.GetClass(typeof(AttributeReference));

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                while (true)
                {
                    PromptNestedEntityResult res = ed.GetNestedEntity("\nSelect an attribute: ");
                    if (res.Status != PromptStatus.OK) 
                        break;
                    if (res.ObjectId.ObjectClass != rxc)
                    {
                        ed.WriteMessage("only an attribute !");
                        continue;
                    }
                    AttributeReference att = (AttributeReference)tr.GetObject(res.ObjectId, OpenMode.ForWrite);
                    att.ColorIndex = 1;
                    db.TransactionManager.QueueForGraphicsFlush();
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 20:14:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303510#M49039</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-09-26T20:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: Change attribute color/layer per one block only</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303899#M49040</link>
      <description>&lt;P&gt;You're my master. First solution works good &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2013 05:34:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/4303899#M49040</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-06-20T05:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: Re : Change attribute color/layer per one block only</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/8838884#M49041</link>
      <description>&lt;P&gt;How do I change, the color of only one block, instead of all the blocks?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You for your help in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 13:54:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-color-layer-per-one-block-only/m-p/8838884#M49041</guid>
      <dc:creator>jlobo2</dc:creator>
      <dc:date>2019-06-07T13:54:39Z</dc:date>
    </item>
  </channel>
</rss>

