addPoly3d(this List <Point3d> pnt3ds, string nameLayer = "0", short color = 256) { ObjectId idPoly3d = ObjectId.Null; Polyline3d poly3d = new Polyline3d(); try { using (Transaction tr = BaseObjs.startTransactionDb()) { BlockTable bt = (BlockTable)BaseObjs._db.BlockTableId.GetObject(OpenMode.ForRead); BlockTableRecord MS = (BlockTableRecord)bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite); idPoly3d = MS.AppendEntity(poly3d); tr.AddNewlyCreatedDBObject(poly3d, true); poly3d.SetDatabaseDefaults(); Layer.manageLayers(nameLayer); poly3d.Layer = nameLayer; poly3d.Color = Color.FromColorIndex(ColorMethod.ByBlock, color); foreach (Point3d pnt3d in pnt3ds) { PolylineVertex3d poly3dVertex = new PolylineVertex3d(pnt3d); poly3d.AppendVertex(poly3dVertex); tr.AddNewlyCreatedDBObject(poly3dVertex, true); } tr.Commit(); }// end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Draw.cs: line: 406"); } return(idPoly3d); }
public static ObjectId Create3dPolyline(this Database database, IEnumerable <Point3d> points, string layer = null, int layerColor = 256, short entityCollor = 256) { using (var transAction = database.TransactionManager.StartOpenCloseTransaction()) { // Get the layer table from the drawing using (var blocktable = (BlockTable)transAction.GetObject(database.BlockTableId, OpenMode.ForRead)) { var blockTableRecord = (BlockTableRecord)transAction.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite); ObjectId id; //create the layer using (var pl3d = new Polyline3d(Poly3dType.SimplePoly, new Point3dCollection(points.ToArray()), false)) { pl3d.SetDatabaseDefaults(); if (layer != null) { database.CreateLayer(layer, (short)layerColor, ""); pl3d.Layer = layer; } pl3d.ColorIndex = entityCollor; id = blockTableRecord.AppendEntity(pl3d); transAction.AddNewlyCreatedDBObject(pl3d, true); transAction.Commit(); return(id); } } } }
addPoly3d(Point3d[] pnt3ds, string nameLayer = "0", short color = 256) { ObjectId idPoly3d = ObjectId.Null; Polyline3d poly3d = new Polyline3d(); try { using (Transaction tr = BaseObjs.startTransactionDb()) { BlockTableRecord MS = Blocks.getBlockTableRecordMS(); idPoly3d = MS.AppendEntity(poly3d); tr.AddNewlyCreatedDBObject(poly3d, true); int i = -1; poly3d.SetDatabaseDefaults(); Layer.manageLayers(nameLayer); poly3d.Layer = nameLayer; poly3d.Color = Color.FromColorIndex(ColorMethod.ByBlock, color); foreach (Point3d pnt3d in pnt3ds) { i = ++i; PolylineVertex3d poly3dVertex = new PolylineVertex3d(pnt3d); poly3d.AppendVertex(poly3dVertex); tr.AddNewlyCreatedDBObject(poly3dVertex, true); } tr.Commit(); }// end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Draw.cs: line: 443"); } return(idPoly3d); }
handOverPoly3d2(this ObjectId idPoly3dOrg, List <Point3d> pnts3d) { Database db = BaseObjs._db; Point3dCollection pnts3dColl = new Point3dCollection(); foreach (Point3d pnt3d in pnts3d) { pnts3dColl.Add(pnt3d); } using (OpenCloseTransaction tr = db.TransactionManager.StartOpenCloseTransaction()) { Polyline3d poly3dOrg = (Polyline3d)tr.GetObject(idPoly3dOrg, OpenMode.ForRead); Debug.Print(poly3dOrg.Handle.ToString()); Polyline3d poly3dNew = new Polyline3d(Poly3dType.SimplePoly, pnts3dColl, false); poly3dNew.SetDatabaseDefaults(); poly3dNew.Layer = poly3dOrg.Layer; poly3dOrg.UpgradeOpen(); poly3dOrg.HandOverTo(poly3dNew, true, true); Debug.Print(poly3dOrg.Handle.ToString()); Debug.Print(poly3dNew.Handle.ToString()); bool x = poly3dOrg.IsDisposed; poly3dOrg.Dispose(); tr.AddNewlyCreatedDBObject(poly3dNew, true); tr.Commit(); } }
public static DBObject Create(this Grevit.Types.PLine a, Transaction tr) { try { LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead); Point3dCollection pc = new Point3dCollection(); foreach (Grevit.Types.Point p in a.points) { pc.Add(p.ToPoint3d()); } Polyline3d pp = new Polyline3d(Poly3dType.SimplePoly, pc, a.closed); pp.SetDatabaseDefaults(Command.Database); if (lt.Has(a.TypeOrLayer)) { pp.LayerId = lt[a.TypeOrLayer]; } BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); ms.AppendEntity(pp); tr.AddNewlyCreatedDBObject(pp, true); return(pp); } catch (Autodesk.AutoCAD.Runtime.Exception e) { } return(null); }
updatePoly3dCoordinates(this ObjectId idPoly3dOrg, List <Point3d> pnts3d) { ObjectId idPoly3dNew = ObjectId.Null; Polyline3d poly3dNew = new Polyline3d(); using (Transaction tr = BaseObjs.startTransactionDb()) { BlockTableRecord ms = Blocks.getBlockTableRecordMS(); idPoly3dNew = ms.AppendEntity(poly3dNew); poly3dNew.SetDatabaseDefaults(); poly3dNew.Layer = idPoly3dOrg.getLayer(); foreach (Point3d pnt3dX in pnts3d) { PolylineVertex3d v3d = new PolylineVertex3d(pnt3dX); poly3dNew.AppendVertex(v3d); tr.AddNewlyCreatedDBObject(v3d, true); } tr.AddNewlyCreatedDBObject(poly3dNew, true); tr.Commit(); } using (Transaction tr1 = BaseObjs.startTransactionDb()) { DBObject dbObjOrg = tr1.GetObject(idPoly3dOrg, OpenMode.ForRead); DBObject dbObjNew = tr1.GetObject(idPoly3dNew, OpenMode.ForRead); dbObjNew.UpgradeOpen(); dbObjNew.SwapIdWith(dbObjOrg.ObjectId, true, true); idPoly3dNew.delete(); tr1.Commit(); } }
public static Polyline3d CreatePolyLine3d(Database db, bool closed, Point3dCollection points) { using (CurrentDB curr = new CurrentDB(db)) { Polyline3d pline = new Polyline3d(Poly3dType.SimplePoly, points, closed); pline.SetDatabaseDefaults(db); return(pline); } }
addVertexToPoly3d(this ObjectId idPoly3dOrg, Point3d pnt3d, int pos, Handle hCgPNt) { List <Point3d> pnts3d = idPoly3dOrg.getCoordinates3dList(); ObjectId idPoly3dNew = ObjectId.Null; Polyline3d poly3dNew = new Polyline3d(); using (Transaction tr = BaseObjs.startTransactionDb()) { BlockTableRecord ms = Blocks.getBlockTableRecordMS(); idPoly3dNew = ms.AppendEntity(poly3dNew); poly3dNew.SetDatabaseDefaults(); poly3dNew.Layer = idPoly3dOrg.getLayer(); pnts3d.Insert(pos + 1, pnt3d); foreach (Point3d pnt3dX in pnts3d) { PolylineVertex3d v3d = new PolylineVertex3d(pnt3dX); poly3dNew.AppendVertex(v3d); tr.AddNewlyCreatedDBObject(v3d, true); } tr.AddNewlyCreatedDBObject(poly3dNew, true); tr.Commit(); } using (Transaction tr1 = BaseObjs.startTransactionDb()) { DBObject dbObjOrg = tr1.GetObject(idPoly3dOrg, OpenMode.ForRead); DBObject dbObjNew = tr1.GetObject(idPoly3dNew, OpenMode.ForRead); dbObjNew.UpgradeOpen(); dbObjNew.SwapIdWith(dbObjOrg.ObjectId, true, true); idPoly3dNew.delete(); tr1.Commit(); } ResultBuffer rb = idPoly3dOrg.getXData(apps.lnkBrks); TypedValue[] tvs = rb.AsArray(); TypedValue[] tvsNew = new TypedValue[tvs.Length + 1]; for (int i = 0; i < pos + 2; i++) { tvsNew[i] = tvs[i]; } tvsNew.SetValue(new TypedValue(1005, hCgPNt), pos + 2); for (int i = pos + 2; i < tvs.Length; i++) { tvsNew[i + 1] = tvs[i]; } idPoly3dOrg.clearXData(apps.lnkBrks); idPoly3dOrg.setXData(tvsNew, apps.lnkBrks); }
handOverPoly3d(this ObjectId idPoly3dOrg, List <Point3d> pnts3d) { Polyline3d poly3dOrg = (Polyline3d)idPoly3dOrg.Open(OpenMode.ForRead); Point3dCollection pnts3dColl = new Point3dCollection(); foreach (Point3d pnt3d in pnts3d) { pnts3dColl.Add(pnt3d); } Polyline3d poly3dNew = new Polyline3d(Poly3dType.SimplePoly, pnts3dColl, false); poly3dNew.SetDatabaseDefaults(); poly3dOrg.UpgradeOpen(); poly3dOrg.HandOverTo(poly3dNew, true, true); poly3dNew.Close(); poly3dOrg.Dispose(); }
/// <summary> /// Adds the polyline3d. /// </summary> /// <param name="sidedb">The sidedb.</param> /// <param name="points">The points.</param> /// <param name="layername">The layername.</param> /// <param name="isClosed">if set to <c>true</c> [is closed].</param> /// <param name="colorIndex">Index of the color.</param> /// <returns>ObjectId.</returns> public static ObjectId AddPolyline3d(Autodesk.AutoCAD.DatabaseServices.Database sidedb, Point3dCollection points, string layername, bool isClosed, int colorIndex) { //_logger.Debug("Start AddPolyline"); ObjectId id = ObjectId.Null; Autodesk.AutoCAD.DatabaseServices.Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; HostApplicationServices.WorkingDatabase = sidedb; using (Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sidedb.TransactionManager) { using (Transaction tr = tm.StartTransaction()) { Polyline3d pline = new Polyline3d(); pline.SetDatabaseDefaults(); pline.Layer = layername; if ((colorIndex > 0) && (colorIndex < 256)) { pline.ColorIndex = colorIndex; } // int index = 0; // double width = 0.0; foreach (PolylineVertex3d pt in points) { pline.AppendVertex(pt); } pline.Closed = isClosed; id = AddToDatabase(db, pline, tr); tr.Commit(); } } //_logger.Debug("End AddPolyline"); return(id); }
/// <summary> /// Adds the polyline3d. /// </summary> /// <param name="sidedb">The sidedb.</param> /// <param name="pline">The pline.</param> /// <param name="layername">The layername.</param> /// <param name="isClosed">if set to <c>true</c> [is closed].</param> /// <param name="colorIndex">Index of the color.</param> /// <returns>ObjectId.</returns> public static ObjectId AddPolyline3d(Autodesk.AutoCAD.DatabaseServices.Database sidedb, Polyline3d pline, string layername, bool isClosed, int colorIndex) { //_logger.Debug("Start AddPolyline"); ObjectId id = ObjectId.Null; Autodesk.AutoCAD.DatabaseServices.Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; HostApplicationServices.WorkingDatabase = sidedb; using (Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sidedb.TransactionManager) { using (Transaction tr = tm.StartTransaction()) { pline.SetDatabaseDefaults(); if (!LayerManager.IsDefined(sidedb, layername)) { LayerManager.CreateLayer(sidedb, layername); } pline.Layer = layername; if ((colorIndex > 0) && (colorIndex < 256)) { pline.ColorIndex = colorIndex; } //int index = 0; pline.Closed = isClosed; id = AddToDatabase(sidedb, pline, tr); tr.Commit(); } } //_logger.Debug("End AddPolyline"); return(id); }
public static DBObject Create(this Grevit.Types.PLine a, Transaction tr) { try { LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead); Point3dCollection pc = new Point3dCollection(); foreach (Grevit.Types.Point p in a.points) pc.Add(p.ToPoint3d()); Polyline3d pp = new Polyline3d(Poly3dType.SimplePoly, pc, a.closed); pp.SetDatabaseDefaults(Command.Database); if (lt.Has(a.TypeOrLayer)) pp.LayerId = lt[a.TypeOrLayer]; BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); ms.AppendEntity(pp); tr.AddNewlyCreatedDBObject(pp, true); return pp; } catch (Autodesk.AutoCAD.Runtime.Exception e) { } return null; }
public static void Create(Grevit.Types.PLine a) { Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; try { LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead); Point3dCollection pc = new Point3dCollection(); foreach (Grevit.Types.Point p in a.points) pc.Add(GrevitPtoPoint3d(p)); Polyline3d pp = new Polyline3d(Poly3dType.SimplePoly, pc, a.closed); pp.SetDatabaseDefaults(db); if (lt.Has(a.TypeOrLayer)) pp.LayerId = lt[a.TypeOrLayer]; BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); ms.AppendEntity(pp); tr.AddNewlyCreatedDBObject(pp, true); writeProperties(pp, a.parameters, tr); storeID(a, pp.Id); tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ed.WriteMessage(e.Message); tr.Abort(); } finally { tr.Dispose(); } }