예제 #1
0
 public static void Delete(ObjectId id, string key)
 {
     try {
         if (id.IsErased == false & id.IsEffectivelyErased == false)
         {
             using (World.Docu.LockDocument()) {
                 using (Database db = World.Docu.Database) {
                     using (Transaction tr = db.TransactionManager.StartTransaction()) {
                         using (BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead)) {
                             foreach (ObjectId attributeId in br.AttributeCollection)
                             {
                                 using (AttributeReference attributeRef = (AttributeReference)tr.GetObject(attributeId, OpenMode.ForRead)) {
                                     if (attributeRef.Tag == key)
                                     {
                                         attributeRef.Erase();
                                     }
                                 }
                             }
                         }
                         tr.Commit();
                     }
                 }
             }
         }
     }
     catch (System.Exception ex) {
         Err.Log(ex);
     }
 }
예제 #2
0
        private static void ResetAttributes(this BlockReference br, List <AttributeDefinition> attDefs, Transaction tr)
        {
            Dictionary <string, string> attValues = new Dictionary <string, string>();

            foreach (ObjectId id in br.AttributeCollection)
            {
                if (!id.IsErased)
                {
                    AttributeReference attRef = (AttributeReference)tr.GetObject(id, OpenMode.ForWrite);
                    attValues.Add(attRef.Tag,
                                  attRef.IsMTextAttribute ? attRef.MTextAttribute.Contents : attRef.TextString);
                    attRef.Erase();
                }
            }
            foreach (AttributeDefinition attDef in attDefs)
            {
                AttributeReference attRef = new AttributeReference();
                attRef.SetAttributeFromBlock(attDef, br.BlockTransform);
                if (attDef.Constant)
                {
                    attRef.TextString = attDef.IsMTextAttributeDefinition ?
                                        attDef.MTextAttributeDefinition.Contents :
                                        attDef.TextString;
                }
                else if (attValues.ContainsKey(attRef.Tag))
                {
                    attRef.TextString = attValues[attRef.Tag];
                }
                br.AttributeCollection.AppendAttribute(attRef);
                tr.AddNewlyCreatedDBObject(attRef, true);
            }
        }