ย้ายการวาดลงเพื่อเพิ่มชื่อเรื่อง
Contents
[
Hide
]วิธีการย้ายการวาดลงเพื่อเพิ่มชื่อเรื่อง
ปัญหา: วิธีการย้ายการวาดลงเพื่อเพิ่มชื่อเรื่อง (CADNET-980).
เคล็ดลับ: เพื่อทำสิ่งนี้ สร้างอ็อบเจ็กต์ CadText ด้วยพารามิเตอร์ เพิ่มบล็อกนี้ลงในภาพวาด จากนั้นอัปเดตภาพวาดด้วยขนาดใหม่โดยใช้ UpdateSize เพิ่มเส้นโพลีไลน์ที่เป็นกรอบรอบภาพวาด เพิ่มโพลีไลน์ลงใน BlockEntities["*Model_Space"] และอัปเดตอีกครั้งด้วย UpdateSize.
ตัวอย่าง:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (CadImage cadImage = (CadImage)Image.Load(GetPath(fileName))) | |
{ | |
CadText text = new CadText(); | |
text.DefaultValue = "CAD Drawing"; | |
text.TextHeight = 5; | |
// second alignment point is required in case text is aligned (first alignment point is ignored) | |
text.SecondAlignmentPoint = new Cad3DPoint(cadImage.Width / 2, cadImage.Height - text.TextHeight); | |
text.HorizontalJustification = 1; | |
text.ObjectHandle = "bebebebe";//Guid.NewGuid().ToString(); | |
text.LayerName = "0"; | |
text.SoftOwner = cadImage.Layouts["Model"].BlockTableRecordHandle; | |
cadImage.BlockEntities["*Model_Space"].AddEntity(text); | |
// should be called because we need to add one more entity using new size of image | |
cadImage.UpdateSize(); | |
// add polyline that is a border around the drawing | |
CadLwPolyline lwPolyline = new CadLwPolyline(); | |
lwPolyline.Coordinates = new List<Cad2DPoint>(); | |
lwPolyline.Coordinates.Add(new Cad2DPoint(cadImage.MinPoint.X - 20, cadImage.MinPoint.Y - 20)); | |
lwPolyline.Coordinates.Add(new Cad2DPoint(cadImage.MinPoint.X - 20, cadImage.MaxPoint.Y + 20)); | |
lwPolyline.Coordinates.Add(new Cad2DPoint(cadImage.MaxPoint.X + 20, cadImage.MaxPoint.Y + 20)); | |
lwPolyline.Coordinates.Add(new Cad2DPoint(cadImage.MaxPoint.X + 20, cadImage.MinPoint.Y - 20)); | |
cadImage.BlockEntities["*Model_Space"].AddEntity(lwPolyline); | |
// should be called because adding of new entity may change size of drawing | |
cadImage.UpdateSize(); | |
// remove border polyline after drawing is updated | |
cadImage.RemoveEntity(lwPolyline); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
cadImage.Save(outPath, pdfOptions); | |
} |