DGN 图纸

作为 DWG 一部分的 DGN 格式图纸

Aspose.CAD for Java 允许开发人员导出包含嵌入 DGN 下图的 DWG 文件。以下是演示如何在导出 DWG 文件时访问 DWG 文件内的 DGN 下图的代码。

// 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);

DGN v7 的 3D 实体支持

Aspose.CAD for Java API 引入了加载 DGN AutoCAD 文件的功能,并支持 DGN v7 的 3D 实体。CadImage 类实现了这个目的。每个 DGN 图像支持 9 个预定义视图。它的枚举从 1 到 9。如果在导出时未定义视图,对于多页输出格式(如 PDF),所有视图将被导出,每个视图在一个单独的页面上。DGN 文件格式支持 3D 实体,以及 2D。对于 DGN 格式(同时支持 2D 和 3D),不再使用 VectorRasterizationOptions.TypeOfEntities。

查看支持的 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;
}
}