Muhammad Ijaz May 26, 2016one Comment

Work with CAD formats including DWG and DXF using Aspose.CAD for .NET

Work with CAD formats including DWG and DXF using Aspose.CAD for .NET

May 26, 2016
Share on FacebookTweet about this on TwitterShare on LinkedIn

We are pleased to announce the release of Aspose.CAD for .NET 1.0.0. This is a new addition to Aspose APIs and allows you to work with CAD formats including DWG and DXF formats. Aspose.Imaging also supports CAD formats but these formats will be removed from Aspose.Imaging in next three months and all features related to CAD formats will be the part of Aspose.CAD only.

This release of Aspose.CAD for .NET supports converting DWG and DXF formats to PDF and raster image formats. Converting CAD layers and layouts to PDF and raster image formats has also been supported by this release. You can also remove entities from DWG and DXF documents.

Convert CAD formats to PDF

Aspose.CAD for .NET allows you to convert CAD drawings to PDF format. Aspose.CAD.Image.Load method can be used to load CAD drawings, Aspose.CAD.ImageOptions.CadRasterizationOptions can be used to set vector rasterization options, Aspose.CAD.ImageOptions.PdfOptions can be used to set PDF options and Aspose.CAD.Image.Save method can be used to save output PDF e.g.


string MyDir = RunExamples.GetDataDir_DWGDrawings(); 
 string sourceFilePath = MyDir + "Bottom_plate.dwg"; 
 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 + "Bottom_plate_out_.pdf"; 
     // Export the DWG to PDF 
     image.Save(MyDir, pdfOptions);                 
 } 

Convert CAD formats to raster image formats

Aspose.CAD for .NET allows you to convert CAD drawings to raster image formats. Aspose.CAD.Image.Load method can be used to load CAD drawings, Aspose.CAD.ImageOptions.CadRasterizationOptions can be used to set vector rasterization options, Aspose.CAD. ImageOptionsBase can be used to set image options and Aspose.CAD.Image.Save method can be used to save output image e.g.


string MyDir = RunExamples.GetDataDir_ConvertingCAD(); 
 string sourceFilePath = MyDir + "conic_pyramid.dxf"; 
 using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath)) 
 { 
     // Create an instance of CadRasterizationOptions 
     Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); 
     // Set page width & height 
     rasterizationOptions.PageWidth = 1200; 
     rasterizationOptions.PageHeight = 1200; 
  
     // Create an instance of PngOptions for the resultant image 
     ImageOptionsBase options = new Aspose.CAD.ImageOptions.PngOptions(); 
     //Set rasterization options 
     options.VectorRasterizationOptions = rasterizationOptions; 
  
     MyDir = MyDir + "conic_pyramid_raster_image_out_.png"; 
     // Save resultant image 
     image.Save(MyDir, options);                 
 } 

Remove entities from CAD documents

Aspose.CAD for .NET allows you to remove specific entities from CAD drawings. Aspose.CAD.Image.Load method can be used to load CAD drawings, Aspose.CAD.FileFormats.Cad.CadImage.Entities can be used to loop through each entity and Aspose.CAD.FileFormats.Cad.CadImage.RemoveEntity can be used to remove any entity e.g.


using (CadImage cadImage = (CadImage)Image.Load(fileName))
{
    for (int i = 0; i < cadImage.Entities.Length; i++)
    {
        CadBaseEntity baseEntity = cadImage.Entities[i];
        if (baseEntity.GetType() == typeof(CadArc))
        {
            CadArc arc = (CadArc)baseEntity;
            if (arc.CenterPoint.X > 1e10)
            {
                // cadImage.RemoveEntityAt(i);
                cadImage.RemoveEntity(baseEntity);
                i--;
            }
        }
    }

    cadImage.UpdateSize();

    CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
    rasterizationOptions.BackgroundColor = Color.White;
    rasterizationOptions.Layouts = new string[] { "Model" };

    rasterizationOptions.PageWidth = 1600;
    rasterizationOptions.PageHeight = 1600;
    rasterizationOptions.CenterDrawing = true;
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.VectorRasterizationOptions = rasterizationOptions;

    cadImage.Save(outPath, pdfOptions);
}

Other Important Features

Following is a list of some important features included in this release.

To view a complete list of new features and to download the latest release, please visit Aspose.CAD for .NET 1.0.0 page in downloads section.

Aspose.CAD for .NET Resources

The resources, you may need to accomplish your tasks:

Join the Conversation

1 Comment

Leave a comment

Posted inAspose.CAD Product Family
 

Related Articles