Dibujos DXF
Exportando Dibujos DXF a PDF
Aspose.CAD proporciona la función de cargar las entidades de dibujo DXF de AutoCAD y renderizarlas como un dibujo completo en formato PDF. El enfoque de conversión de DXF a PDF funciona de la siguiente manera:
- Cargar el archivo de dibujo DXF utilizando el método de fábrica Image.Load.
- Crear un objeto de la clase CadRasterizationOptions y establecer las propiedades PageHeight y PageWidth.
- Crear un objeto de la clase PdfOptions y establecer la propiedad VectorRasterizationOptions.
- Llamar a Image.Save pasando un objeto de PdfOptions como segundo parámetro.
El siguiente ejemplo de código muestra cómo convertir un archivo utilizando la configuración predeterminada.
// 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); | |
} |
Formatos Soportados
En este momento, soportamos completamente los formatos de archivo DXF de AutoCAD 2010. Las versiones anteriores de DXF no tienen garantía de ser 100% válidas. Planeamos incluir más formatos y características en futuras versiones de Aspose.CAD.
Entidades Soportadas
En este momento, soportamos todas las entidades 2D ampliamente utilizadas y sus parámetros básicos predeterminados de la siguiente manera:
- Dimensión Alineada
- Dimensión Angular
- Arco
- Atributo
- Referencia de Bloque
- Círculo
- Dimensión de Diámetro
- Elipse
- Hatch
- Línea
- Texto Multilínea
- Dimensión Ordinada
- Punto
- Polilínea
- Dimensión Radial
- Rayo
- Dimensión Rotada
- Tabla
- Texto
- Xline
Gestión de Memoria
La propiedad ExactReallocateOnly de la clase Cache se puede utilizar para controlar la reubicación de memoria. La reubicación es más probable que ocurra para cachés pre-asignados. Puede ocurrir cuando el sistema determina que el espacio asignado no será suficiente.
- Si ExactReallocateOnly está establecido en el valor predeterminado, False, el espacio se reubica en el mismo medio.
- Cuando se establece en True, la reubicación no puede exceder el espacio máximo especificado. En este caso, la caché en memoria existente (que requiere reubicación) se libera y se asigna espacio extendido en disco.
Exportando una Capa Específica de Dibujos DXF a PDF
Este enfoque funciona de la siguiente manera:
- Abrir un archivo de dibujo DXF utilizando el método de fábrica Image.Load.
- Crear una instancia de CadRasterizationOptions y especificar las propiedades PageWidth y PageHeight.
- Agregar capas al objeto de CadRasterizationOptions.
- Crear una instancia de PdfOptions y establecer su propiedad VectorRasterizationOptions.
- Llamar al método Image.Save y pasar el objeto de PdfOptions como segundo parámetro.
El siguiente ejemplo de código muestra cómo convertir una capa específica de DXF a 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); | |
} |
Renderizar archivos PDF como parte de dibujos DXF
Este enfoque funciona de la siguiente manera:
- Cargar el archivo de dibujo DXF utilizando el método de fábrica Image.Load.
- Crear un objeto de la clase CadRasterizationOptions y cargar archivos PDF.
- Establecer las propiedades PageHeight y PageWidth.
- Llamar a Image.Save y guardar el archivo.
El siguiente ejemplo de código muestra cómo renderizar archivos PDF como parte de dibujos 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); | |
} |
Exportar la superposición DGN incrustada para el formato DXF
Aspose.CAD proporciona la función de cargar archivos DXF de AutoCAD y exportar la superposición DGN incrustada para el formato DXF.
El siguiente ejemplo de código muestra cómo lograr los requisitos especificados.
// 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); | |
} |
Soporte para Guardar Archivos DXF
Aspose.CAD proporciona la función de cargar archivos DXF de AutoCAD, realizar cambios en ellos y guardarlos nuevamente como un archivo DXF.
El siguiente ejemplo de código muestra cómo lograr los requisitos especificados.
// 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"); | |
} | |
Exportar DXF a WMF
Este enfoque funciona de la siguiente manera:
- Cargar el archivo de dibujo DXF utilizando el método de fábrica Image.Load.
- Crear un objeto de la clase CadRasterizationOptions y cargar archivos PDF.
- Establecer las propiedades PageHeight y PageWidth.
- Llamar a Image.Save y guardar el archivo.
// 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); | |
} |
Exportando un Layout DXF Específico a PDF
Este enfoque funciona de la siguiente manera:
- Abrir un archivo de dibujo DXF utilizando el método de fábrica Image.Load.
- Crear una instancia de CadRasterizationOptions y especificar las propiedades PageWidth y PageHeight.
- Especificar el nombre(s) de layout deseado(s) utilizando la propiedad CadRasterizationOptions.Layouts.
- Crear una instancia de PdfOptions y establecer su propiedad VectorRasterizationOptions.
- Exportar el dibujo a PDF llamando al método Image.Save y pasando el objeto de PdfOptions como segundo parámetro.
El siguiente ejemplo de código muestra cómo convertir un layout específico de DXF a 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); | |
} |
Soporte para Recorte de Bloques
Aspose.CAD proporciona la función de Recorte de Bloques. El enfoque de Recorte de Bloques funciona de la siguiente manera:
- Cargar el archivo de dibujo DXF utilizando el método de fábrica Image.Load.
- Crear un objeto de la clase CadRasterizationOptions y cargar archivos PDF.
- Establecer las propiedades deseadas de CadRasterizationOptions.
- Llamar a Image.Save pasando un objeto de PdfOptions como segundo parámetro y guardar el archivo.
El siguiente ejemplo de código muestra cómo funciona el Recorte de Bloques.
// 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); |
Exportar Imágenes a DXF
Usando Aspose.CAD, puedes exportar imágenes a formato DXF. Usando este enfoque, puedes realizar las siguientes acciones:
- Establecer una nueva fuente
- Ocultar entidades
- Actualizar texto
El siguiente fragmento de código te muestra cómo realizar las acciones enumeradas anteriormente.
// 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"); | |
} | |
} | |
Exportando una Capa Específica de Dibujos DXF a Imagen
Este enfoque funciona de la siguiente manera:
- Abrir un archivo de dibujo DXF utilizando el método de fábrica Image.Load.
- Crear una instancia de CadRasterizationOptions y especificar las propiedades PageWidth y PageHeight.
- Agregar capas al objeto de CadRasterizationOptions.
- Crear una instancia de JpegOptions y establecer su propiedad VectorRasterizationOptions.
- Exportar el dibujo a PDF utilizando el método Image.Save.
El siguiente ejemplo de código muestra cómo convertir una capa específica de DXF a Imagen.
// 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); | |
} | |
} |