Disegni DXF
Esportazione di Disegni DXF in PDF
Aspose.CAD fornisce la funzionalità per caricare entità di disegno DXF di AutoCAD e renderizzarle come disegno completo in formato PDF. L’approccio di conversione da DXF a PDF funziona come segue:
- Carica il file di disegno DXF utilizzando il metodo di fabbrica Image.Load.
- Crea un oggetto della classe CadRasterizationOptions e imposta le proprietà PageHeight e PageWidth.
- Crea un oggetto della classe PdfOptions e imposta la proprietà VectorRasterizationOptions.
- Chiama Image.Save passando un oggetto di PdfOptions come secondo parametro.
Il campione di codice sottostante mostra come convertire un file utilizzando le impostazioni predefinite.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of CadRasterizationOptions and set its various properties | |
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
rasterizationOptions.BackgroundColor = Aspose.CAD.Color.White; | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
// Create an instance of PdfOptions | |
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions(); | |
// Set the VectorRasterizationOptions property | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
MyDir = MyDir + "conic_pyramid_out.pdf"; | |
//Export the DXF to PDF | |
image.Save(MyDir, pdfOptions); | |
} |
Formati Supportati
Al momento supportiamo completamente i formati di file DXF 2010 di AutoCAD. Le versioni DXF precedenti non sono garantite per essere valide al 100%. Abbiamo in programma di includere più formati e funzionalità nelle future versioni di Aspose.CAD.
Entità Supportate
Al momento supportiamo tutte le entità 2D diffuse e i loro parametri predefiniti di base come segue:
- Dimensione allineata
- Dimensione angolare
- Arco
- Attributo
- Riferimento blocco
- Cerchio
- Dimensione diametro
- Ellisse
- Riempimento
- Linea
- Testo multilinea
- Dimensione ordinata
- Punto
- Polilinea
- Dimensione radiale
- Raggio
- Dimensione ruotata
- Tavola
- Testo
- Xline
Gestione della Memoria
La proprietà ExactReallocateOnly della classe Cache può essere utilizzata per controllare la riallocazione della memoria. La riallocazione è più probabile che si verifichi per le cache pre-allocate. Può avvenire quando il sistema scopre che lo spazio allocato non sarà sufficiente.
- Se ExactReallocateOnly è impostato sul valore predefinito, False, lo spazio viene riallocato allo stesso supporto.
- Quando impostato su True, la riallocazione non può superare lo spazio massimo specificato. In questo caso, la cache in memoria già allocata (che richiede riallocazione) viene liberata e viene allocato uno spazio esteso su disco.
Esportazione di un Livello Specifico dei Disegni DXF in PDF
Questo approccio funziona come segue:
- Apri un file di disegno DXF utilizzando il metodo di fabbrica Image.Load.
- Crea un’istanza di CadRasterizationOptions e specifica le proprietà PageWidth e PageHeight.
- Aggiungi livelli all’oggetto di CadRasterizationOptions.
- Crea un’istanza di PdfOptions e imposta la sua proprietà VectorRasterizationOptions.
- Chiama il metodo Image.Save e passa l’oggetto di PdfOptions come secondo parametro.
Il campione di codice sottostante mostra come convertire un livello specifico di DXF in PDF.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of CadRasterizationOptions and set its various properties | |
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
// Add desired layers | |
rasterizationOptions.Layers = new string[] { "LayerA" }; | |
// Create an instance of PdfOptions | |
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions(); | |
// Set the VectorRasterizationOptions property | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
MyDir = MyDir + "conic_pyramid_layer_out.pdf"; | |
//Export the DXF to PDF | |
image.Save(MyDir, pdfOptions); | |
} |
Renderizza i file PDF come parte dei Disegni DXF
Questo approccio funziona come segue:
- Carica il file di disegno DXF utilizzando il metodo Image.Load.
- Crea un oggetto della classe CadRasterizationOptions e carica i file PDF.
- Imposta le proprietà PageHeight e PageWidth.
- Chiama Image.Save e salva il file.
Il campione di codice sottostante mostra come renderizzare file PDF come parte dei disegni DXF.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of CadRasterizationOptions and set its various properties | |
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
// Specify desired layout name | |
rasterizationOptions.Layouts = new string[] { "Model" }; | |
// Create an instance of PdfOptions | |
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions(); | |
// Set the VectorRasterizationOptions property | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
MyDir = MyDir + "conic_pyramid_layout_out.pdf"; | |
//Export the DXF to PDF | |
image.Save(MyDir, pdfOptions); | |
} |
Esportazione del sottofondo DGN incorporato per il formato DXF
Aspose.CAD fornisce la funzionalità di caricare file DXF di AutoCAD ed esportare il sottofondo DGN incorporato per il formato DXF.
Il campione di codice sottostante mostra come raggiungere i requisiti specificati.
// 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); | |
} |
Supporto per il Salvataggio dei File DXF
Aspose.CAD fornisce la funzionalità di caricare file DXF di AutoCAD, apportare modifiche e salvarli nuovamente come file DXF.
Il campione di codice sottostante mostra come raggiungere i requisiti specificati.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath)) | |
{ | |
// any entities updates | |
cadImage.Save(MyDir+"conic.dxf"); | |
} | |
Esportazione di DXF in WMF
Questo approccio funziona come segue:
- Carica il file di disegno DXF utilizzando il metodo Image.Load.
- Crea un oggetto della classe CadRasterizationOptions e carica i file PDF.
- Imposta le proprietà PageHeight e PageWidth.
- Chiama Image.Save e salva il file.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (var image = Image.Load("NRB-GRID-BLOCK-MD-PROVALVDK-241000-162000-45400.dgn")) | |
{ | |
var vectorOptions = new CadRasterizationOptions(); | |
vectorOptions.AutomaticLayoutsScaling = true; | |
vectorOptions.BackgroundColor = Color.Black; | |
vectorOptions.PageWidth = 500; | |
vectorOptions.PageHeight = 500; | |
WmfOptions wmfOptions = new WmfOptions() | |
{ | |
VectorRasterizationOptions = vectorOptions | |
}; | |
image.Save("NRB-GRID-BLOCK-MD-PROVALVDK-241000-162000-45400.dgn.wmf", wmfOptions); | |
} |
Esportazione di un Layout Specifico DXF in PDF
Questo approccio funziona come segue:
- Apri un file di disegno DXF utilizzando il metodo di fabbrica Image.Load.
- Crea un’istanza di CadRasterizationOptions e specifica le proprietà PageWidth e PageHeight.
- Specifica il nome del layout desiderato utilizzando la proprietà CadRasterizationOptions.Layouts.
- Crea un’istanza di PdfOptions e imposta la sua proprietà VectorRasterizationOptions.
- Esporta il disegno in PDF chiamando il metodo Image.Save e passando l’oggetto di PdfOptions come secondo parametro.
Il campione di codice sottostante mostra come convertire un layout specifico di DXF in PDF.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of CadRasterizationOptions and set its various properties | |
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
// Specify desired layout name | |
rasterizationOptions.Layouts = new string[] { "Model" }; | |
// Create an instance of PdfOptions | |
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions(); | |
// Set the VectorRasterizationOptions property | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
MyDir = MyDir + "conic_pyramid_layout_out.pdf"; | |
//Export the DXF to PDF | |
image.Save(MyDir, pdfOptions); | |
} |
Supporto per il Ritaglio dei Blocchi
Aspose.CAD fornisce la funzionalità di Ritaglio dei Blocchi. L’approccio di Ritaglio dei Blocchi funziona come segue:
- Carica il file di disegno DXF utilizzando il metodo di fabbrica Image.Load.
- Crea un oggetto della classe CadRasterizationOptions e carica i file PDF.
- Imposta le proprietà desiderate di CadRasterizationOptions.
- Chiama Image.Save passando un oggetto di PdfOptions come secondo parametro e salva il file.
Il campione di codice sottostante mostra come funziona il Ritaglio dei Blocchi.
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string inputFile = MyDir + "SLS-CW-CD-CE001-R01_blockClip.dxf"; | |
string outputFile = MyDir + "SLS-CW-CD-CE001-R01_blockClip.pdf"; | |
using (CadImage cadImage = (CadImage)Image.Load(inputFile)) | |
{ | |
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions | |
{ | |
BackgroundColor = Aspose.CAD.Color.White, | |
DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor, | |
PageWidth = 1200, | |
PageHeight = 1600, | |
Margins = new Margins | |
{ | |
Top = 5, | |
Right = 30, | |
Bottom = 5, | |
Left = 30 | |
}, | |
Layouts = new string[] { "Model" } | |
}; | |
PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions | |
{ | |
VectorRasterizationOptions = rasterizationOptions | |
}; | |
cadImage.Save(outputFile, pdfOptions); |
Esportazione di Immagini in DXF
Utilizzando Aspose.CAD, puoi esportare immagini in formato DXF. Utilizzando questo approccio, puoi eseguire le seguenti azioni:
- Imposta un nuovo carattere
- Nascondi le entità
- Aggiorna il testo
Il seguente frammento di codice ti mostra come eseguire le azioni elencate sopra.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
foreach (var file in new DirectoryInfo(MyDir).EnumerateFiles("*.dxf")) | |
{ | |
// **************************** | |
// Set new font per document | |
// **************************** | |
using (var cadImage = (CadImage)Image.Load(file.FullName)) | |
{ | |
// Iterate over the items of CadStyleTableObject | |
foreach (CadStyleTableObject style in cadImage.Styles) | |
{ | |
// Set font name | |
style.PrimaryFontName = "Broadway"; | |
} | |
cadImage.Save(file.FullName + "_font.dxf"); | |
} | |
// **************************** | |
// Hide all "straight" lines | |
// **************************** | |
using (var cadImage = (CadImage)Image.Load(file.FullName)) | |
{ | |
foreach (var entity in cadImage.Entities) | |
{ | |
// Make lines invisible | |
if (entity.TypeName == CadEntityTypeName.LINE) | |
{ | |
entity.Visible = 0; | |
} | |
} | |
cadImage.Save(file.FullName + "_lines.dxf"); | |
} | |
// **************************** | |
// Manipulations with text | |
// **************************** | |
using (var cadImage = (CadImage)Image.Load(file.FullName)) | |
{ | |
foreach (var entity in cadImage.Entities) | |
{ | |
if (entity.TypeName == CadEntityTypeName.TEXT) | |
{ | |
((CadText)entity).DefaultValue = "New text here!!! :)"; | |
break; | |
} | |
} | |
cadImage.Save(file.FullName + "_text.dxf"); | |
} | |
} | |
Esportazione di un Livello Specifico dei Disegni DXF in Immagine
Questo approccio funziona come segue:
- Apri un file di disegno DXF utilizzando il metodo di fabbrica Image.Load.
- Crea un’istanza di CadRasterizationOptions e specifica le proprietà PageWidth e PageHeight.
- Aggiungi livelli all’oggetto di CadRasterizationOptions.
- Crea un’istanza di JpegOptions e imposta la sua proprietà VectorRasterizationOptions.
- Esporta il disegno in PDF utilizzando il metodo Image.Save.
Il campione di codice sottostante mostra come convertire un livello specifico di DXF in Immagine.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DXFDrawings(); | |
string sourceFilePath = MyDir + "for_layers_test.dwf"; | |
using (var image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of CadRasterizationOptions | |
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
// Set image width & height | |
rasterizationOptions.PageWidth = 500; | |
rasterizationOptions.PageHeight = 500; | |
// Set the drawing to render at the center of image | |
// rasterizationOptions.CenterDrawing = true; | |
// Get the layers in an instance of CadLayersDictionary | |
var layersList = image.Layers; | |
// Iterate over the layers | |
foreach (var layerName in layersList.GetLayersNames()) | |
{ | |
// Display layer name for tracking | |
Console.WriteLine("Start with " + layerName); | |
// Add the layer name to the CadRasterizationOptions's layer list | |
rasterizationOptions.Layers = new string[] { "LayerA" }; | |
// Create an instance of JpegOptions (or any ImageOptions for raster formats) | |
var options = new Aspose.CAD.ImageOptions.JpegOptions(); | |
// Set VectorRasterizationOptions property to the instance of CadRasterizationOptions | |
options.VectorRasterizationOptions = rasterizationOptions; | |
//Export each layer to Jpeg format | |
image.Save(layerName + "_out.jpg", options); | |
} | |
} |