การวาด DGN

การวาดรูปแบบ DGN เป็นส่วนหนึ่งของ DWG

Aspose.CAD สำหรับ Java ช่วยให้ผู้พัฒนาสามารถส่งออกไฟล์ DWG พร้อมการฝัง DGN ใต้เลเยอร์ภายใน ภายใต้คือโค้ดที่แสดงวิธีการเข้าถึงใต้เลเยอร์ DGN ภายในไฟล์ DWG ขณะส่งออกไฟล์ DWG

// Input and Output file paths
String dataDir = Utils.getDataDir(ExportDGNAsPartofDWG.class) + "ExportingDGN/";
// Input and Output file paths
String fileName = dataDir + "BlockRefDgn.dwg";
String outPath = dataDir +"BlockRefDgn.dwg.pdf";
// Create an instance of PdfOptions class as we are exporting the DWG file to PDF format
com.aspose.cad.imageoptions.PdfOptions exportOptions = new com.aspose.cad.imageoptions.PdfOptions();
// Load any existing DWG file as image and convert it to CadImage type
com.aspose.cad.fileformats.cad.CadImage cadImage = (com.aspose.cad.fileformats.cad.CadImage) com.aspose.cad.Image.load(fileName);
// Go through each entity inside the DWG file
for (com.aspose.cad.fileformats.cad.cadobjects.CadBaseEntity baseEntity : cadImage.getEntities())
{
// Check if entity is an image definition
if (baseEntity.getTypeName() == com.aspose.cad.fileformats.cad.cadconsts.CadEntityTypeName.DGNUNDERLAY)
{
com.aspose.cad.fileformats.cad.cadobjects.CadDgnUnderlay dgnFile = (com.aspose.cad.fileformats.cad.cadobjects.CadDgnUnderlay)baseEntity;
// Get external reference to object
System.out.println(dgnFile.getUnderlayPath());
}
}
// Define settings for CadRasterizationOptions object
com.aspose.cad.imageoptions.CadRasterizationOptions vectorRasterizationOptions = new com.aspose.cad.imageoptions.CadRasterizationOptions();
vectorRasterizationOptions.setPageWidth(1600);
vectorRasterizationOptions.setPageHeight(1600);
vectorRasterizationOptions.setLayouts(new String[] { "Model" });
vectorRasterizationOptions.setAutomaticLayoutsScaling(false);
vectorRasterizationOptions.setNoScaling(true);
vectorRasterizationOptions.setBackgroundColor(com.aspose.cad.Color.getBlack());
vectorRasterizationOptions.setDrawType(com.aspose.cad.fileformats.cad.CadDrawTypeMode.UseObjectColor);
// Set Vector Rasterization Options
exportOptions.setVectorRasterizationOptions(vectorRasterizationOptions);
// Export the DWG to PDF by calling Save method
cadImage.save(outPath, exportOptions);

การสนับสนุนเอนทิตี้ 3D สำหรับ DGN v7

Aspose.CAD สำหรับ Java API ได้แนะนำความสามารถในการโหลดไฟล์ DGN AutoCAD และรองรับเอนทิตี้ 3D สำหรับ DGN v7 คลาส CadImage มีวัตถุประสงค์ดังกล่าว รูปภาพ DGN แต่ละรูปสนับสนุน 9 มุมมองที่กำหนดล่วงหน้า มันจะถูกจัดลำดับจาก 1 ถึง 9 หากมุมมองไม่ได้ถูกกำหนดบนการส่งออก สำหรับฟอร์แมตเอาต์พุตหลายหน้าที่มีหน้า (เช่น PDF) มุมมองทั้งหมดจะถูกส่งออก โดยแต่ละมุมมองอยู่ในหน้าที่แยกต่างหาก เอนทิตี้ 3D ได้รับการสนับสนุนในรูปแบบไฟล์ DGN เช่นเดียวกับ 2D VectorRasterizationOptions.TypeOfEntities ไม่ถูกใช้แล้วสำหรับรูปแบบ DGN (ทั้ง 2D และ 3D ได้รับการสนับสนุนพร้อมกัน)

โค้ดตัวอย่างเพื่อดูองค์ประกอบ DGN ที่ได้รับการสนับสนุน

String fileName = dataDir + "Nikon_D90_Camera.dgn";
String outFile = dataDir + "Nikon_D90_Camera.dgn";
DgnImage objImage = (DgnImage)com.aspose.cad.Image.load(fileName);
PdfOptions options = new PdfOptions();
CadRasterizationOptions vectorOptions = new CadRasterizationOptions();
vectorOptions.setPageWidth(1500);
vectorOptions.setPageHeight(1500);
vectorOptions.setAutomaticLayoutsScaling(true);
vectorOptions.setBackgroundColor(Color.getBlack());
vectorOptions.setLayouts(new String[] { "1", "2", "3", "9" });//only export 4 (1,2,3 and 9) views
options.setVectorRasterizationOptions(vectorOptions);
objImage.save(outFile, options);
// Input and Output file paths
String fileName = "BlockRefDgn.dwg";
String outPath = "BlockRefDgn.dwg.pdf";
DgnImage dgnImage = (DgnImage)Image.load(dataDir);
{
for (DgnDrawingElementBase element : dgnImage.getElements())
{
switch (element.getMetadata().getType())
{
case DgnElementType.Line:
case DgnElementType.Ellipse:
case DgnElementType.Curve:
case DgnElementType.BSplineCurveHeader:
case DgnElementType.Arc:
case DgnElementType.Shape:
case DgnElementType.PolyLine:
case DgnElementType.TextNode:
case DgnElementType.Text:
case DgnElementType.ComplexShapeHeader:
case DgnElementType.ComplexChainHeader:
{
//previously supported entities, now supported also for 3D
break;
}
case DgnElementType.SolidHeader3D:
case DgnElementType.Cone:
case DgnElementType.CellHeader:
{
//supported 3D entities
break;
}
}