<?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: Title Block Replacement - Does not honor constant attribute in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8128330#M25385</link>
    <description>&lt;P&gt;I got that figured out. I added a check to determine if it was a constant attribute and skip the value copy if it is and everything is working. Thanks for the sanity checks.&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jul 2018 11:14:33 GMT</pubDate>
    <dc:creator>ThomasRambach</dc:creator>
    <dc:date>2018-07-13T11:14:33Z</dc:date>
    <item>
      <title>Title Block Replacement - Does not honor constant attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8117630#M25379</link>
      <description>&lt;P&gt;I have some code that replaces title blocks in batch that works good (excerpt below). But for some reason the few attributes in the block that are set to Constant = Yes are appearing in an DDATTE edit of the block after it's inserted even with the attribute set correctly. A manual insert of the block has the desire result. What am I doing wrong? What am I missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private static bool ProcessTitleBlockObjectMigration(Transaction transaction, Database db, ObjectId id, string titleBlocksPath)
        {
            using (DBObject dbObj = transaction.GetObject(id, OpenMode.ForRead))
            {
                if (dbObj is BlockReference)
                {
                    BlockReference blockRef = (BlockReference)dbObj;
                    string blockName = blockRef.Name;
                    ObjectId ownerId = blockRef.OwnerId;
                    string replacementBlockName = GetReplacementBlockName(blockName);

                    if (replacementBlockName == "")
                        return false;

                    // Upgrade to write access.
                    blockRef.UpgradeOpen();
                    // store the current block position/scale/tranform/attributes
                    Point3d position = blockRef.Position;
                    Scale3d scaleFactors = blockRef.ScaleFactors;
                    Matrix3d tranformMatrix = blockRef.BlockTransform;
                    Dictionary&amp;lt;string, string&amp;gt; attributeDataDict = CadUtils.ExtractBlockAttributedata(transaction, blockRef);

                    // MAPPING CODE
                    RemapAttribute(attributeDataDict, "MATL", "MATERIAL");
                    RemapAttribute(attributeDataDict, "REV", "REV.");
                    RemapAttribute(attributeDataDict, "HEAT", "HEAT_TREATMENT");
                    RemapAttribute(attributeDataDict, "SPECS", "SPECIFICATIONS");
                    RemapAttribute(attributeDataDict, "DSGN", "DSG/INT");
                    RemapAttribute(attributeDataDict, "NOTES", "DRAWING_TYPE");
                    RemapAttribute(attributeDataDict, "DWG_TITLE", "DRAWING_DESCRIPTION");
                    RemapAttribute(attributeDataDict, "EFC", "EFC No.");


                    if (attributeDataDict.ContainsKey("XXX-000000-00000"))
                        RemapAttribute(attributeDataDict, "XXX-000000-00000", "DWG_NO");



                    // Hard rule. Check rev and make it 0 if its blank or -
                    if (attributeDataDict.ContainsKey("REV."))
                    {
                        string rev = attributeDataDict["REV."].Trim();
                        if (rev == "" || rev == "-")
                            attributeDataDict["REV."] = "0";
                    }

                    blockRef.Erase();

                    ObjectId btrId = CadUtils.LoadBlockFromFile(transaction, db, titleBlocksPath + "\\" + replacementBlockName, (replacementBlockName.Replace(".dwg", "")).Replace("_","")); // Replace "_" added by TJR
                    BlockReference newBtr = new BlockReference(position, btrId);

                    using (BlockTableRecord space = (BlockTableRecord)transaction.GetObject(ownerId, OpenMode.ForWrite))
                    {
                        space.AppendEntity(newBtr);
                        transaction.AddNewlyCreatedDBObject(newBtr, true);

                        newBtr.Position = position; // Added by TJR 07/07/2018 ####
                        newBtr.ScaleFactors = scaleFactors;
                        newBtr.BlockTransform = tranformMatrix;
                        CadUtils.CopyAttributesToBlock(db, transaction, newBtr, attributeDataDict);
                    }


                    return true;
                }

                return false;
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Jul 2018 13:11:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8117630#M25379</guid>
      <dc:creator>ThomasRambach</dc:creator>
      <dc:date>2018-07-09T13:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Title Block Replacement - Does not honor constant attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8117798#M25380</link>
      <description>&lt;P&gt;I am not very sure "Does not honor..." mean: do these constant attributes present, or not present after your code inserts the replacing block?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, it looks like the most portion of your code shown here is about retrieve existing attribute values before existing block is erased. This is totally irrelevant to the issue at hand. Probably, the code in CadUtil.CopyAttributesToBlock() actually add the attributes to the newly inserted block reference. That is where the code may not write correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 14:04:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8117798#M25380</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2018-07-09T14:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: Title Block Replacement - Does not honor constant attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8118048#M25381</link>
      <description>&lt;P&gt;You're right... here's that code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static List&amp;lt;ObjectId&amp;gt; CopyAttributesToBlock(Database db, Transaction transaction, BlockReference br, Dictionary&amp;lt;string,string&amp;gt; dataDict )
        {

            if(!dataDict.ContainsKey("DWG_NO"))
                Log.LogFailure("Attribute did not exist DWG_NO in file " + db.Filename);

            List&amp;lt;ObjectId&amp;gt; refIdList = new List&amp;lt;ObjectId&amp;gt;();
            List&amp;lt;string&amp;gt; unusedKeys = dataDict.Keys.ToList&amp;lt;string&amp;gt;();
            using (BlockTableRecord btr = (BlockTableRecord)transaction.GetObject(br.BlockTableRecord, OpenMode.ForWrite, false, true))
            {
                foreach (ObjectId id in btr)
                {
                    using (Entity ent = (Entity)transaction.GetObject(id, OpenMode.ForRead, false, true))
                    {
                        if (ent is AttributeDefinition)
                        {
                            AttributeDefinition def = (AttributeDefinition)ent;
                            using (AttributeReference attributeRef = new AttributeReference())
                            {
                                attributeRef.SetAttributeFromBlock(def, br.BlockTransform);
                                br.AttributeCollection.AppendAttribute(attributeRef);
                                if (dataDict.ContainsKey(attributeRef.Tag))
                                {
                                    attributeRef.TextString = dataDict[attributeRef.Tag];
                                    unusedKeys.Remove(attributeRef.Tag);
                                }
                                refIdList.Add(attributeRef.Id);

                                Database wdb = HostApplicationServices.WorkingDatabase;
                                HostApplicationServices.WorkingDatabase = db;
                                attributeRef.AdjustAlignment(db);
                                HostApplicationServices.WorkingDatabase = wdb;
                            }
                        }
                    }
                }

                // Log attributes that are not found that ar enot listed here
                foreach(string key in unusedKeys)
                {

                        Log.LogFailure("Attribute had no mapping "+key+ " in file " + db.Filename);
                }
            }

            return refIdList;
        }

    }&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Jul 2018 15:26:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8118048#M25381</guid>
      <dc:creator>ThomasRambach</dc:creator>
      <dc:date>2018-07-09T15:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Title Block Replacement - Does not honor constant attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8118238#M25382</link>
      <description>&lt;P&gt;It seems to me, your code DOES NOT add the newly created AttributeReference to the transaction with&amp;nbsp;&lt;/P&gt;
&lt;P&gt;transaction.AddNewlyCreatedDBObject(), thus, no AttributeReference would&amp;nbsp;eventually be added&amp;nbsp;the replacing block after your code execution (except for the constant attribute, which AutoCAD treats it as Text entity in the block definition).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what in your post's title&amp;nbsp;confuses me: the replacing block should not have any regular attribute in it (because of not being added into the transaction), yet you are saying "does not honor constant attribute"...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 16:23:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8118238#M25382</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2018-07-09T16:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Title Block Replacement - Does not honor constant attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8118319#M25383</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;I think I'm confusing myself. I inherited this code so I'm trying to reverse engineer it. The code might be missing something. The other normal attributes copy without issues (somehow). The attributes marked as constant come in acting as normal attributes and not constant attributes.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 16:57:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8118319#M25383</guid>
      <dc:creator>ThomasRambach</dc:creator>
      <dc:date>2018-07-09T16:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Title Block Replacement - Does not honor constant attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8127751#M25384</link>
      <description>Your code is not checking each AttributeDefinition to see if it is constant and skipping it in that case.</description>
      <pubDate>Fri, 13 Jul 2018 05:27:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8127751#M25384</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-07-13T05:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Title Block Replacement - Does not honor constant attribute</title>
      <link>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8128330#M25385</link>
      <description>&lt;P&gt;I got that figured out. I added a check to determine if it was a constant attribute and skip the value copy if it is and everything is working. Thanks for the sanity checks.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 11:14:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/title-block-replacement-does-not-honor-constant-attribute/m-p/8128330#M25385</guid>
      <dc:creator>ThomasRambach</dc:creator>
      <dc:date>2018-07-13T11:14:33Z</dc:date>
    </item>
  </channel>
</rss>

