public static DBObject Create(this Grevit.Types.Room r, Transaction tr) { DictionarySpaceStyle ss = new DictionarySpaceStyle(Command.Database); try { BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); Polyline acPoly = new Polyline(); acPoly.SetDatabaseDefaults(); int i = 0; foreach (Grevit.Types.Point p in r.points) { acPoly.AddVertexAt(i, new Point2d(p.x, p.y), 0, 0, 0); i++; } acPoly.Closed = true; ms.AppendEntity(acPoly); tr.AddNewlyCreatedDBObject(acPoly, true); Autodesk.Aec.Geometry.Profile myProfile = Autodesk.Aec.Geometry.Profile.CreateFromEntity(acPoly, Command.Editor.CurrentUserCoordinateSystem); Space space; bool newEnt = false; if (Command.existing_objects.ContainsKey(r.GID)) { space = (Space)tr.GetObject(Command.existing_objects[r.GID], OpenMode.ForWrite); } else { newEnt = true; space = new Space(); space.SetDatabaseDefaults(Command.Database); space.SetToStandard(Command.Database); } space.Associative = r.associative; space.Name = r.name; space.GeometryType = SpaceGeometryType.TwoD; space.Location = new Point3d(0, 0, 0); space.SetBaseProfile(myProfile, Matrix3d.Identity); LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead); if (r.TypeOrLayer != "") { if (lt.Has(r.TypeOrLayer)) { space.LayerId = lt[r.TypeOrLayer]; } } if (ss.Has(r.FamilyOrStyle, tr)) { space.StyleId = ss.GetAt(r.FamilyOrStyle); } if (newEnt) { ms.AppendEntity(space); tr.AddNewlyCreatedDBObject(space, true); ms.Dispose(); } return(space); } catch (Autodesk.AutoCAD.Runtime.Exception e) { } return(null); }
public static DBObject Create(this Grevit.Types.Room r, Transaction tr) { DictionarySpaceStyle ss = new DictionarySpaceStyle(Command.Database); try { BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); Polyline acPoly = new Polyline(); acPoly.SetDatabaseDefaults(); int i = 0; foreach (Grevit.Types.Point p in r.points) { acPoly.AddVertexAt(i, new Point2d(p.x, p.y), 0, 0, 0); i++; } acPoly.Closed = true; ms.AppendEntity(acPoly); tr.AddNewlyCreatedDBObject(acPoly, true); Autodesk.Aec.Geometry.Profile myProfile = Autodesk.Aec.Geometry.Profile.CreateFromEntity(acPoly, Command.Editor.CurrentUserCoordinateSystem); Space space; bool newEnt = false; if (Command.existing_objects.ContainsKey(r.GID)) { space = (Space)tr.GetObject(Command.existing_objects[r.GID], OpenMode.ForWrite); } else { newEnt = true; space = new Space(); space.SetDatabaseDefaults(Command.Database); space.SetToStandard(Command.Database); } space.Associative = r.associative; space.Name = r.name; space.GeometryType = SpaceGeometryType.TwoD; space.Location = new Point3d(0, 0, 0); space.SetBaseProfile(myProfile, Matrix3d.Identity); LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead); if (r.TypeOrLayer != "") { if (lt.Has(r.TypeOrLayer)) space.LayerId = lt[r.TypeOrLayer]; } if (ss.Has(r.FamilyOrStyle, tr)) space.StyleId = ss.GetAt(r.FamilyOrStyle); if (newEnt) { ms.AppendEntity(space); tr.AddNewlyCreatedDBObject(space, true); ms.Dispose(); } return space; } catch (Autodesk.AutoCAD.Runtime.Exception e) { } return null; }
public static void Create(Grevit.Types.Room r) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; DictionarySpaceStyle ss = new DictionarySpaceStyle(db); try { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); Polyline acPoly = new Polyline(); acPoly.SetDatabaseDefaults(); int i = 0; foreach (Grevit.Types.Point p in r.points) { acPoly.AddVertexAt(i, new Point2d(p.x, p.y), 0, 0, 0); i++; } acPoly.Closed = true; ms.AppendEntity(acPoly); tr.AddNewlyCreatedDBObject(acPoly, true); Autodesk.Aec.Geometry.Profile myProfile = Autodesk.Aec.Geometry.Profile.CreateFromEntity(acPoly, ed.CurrentUserCoordinateSystem); Space space; bool newEnt = false; if (Command.existing_objects.ContainsKey(r.GID)) { space = (Space)tr.GetObject(Command.existing_objects[r.GID], OpenMode.ForWrite); } else { newEnt = true; space = new Space(); space.SetDatabaseDefaults(db); space.SetToStandard(db); } space.Associative = r.associative; space.Name = r.name; space.GeometryType = SpaceGeometryType.TwoD; space.Location = new Point3d(0, 0, 0); space.SetBaseProfile(myProfile, Matrix3d.Identity); LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); if (r.TypeOrLayer != "") { if (lt.Has(r.TypeOrLayer)) space.LayerId = lt[r.TypeOrLayer]; } if (ss.Has(r.FamilyOrStyle, tr)) space.StyleId = ss.GetAt(r.FamilyOrStyle); if (newEnt) { ms.AppendEntity(space); tr.AddNewlyCreatedDBObject(space, true); } AddXData(r, space); writeProperties(space, r.parameters, tr); storeID(r, space.Id); tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ed.WriteMessage(e.Message); tr.Abort(); } finally { tr.Dispose(); } }