Autodesk Forge Platform
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.DatabaseServices; public void delete Group () { Editor ed =.Application.DocumentManager.MdiActiveDocument.Editor; Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; DBDictionary groupDic = trans.GetObject (db.GroupDictionaryId, OpenMode.ForWrite) as DBDictionary; foreach (DBDictionaryEntry groupId in groupDic) { Group group = trans.GetObject(groupId.Value, OpenMode.ForWrite) as Group; ed.WriteMessage ("Earased group :-" + group.Name + "n"); if(group.NumEntities! = 0) { ObjectId [] id = group.GetAllEntityIds (); for (int i = 0; i < group.NumEntities; i++) { Entity ent = (Entity) trans.GetObject (id[i], OpenMode.ForWrite); ent.Erase (true); } } }
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.DatabaseServices; public ObjectId createBlock(string blockname) { ObjectId blkid = ObjectId. Null; try { Database db = HostApplicationServices.WorkingDatabase; using (Transaction tr = db.TransactionManager.StartTransaction ()){ BlockTable bt = (BlockTable) tr.GetObject (db.BlockTableId, OpenMode.ForWrite, false); if (bt.Has(blockname)) { blkid = bt[blockname]; } else { BlockTableRecord btr = new BlockTableRecord (); btr.Name = blockname; btr.Explodable = true; btr.Origin = new Point3d(0, 0, 0); btr.Units = UnitsValue.Inches; btr.BlockScaling = BlockScaling.Any; Line line = new Line (new Point3d (-2, -0.4, 0), new Point3d (2, -0.4, 0)); blkid = bt.Add (btr); Application.SetSystemVariable ("CECOLOR", "ByLayer"); tr.AddNewlyCreatedDBObject (btr, true); } tr.Commit(); } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { Application.ShowAlertDialog ("ERROR: " + "n" + ex.Message + "nSOURCE: " + ex.StackTrace); } return blkid; }
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.DatabaseServices; public static void getAttributesTest() { Document doc = DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; StringBuilder sb = new StringBuilder(); using (DocumentLock docloc = doc.LockDocument()) { using (Transaction tr = db.TransactionManager.StartTransaction ()) { try { BlockTable bt = db.BlockTableId.GetObject (OpenMode.ForRead) as BlockTable; foreach (ObjectId adId in bt) { BlockTableRecord btrec = (BlockTableRecord) tr.GetObject (adId, OpenMode.ForRead); foreach (ObjectId eid in btrec) { DBObject obj = (Entity) tr.GetObject(eid, OpenMode.ForWrite); if (obj is AttributeDefinition) { AttributeDefinition atdef = obj as AttributeDefinition; if (atdef.Constant) { sb.AppendLine(atdef.TextString); } } } } tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage ("n" + ex.Message + "n" + ex.StackTrace); } } }