/// <summary> /// Adds the polyline. /// </summary> /// <param name="trans">The trans.</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></returns> public static ObjectId AddPolyline(Transaction trans, Point2dCollection 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; Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager; using (Polyline pline = new Polyline()) { pline.SetDatabaseDefaults(); pline.Layer = layername; if ((colorIndex > 0) && (colorIndex < 256)) { pline.ColorIndex = colorIndex; } int index = 0; double buldge = 0.0; double width = 0.0; foreach (Point2d pt in points) { pline.AddVertexAt(index++, pt, buldge, width, width); } pline.Closed = isClosed; id = AddToDatabase(db, pline, trans); } //_logger.Debug("End AddPolyline"); return(id); }
/// <summary> /// Adds the predefined hatch. /// </summary> /// <param name="trans">The trans.</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="patternName">Name of the pattern.</param> /// <returns></returns> public static ObjectId AddPredefinedHatch(Transaction trans, Point2dCollection points, string layername, bool isClosed, string patternName) { //_logger.Debug("Start AddPredefinedHatch"); ObjectId id = ObjectId.Null; Autodesk.AutoCAD.DatabaseServices.Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database; Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager; using (Hatch hatch = new Hatch()) { hatch.SetDatabaseDefaults(); hatch.Layer = layername; id = AddToDatabase(db, hatch, trans); hatch.UpgradeOpen(); //hatch.HatchStyle = HatchStyle.Outer; hatch.Associative = true; hatch.PatternScale = 100.0; hatch.SetHatchPattern(HatchPatternType.PreDefined, patternName); double buldge = 0.0; HatchLoop loop = new HatchLoop(HatchLoopTypes.Polyline); foreach (Point2d pt in points) { BulgeVertex bv = new BulgeVertex(pt, buldge); loop.Polyline.Add(bv); } hatch.AppendLoop(loop); hatch.EvaluateHatch(true); } //_logger.Debug("End AddPredefinedHatch"); return(id); }
/// <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); }