public static ObjectId LineAttribute(TypeofLine lt) { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database db = ed.Document.Database; Transaction trans = db.TransactionManager.StartTransaction(); ObjectId ltId = ObjectId.Null; if (lt == TypeofLine.ImaginaryLine) { LinetypeTable ltt = (LinetypeTable)trans.GetObject(db.LinetypeTableId, OpenMode.ForWrite); if (ltt.Has("ImaginaryLine")) { ltId = ltt["ImaginaryLine"]; } else { //create new line type LinetypeTableRecord ltr = new LinetypeTableRecord(); //line properties ltr.AsciiDescription = "ImaginaryLineForPipe"; ltr.PatternLength = 1.0; ltr.NumDashes = 2; ltr.SetDashLengthAt(0, 0.5); ltr.SetDashLengthAt(1, -0.5); ltr.Name = "ImaginaryLine"; ltId = ltt.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); trans.Commit(); trans.Dispose(); } } return(ltId); }
public static ObjectId LineAttribute(TypeofLine lt) { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database db = ed.Document.Database; Transaction trans = db.TransactionManager.StartTransaction(); ObjectId ltId = ObjectId.Null; if (lt == TypeofLine.ImaginaryLine) { LinetypeTable ltt = (LinetypeTable)trans.GetObject(db.LinetypeTableId, OpenMode.ForWrite); if (ltt.Has("ImaginaryLine")) ltId = ltt["ImaginaryLine"]; else { //create new line type LinetypeTableRecord ltr = new LinetypeTableRecord(); //line properties ltr.AsciiDescription = "ImaginaryLineForPipe"; ltr.PatternLength = 1.0; ltr.NumDashes = 2; ltr.SetDashLengthAt(0, 0.5); ltr.SetDashLengthAt(1, -0.5); ltr.Name = "ImaginaryLine"; ltId = ltt.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); trans.Commit(); trans.Dispose(); } } return ltId; }
// 创建直线 // <param name="p1"></param> // <param name="p2"></param> // <returns>id of the line object</returns> public static ObjectId createLine(Point3d p1, Point3d p2, TypeofLine lt = TypeofLine.StraghtLine) { ObjectId createdLineId = new ObjectId(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database db = ed.Document.Database; Transaction trans = db.TransactionManager.StartTransaction(); try { //TODO: create other new line types ObjectId ltId = ObjectId.Null; if (lt == TypeofLine.ImaginaryLine) { LinetypeTable ltt = (LinetypeTable)trans.GetObject(db.LinetypeTableId, OpenMode.ForWrite); if (ltt.Has("ImaginaryLine")) { ltId = ltt["ImaginaryLine"]; } else { //create new line type LinetypeTableRecord ltr = new LinetypeTableRecord(); //line properties ltr.AsciiDescription = "ImaginaryLineForPipe"; ltr.PatternLength = 1.0; ltr.NumDashes = 2; ltr.SetDashLengthAt(0, 0.5); ltr.SetDashLengthAt(1, -0.5); ltr.Name = "ImaginaryLine"; ltId = ltt.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); } } Line l = new Line((Point3d)p1, (Point3d)p2); BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); // now the circle to the current space, model space more than likely if (lt == TypeofLine.ImaginaryLine) { l.LinetypeId = ltId; } createdLineId = btr.AppendEntity(l); // tell the transaction about the new circle so that it can autoclose it trans.AddNewlyCreatedDBObject(l, true); // now commit the transaction trans.Commit(); } catch (System.Exception ex) { ed.WriteMessage("Problem:" + ex.Message); } finally { trans.Dispose(); } return(createdLineId); }
// 创建直线 // <param name="p1"></param> // <param name="p2"></param> // <returns>id of the line object</returns> public static ObjectId createLine(Point3d p1, Point3d p2, TypeofLine lt = TypeofLine.StraghtLine) { ObjectId createdLineId = new ObjectId(); Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Database db = ed.Document.Database; Transaction trans = db.TransactionManager.StartTransaction(); try { //TODO: create other new line types ObjectId ltId = ObjectId.Null; if (lt == TypeofLine.ImaginaryLine) { LinetypeTable ltt = (LinetypeTable)trans.GetObject(db.LinetypeTableId, OpenMode.ForWrite); if (ltt.Has("ImaginaryLine")) ltId = ltt["ImaginaryLine"]; else { //create new line type LinetypeTableRecord ltr = new LinetypeTableRecord(); //line properties ltr.AsciiDescription = "ImaginaryLineForPipe"; ltr.PatternLength = 1.0; ltr.NumDashes = 2; ltr.SetDashLengthAt(0, 0.5); ltr.SetDashLengthAt(1, -0.5); ltr.Name = "ImaginaryLine"; ltId = ltt.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); } } Line l = new Line((Point3d)p1, (Point3d)p2); BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); // now the circle to the current space, model space more than likely if (lt == TypeofLine.ImaginaryLine) l.LinetypeId = ltId; createdLineId = btr.AppendEntity(l); // tell the transaction about the new circle so that it can autoclose it trans.AddNewlyCreatedDBObject(l, true); // now commit the transaction trans.Commit(); } catch (System.Exception ex) { ed.WriteMessage("Problem:" + ex.Message); } finally { trans.Dispose(); } return createdLineId; }