<?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: Issue With Attribute Visibility in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611533#M5230</link>
    <description>&lt;P&gt;The BATTMAN command changes the Invisible property of the AttributeDefinition in the block definition (BlockTableRecord) and synchronizes the attribute references.&lt;/P&gt;
&lt;P&gt;The "SetAttributeVisibility" method called by "HandleCheckboxVisibility" changes the Invisible property of the attribute reference of the block reference found in the paper space layout only.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Mar 2024 16:00:23 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2024-03-04T16:00:23Z</dc:date>
    <item>
      <title>Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610151#M5221</link>
      <description>&lt;P&gt;Hi Guys i am having a weird problem With a Blocks Attribute.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;at default a Certain Attribute is not visible because of the field being blank. i have a program with a checkbox to make the Attribute Visible. This seems to work fine only when the Battman command has been used on that drawing before, otherwise the checkbox doesn't work and does not activate the visibility state of that attribute. this is strange i am not sure if there is a system variable that also has to be changed. can someone please give some input?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Here is a snip of my code:

Class:
    private void SetAttributeVisibility(Transaction tr, BlockReference blockRef, string attributeName, bool isVisible)
    {
        foreach (ObjectId attId in blockRef.AttributeCollection)
        {
            AttributeReference attRef = tr.GetObject(attId, OpenMode.ForWrite) as AttributeReference;
            if (attRef != null &amp;amp;&amp;amp; attRef.Tag == attributeName)
            {
                attRef.Visible = isVisible;
                break;
            }
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;  public void HandleCheckboxVisibility(CheckBox checkBox, params string[] attributeNames)
  {
      // Get the visibility state based on the checkbox checked status
      bool isVisible = checkBox.Checked;

      Document doc = Application.DocumentManager.MdiActiveDocument;
      Database db = doc.Database;
      Editor ed = doc.Editor;

      using (DocumentLock docLock = doc.LockDocument())
      {
          using (Transaction tr = db.TransactionManager.StartTransaction())
          {
              BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
              if (bt != null)
              {
                  BlockTableRecord layout = tr.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForRead) as BlockTableRecord;
                  if (layout != null)
                  {
                      foreach (ObjectId objId in layout)
                      {
                          if (objId.ObjectClass.Name == "AcDbBlockReference")
                          {
                              BlockReference blockRef = tr.GetObject(objId, OpenMode.ForWrite) as BlockReference;
                              if (blockRef != null &amp;amp;&amp;amp; blockRef.Name == BlockName)
                              {
                                  foreach (string attributeName in attributeNames)
                                  {
                                      SetAttributeVisibility(tr, blockRef, attributeName, isVisible);
                                  }
                              }
                          }
                      }
                  }
                  else
                  {
                      MessageBox.Show("The Titleblock is not loaded. Please ensure the Titleblock is loaded and try again.", "Titleblock Not Loaded", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                      return;
                  }
              }
          }
      }&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 04 Mar 2024 06:12:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610151#M5221</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-03-04T06:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610337#M5222</link>
      <description>&lt;P&gt;I don't see a Transaction Commit, does that change anything?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 08:16:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610337#M5222</guid>
      <dc:creator>Anton_Huizinga</dc:creator>
      <dc:date>2024-03-04T08:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610450#M5223</link>
      <description>&lt;P&gt;you are right sometimes it needs another eye lol let me fix and retry/thanks though&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 09:31:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610450#M5223</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-03-04T09:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610574#M5224</link>
      <description>&lt;P&gt;Fixed the trans.commit error i made. still the same. its weird how it doesnt want to work untill the visibility has ben changed in the "battman" command and after that it works without any issues. i am stumped at this point and have no idea what to look at next&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 10:49:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610574#M5224</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-03-04T10:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610695#M5225</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;In the code you post, you use the &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_Entity_Visible" target="_blank" rel="noopener"&gt;Entity.Visible&lt;/A&gt; property, not the specific &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_AttributeReference_Invisible" target="_blank" rel="noopener"&gt;AttributeReference.Invisible&lt;/A&gt; one.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 12:05:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610695#M5225</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-03-04T12:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610969#M5226</link>
      <description>&lt;P&gt;i have fix and updated the code. does exactly the same thing. this is really weird for me. does the "Battman command" maybe change some variable that i also need to change in the code?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 14:06:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12610969#M5226</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-03-04T14:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611029#M5227</link>
      <description>&lt;P&gt;This works for me:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;private static void SetAttributeVisibility(Transaction tr, BlockReference blockRef, string attributeName, bool isVisible)
{
    foreach (ObjectId attId in blockRef.AttributeCollection)
    {
        AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForWrite);
        if (attRef.Tag.Equals(attributeName, StringComparison.OrdinalIgnoreCase))
        {
            attRef.Invisible = !isVisible;
            break;
        }
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take care, in the HandleCheckboxVisibility method you show, doing:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;BlockTableRecord layout = tr.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForRead) as BlockTableRecord;&lt;/LI-CODE&gt;
&lt;P&gt;only gets the last opened layout block table record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another thing, it the block you're looking from is a dynamic block, it may be "anonymous". In this case, you should replace:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;if (blockRef != null &amp;amp;&amp;amp; blockRef.Name == BlockName)
{
    foreach (string attributeName in attributeNames)
    {
        SetAttributeVisibility(tr, blockRef, attributeName, isVisible);
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;with:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;BlockTableRecord dynamicBtr = (BlockTableRecord)tr.GetObject(blockRef.DynamicBlockTableRecord, OpenMode.ForRead);
string effectiveName = dynamicBtr.Name;
if (effectiveName.Equals(BlockName, StringComparison.OrdinalIgnoreCase))
{
    foreach (string attributeName in attributeNames)
    {
        SetAttributeVisibility(tr, blockRef, attributeName, isVisible);
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 04 Mar 2024 14:36:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611029#M5227</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-03-04T14:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611496#M5228</link>
      <description>&lt;P&gt;This method processes each block reference named "BlockName" (or anonymous block references issued from "BlockName") in every paper space layouts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;private void SetAttributeVisibility(Transaction tr, BlockReference blockRef, string attributeName, bool isVisible)
{
    foreach (ObjectId attId in blockRef.AttributeCollection)
    {
        AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForWrite);
        if (attRef.Tag.Equals(attributeName, StringComparison.OrdinalIgnoreCase))
        {
            attRef.Invisible = !isVisible;
            break;
        }
    }
}

public void HandleCheckboxVisibility(CheckBox checkBox, params string[] attributeNames)
{
    // Get the visibility state based on the checkbox checked status
    bool isVisible = checkBox.Checked;

    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;

    using (doc.LockDocument())
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
        if (bt.Has(BlockName))
        {
            BlockTableRecord blockDefinition = (BlockTableRecord)tr.GetObject(bt[BlockName], OpenMode.ForRead);
            foreach (ObjectId brId in blockDefinition.GetBlockReferenceIds(true, false))
            {
                BlockReference blockRef = (BlockReference)tr.GetObject(brId, OpenMode.ForWrite);
                BlockTableRecord owner = (BlockTableRecord)tr.GetObject(blockRef.OwnerId, OpenMode.ForRead);
                if (owner.Name.StartsWith("*Paper_Space"))
                {
                    foreach (string attributeName in attributeNames)
                    {
                        SetAttributeVisibility(tr, blockRef, attributeName, isVisible);
                    }
                }

                // Look for anonymous blocks
                foreach (ObjectId anonymousBlockId in blockDefinition.GetAnonymousBlockIds())
                {
                    BlockTableRecord anonymousBlock = (BlockTableRecord)tr.GetObject(anonymousBlockId, OpenMode.ForRead);
                    foreach (ObjectId anonymousBrId in anonymousBlock.GetBlockReferenceIds(true, false))
                    {
                        blockRef = (BlockReference)tr.GetObject(anonymousBrId, OpenMode.ForWrite);
                        owner = (BlockTableRecord)tr.GetObject(blockRef.OwnerId, OpenMode.ForRead);
                        if (owner.Name.StartsWith("*Paper_Space"))
                        {
                            foreach (string attributeName in attributeNames)
                            {
                                SetAttributeVisibility(tr, blockRef, attributeName, isVisible);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            MessageBox.Show("The Titleblock is not loaded. Please ensure the Titleblock is loaded and try again.", "Titleblock Not Loaded", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }
        tr.Commit();
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 15:41:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611496#M5228</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-03-04T15:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611499#M5229</link>
      <description>&lt;P&gt;I have made the changes but it still does the same thing. If i take 2 drawings. 1 where i quickly set the visibility mode in the battman comand and then run the code it works without issues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But as soon as i open a drawing where the battman command was not run before hand it doesnt work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What can cause this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 15:41:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611499#M5229</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-03-04T15:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611533#M5230</link>
      <description>&lt;P&gt;The BATTMAN command changes the Invisible property of the AttributeDefinition in the block definition (BlockTableRecord) and synchronizes the attribute references.&lt;/P&gt;
&lt;P&gt;The "SetAttributeVisibility" method called by "HandleCheckboxVisibility" changes the Invisible property of the attribute reference of the block reference found in the paper space layout only.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 16:00:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611533#M5230</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-03-04T16:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611548#M5231</link>
      <description>&lt;P&gt;Sorry i am not following. The block it needs to edit is only in paperspace its a titleblock. Thats why i only set it for the block in paperspace. This is interesting im.learning allot from this.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 16:04:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611548#M5231</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-03-04T16:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611592#M5232</link>
      <description>&lt;P&gt;Did you try the code I posted reply #8 ?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 16:02:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611592#M5232</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-03-04T16:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611716#M5233</link>
      <description>&lt;P&gt;yes i did can i maybe send you the 2 drawings for example so you can check your side? will also give you the coding?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 16:22:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611716#M5233</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-03-04T16:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611864#M5234</link>
      <description>&lt;P&gt;For sure, attach the drawings.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 16:43:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611864#M5234</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-03-04T16:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611892#M5235</link>
      <description>&lt;P&gt;can you maybe send me your email adress in pvt message. the drawings contain persona company info which i dont just want to share here.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 16:53:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611892#M5235</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-03-04T16:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611914#M5236</link>
      <description>&lt;P&gt;I do not want to make private personal assistance. I'm on this forum to share with everyone.&lt;/P&gt;
&lt;P&gt;You should be able to make some relevant sample drawing without confidential information.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 16:58:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611914#M5236</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-03-04T16:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611931#M5237</link>
      <description>&lt;P&gt;this issue only occurs in certain drawings i cant just recreate the issue. and i also cant share my companies' drawings online due to security, you have to also understand that. if you are unable to look at the drawings privately i also understand.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 17:05:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611931#M5237</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-03-04T17:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611947#M5238</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13503176"&gt;@My_Civil_3D&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;this issue only occurs in certain drawings&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This means the issue is due to the drawing, not to the code.&lt;/P&gt;
&lt;P&gt;So you should check these drawings (AUDIT), and more specifically the block the issue occurs on&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 17:12:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12611947#M5238</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-03-04T17:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Issue With Attribute Visibility</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12647146#M5239</link>
      <description>&lt;P&gt;I have looked at the Drawing and block itself and i cant see m to find if there is an issue somewhere. i have attached the Working and Not Working Block. The issue is with the Hold List &amp;amp; Remarks not showing correctly in all drawings when the show hold is ticked. Here is the Dwg's and the Code.&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp; as you requested hopefully you can point out the issues&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 06:23:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-with-attribute-visibility/m-p/12647146#M5239</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-03-18T06:23:25Z</dc:date>
    </item>
  </channel>
</rss>

