Exemplo n.º 1
0
 /// <summary>
 /// Appends an attribute to a block reference. This extends the native AppendAttribute Method.
 /// </summary>
 /// <param name="blockReference">The block reference.</param>
 /// <param name="attributeReference">The attribute definition.</param>
 /// <param name="overwrite">Overwrite if the attribute already exists.</param>
 /// <param name="createIfMissing">Create the attribute if it doesn't already exist.</param>
 public static void AppendAttribute(this BlockReference blockReference, AttributeReference attributeReference, bool overwrite = true, bool createIfMissing = true)
 {
     using (var trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
     {
         var attrs = blockReference.GetBlockAttributes();
         if (!attrs.ContainsKey(attributeReference.Tag))
         {
             if (createIfMissing)
             {
                 blockReference.AttributeCollection.AppendAttribute(attributeReference);
             }
         }
         else
         {
             if (overwrite)
             {
                 blockReference.AttributeCollection.AppendAttribute(attributeReference);
             }
         }
         trans.Commit();
     }
 }