<?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 Preserve Constat Attributes on BlockReference in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-preserve-constat-attributes-on-blockreference/m-p/2634989#M66946</link>
    <description>I am creating a new blockreference object based on the block definition already present in the BlockTable.&lt;BR /&gt;
&lt;BR /&gt;
BlockReference br = new BlockReference(pt, bdId);    //where bdId is the objectId of the block&lt;BR /&gt;
&lt;BR /&gt;
I am then cycling through the ObjectIds in the BlockTableRecord and if they are AttributeDefinitions then I attach them to the new blockreference:&lt;BR /&gt;
&lt;BR /&gt;
BlockTableRecord bd = (BlockTableRecord)tr.GetObject(bdId, OpenMode.ForRead);&lt;BR /&gt;
                        &lt;BR /&gt;
foreach (ObjectId attId in bd)&lt;BR /&gt;
{&lt;BR /&gt;
      //Open the Object for reading&lt;BR /&gt;
      Entity ent =  (Entity)tr.GetObject(attId, OpenMode.ForRead);               &lt;BR /&gt;
&lt;BR /&gt;
      //Check whether it is an Attribute or not&lt;BR /&gt;
      if (ent is AttributeDefinition)&lt;BR /&gt;
      {&lt;BR /&gt;
          //Get the Definition&lt;BR /&gt;
         AttributeDefinition ad = (AttributeDefinition)ent;&lt;BR /&gt;
&lt;BR /&gt;
         //Set up a new attribute reference&lt;BR /&gt;
         AttributeReference ar = new AttributeReference();&lt;BR /&gt;
&lt;BR /&gt;
         //Add the attribute definition to the attribute reference&lt;BR /&gt;
         ar.SetAttributeFromBlock(ad, br.BlockTransform);&lt;BR /&gt;
                                &lt;BR /&gt;
         //Add the Attribute reference to the new block&lt;BR /&gt;
         br.AttributeCollection.AppendAttribute(ar);&lt;BR /&gt;
&lt;BR /&gt;
         //Use the transaction to commit the changes&lt;BR /&gt;
         tr.AddNewlyCreatedDBObject(ar, true);&lt;BR /&gt;
&lt;BR /&gt;
   } //End If ent&lt;BR /&gt;
} //End For Loop&lt;BR /&gt;
&lt;BR /&gt;
Question is:  Each of the blocks has 2 attributes that are defined as Constants on the original BlockTableRecord, but when I use the code above to copy them over to the new blockreference they are no longer Constants.  How do I copy them over and retain the original status?</description>
    <pubDate>Wed, 17 Feb 2010 21:21:59 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-02-17T21:21:59Z</dc:date>
    <item>
      <title>How to Preserve Constat Attributes on BlockReference</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-preserve-constat-attributes-on-blockreference/m-p/2634989#M66946</link>
      <description>I am creating a new blockreference object based on the block definition already present in the BlockTable.&lt;BR /&gt;
&lt;BR /&gt;
BlockReference br = new BlockReference(pt, bdId);    //where bdId is the objectId of the block&lt;BR /&gt;
&lt;BR /&gt;
I am then cycling through the ObjectIds in the BlockTableRecord and if they are AttributeDefinitions then I attach them to the new blockreference:&lt;BR /&gt;
&lt;BR /&gt;
BlockTableRecord bd = (BlockTableRecord)tr.GetObject(bdId, OpenMode.ForRead);&lt;BR /&gt;
                        &lt;BR /&gt;
foreach (ObjectId attId in bd)&lt;BR /&gt;
{&lt;BR /&gt;
      //Open the Object for reading&lt;BR /&gt;
      Entity ent =  (Entity)tr.GetObject(attId, OpenMode.ForRead);               &lt;BR /&gt;
&lt;BR /&gt;
      //Check whether it is an Attribute or not&lt;BR /&gt;
      if (ent is AttributeDefinition)&lt;BR /&gt;
      {&lt;BR /&gt;
          //Get the Definition&lt;BR /&gt;
         AttributeDefinition ad = (AttributeDefinition)ent;&lt;BR /&gt;
&lt;BR /&gt;
         //Set up a new attribute reference&lt;BR /&gt;
         AttributeReference ar = new AttributeReference();&lt;BR /&gt;
&lt;BR /&gt;
         //Add the attribute definition to the attribute reference&lt;BR /&gt;
         ar.SetAttributeFromBlock(ad, br.BlockTransform);&lt;BR /&gt;
                                &lt;BR /&gt;
         //Add the Attribute reference to the new block&lt;BR /&gt;
         br.AttributeCollection.AppendAttribute(ar);&lt;BR /&gt;
&lt;BR /&gt;
         //Use the transaction to commit the changes&lt;BR /&gt;
         tr.AddNewlyCreatedDBObject(ar, true);&lt;BR /&gt;
&lt;BR /&gt;
   } //End If ent&lt;BR /&gt;
} //End For Loop&lt;BR /&gt;
&lt;BR /&gt;
Question is:  Each of the blocks has 2 attributes that are defined as Constants on the original BlockTableRecord, but when I use the code above to copy them over to the new blockreference they are no longer Constants.  How do I copy them over and retain the original status?</description>
      <pubDate>Wed, 17 Feb 2010 21:21:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-preserve-constat-attributes-on-blockreference/m-p/2634989#M66946</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-17T21:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to Preserve Constat Attributes on BlockReference</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-preserve-constat-attributes-on-blockreference/m-p/2634990#M66947</link>
      <description>You just skip the constant attributes.&lt;BR /&gt;
