Esportazione del formato DGN AutoCAD

Esportazione del formato DGN AutoCAD in PDF

Aspose.CAD per .NET API ha introdotto la funzionalità per caricare un file DGN AutoCAD e convertirlo in formato PDF. La classe CadImage serve a questo scopo.

È necessario caricare un file DGN esistente come CadImage. Crea un’istanza della classe CadRasterizationOptions e imposta diverse proprietà. Crea un’istanza della classe PdfOptions e passa l’istanza di CadRasterizationOptions. Ora chiama il metodo Save dell’istanza della classe CadImage.

Codice di esempio

Di seguito è riportata la dimostrazione del codice per convertire/esportare DGN in formato PDF.

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.Layouts = new[] { "Model" };
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
cadImage.Save(MyDir + "conic_pyramid.pdf", pdfOptions);
}

Esportazione del formato DGN AutoCAD in formato immagine raster

Aspose.CAD per .NET API ha introdotto la funzionalità per caricare un file DGN AutoCAD e convertirlo in un’immagine raster. La classe CadImage serve a questo scopo.

È necessario caricare un file DGN esistente come CadImage. Crea un’istanza della classe CadRasterizationOptions e imposta diverse proprietà. Crea un’istanza della classe JpegOptions e passa l’istanza di CadRasterizationOptions. Ora chiama il metodo Save dell’istanza della classe CadImage.

Codice di esempio

Di seguito è riportata la dimostrazione del codice per convertire/esportare DGN in immagine JPEG.

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ExportingDGN();
string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn";
// Load an existing DGN file as CadImage.
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an object of DgnRasterizationOptions class and define/set different properties
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 600;
rasterizationOptions.PageHeight = 300;
rasterizationOptions.NoScaling = true;
rasterizationOptions.AutomaticLayoutsScaling = false;
// Create an object of JpegOptions class as we are converting the DGN to jpeg and assign DgnRasterizationOptions object to it.
Aspose.CAD.ImageOptionsBase options = new Aspose.CAD.ImageOptions.JpegOptions();
options.VectorRasterizationOptions = rasterizationOptions;
// Call the save method of the CadImage class object.
cadImage.Save(MyDir + "ExportDGNToRasterImage_out.pdf", options);
}

Supporto di entità 3D per DGN v7

Aspose.CAD per .NET API ha introdotto la funzionalità per caricare un file DGN AutoCAD e supportare le entità 3D per DGN v7. La classe CadImage serve a questo scopo. Ogni immagine DGN supporta 9 viste predefinite. Sono enumerate da 1 a 9. Se la vista non è definita in fase di esportazione, per formati di output a più pagine (come PDF) tutte le viste verranno esportate, ciascuna su una pagina separata. Le entità 3D sono supportate nel formato del file DGN, così come le 2D. Per questo, si utilizza VectorRasterizationOptions, TypeOfEntities non è più utilizzato per il formato DGN (sia 2D che 3D supportati simultaneamente).

Codice di esempio

Di seguito è riportato il codice di esempio per visualizzare gli elementi DGN supportati.

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ExportingDGN();
string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn";
string outFile = MyDir + "Nikon_D90_Camera.dgn";
// Load an existing DGN file as CadImage.
using (DgnImage dgnImage = (DgnImage)Image.Load(sourceFilePath))
{
var options = new PdfOptions
{
VectorRasterizationOptions = new CadRasterizationOptions
{
PageWidth = 1500,
PageHeight = 1500,
AutomaticLayoutsScaling = true,
BackgroundColor = Color.Black,
Layouts = new string[] { "1", "2", "3", "9" }//only export 4 (1,2,3 and 9) views
}
};
dgnImage.Save(outFile, options);
}