&lt;BR /&gt;
They aren't attached to the insertion, they're stored in the block's definition.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;LIAL.WILLIAMS&gt; wrote in message &lt;BR /&gt;
news:6339139@discussion.autodesk.com...&lt;BR /&gt;
I am creating a new blockreference object based on the block definition already &lt;BR /&gt;
present in the BlockTable.&lt;BR /&gt;
&lt;BR /&gt;
BlockReference br = new BlockReference(pt, bdId);    //where bdId is the &lt;BR /&gt;
objectId of the block&lt;BR /&gt;
&lt;BR /&gt;
I am then cycling through the ObjectIds in the BlockTableRecord and if they are &lt;BR /&gt;
AttributeDefinitions then I attach them to the new blockreference:&lt;BR /&gt;
&lt;BR /&gt;
BlockTableRecord bd = (BlockTableRecord)tr.GetObject(bdId, OpenMode.ForRead);&lt;BR /&gt;
&lt;BR /&gt;
foreach (ObjectId attId in bd)&lt;BR /&gt;
{&lt;BR /&gt;
      //Open the Object for reading&lt;BR /&gt;
      Entity ent =  (Entity)tr.GetObject(attId, OpenMode.ForRead);&lt;BR /&gt;
&lt;BR /&gt;
      //Check whether it is an Attribute or not&lt;BR /&gt;
      if (ent is AttributeDefinition)&lt;BR /&gt;
      {&lt;BR /&gt;
          //Get the Definition&lt;BR /&gt;
         AttributeDefinition ad = (AttributeDefinition)ent;&lt;BR /&gt;
&lt;BR /&gt;
         //Set up a new attribute reference&lt;BR /&gt;
         AttributeReference ar = new AttributeReference();&lt;BR /&gt;
&lt;BR /&gt;
         //Add the attribute definition to the attribute reference&lt;BR /&gt;
         ar.SetAttributeFromBlock(ad, br.BlockTransform);&lt;BR /&gt;
&lt;BR /&gt;
         //Add the Attribute reference to the new block&lt;BR /&gt;
         br.AttributeCollection.AppendAttribute(ar);&lt;BR /&gt;
&lt;BR /&gt;
         //Use the transaction to commit the changes&lt;BR /&gt;
         tr.AddNewlyCreatedDBObject(ar, true);&lt;BR /&gt;
&lt;BR /&gt;
   } //End If ent&lt;BR /&gt;
} //End For Loop&lt;BR /&gt;
&lt;BR /&gt;
Question is:  Each of the blocks has 2 attributes that are defined as Constants &lt;BR /&gt;
on the original BlockTableRecord, but when I use the code above to copy them &lt;BR /&gt;
over to the new blockreference they are no longer Constants.  How do I copy them &lt;BR /&gt;
over and retain the original status?&lt;/LIAL.WILLIAMS&gt;</description>
      <pubDate>Wed, 17 Feb 2010 22:35:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-preserve-constat-attributes-on-blockreference/m-p/2634990#M66947</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-17T22:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to Preserve Constat Attributes on BlockReference</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-preserve-constat-attributes-on-blockreference/m-p/2634991#M66948</link>
      <description>Tony,&lt;BR /&gt;
I see the "Constant" method on the AttributeDefinition and can filter them out now.&lt;BR /&gt;
(I was looking at the AttributeReference and it's IsConstant method).&lt;BR /&gt;
&lt;BR /&gt;
But what I really want to do is set the new BlockReference up the same way the original is.&lt;BR /&gt;
That is, copy the two Constant attributes onto the new block reference and then set them as Constant too.&lt;BR /&gt;
&lt;BR /&gt;
I don't see a method that allows me to do that.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Wait!&lt;BR /&gt;
It's starting to come clear now. You mean - &lt;BR /&gt;
The Constants are on the definition by default so by creating an instance of them and attaching them I am actually ending up with two versions of the same attribute.  One is Constant and the one I created is not.&lt;BR /&gt;
&lt;BR /&gt;
Therefore, if I skip the Constants in the code, I still end up with them!

Edited by: lial.williams@arnold.af.mil on Feb 17, 2010 4:52 PM</description>
      <pubDate>Wed, 17 Feb 2010 22:51:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-preserve-constat-attributes-on-blockreference/m-p/2634991#M66948</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-02-17T22:51:41Z</dc:date>
    </item>
  </channel>
</rss>

