Ikram ul Haq August 15, 20165 Comments

Search text in DWG file, get external references and export DGN to PDF & raster formats using Aspose.CAD for .Net 1.1.0

Search text in DWG file, get external references and export DGN to PDF & raster formats using Aspose.CAD for .Net 1.1.0

August 15, 2016
Share on FacebookTweet about this on TwitterShare on LinkedIn

We are pleased to announce the release of Aspose.CAD for .NET 1.1.0. The major developments in this release are support for searching text in DWG AutoCAD file and get external references of block attributes. Support to convert DGN AutoCAD format to PDF and convert DGN AutoCAD format to raster image format have also been incorporated in this release.

Support For Searching Text In DWG AutoCAD File

Aspose.CAD for .Net now supports searching text in DWG file. Aspose.CAD API exposes CadText class that represents text entities in the DWG AutoCAD file. Below provided sample code demonstrate how to search text in DWG file.



// Load an existing DWG file as CadImage.
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load("sample.dwg"))
{
// search for text in the file 
foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadBaseEntity entity in cadImage.Entities)
{
    // please, note: we iterate through CadText entities here, but some other entities
    // may contain text also, e.g. CadMText and others
    if (entity.GetType() == typeof(Aspose.CAD.FileFormats.Cad.CadObjects.CadText))
    {
        Aspose.CAD.FileFormats.Cad.CadObjects.CadText text = (Aspose.CAD.FileFormats.Cad.CadObjects.CadText)entity;
        System.Console.WriteLine(text.DefaultValue);
    }
}

// search for text on specific layout
// get all layout names and link each layout with corresponding block with entities
Aspose.CAD.FileFormats.Cad.CadLayoutDictionary layouts = cadImage.Layouts;
string[] layoutNames = new string[layouts.Count];
int i = 0;
foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadLayout layout in layouts.Values)
{
    layoutNames[i++] = layout.LayoutName;
    System.Console.WriteLine("Layout " + layout.LayoutName + " is found");

    // find block, applicable for DWG only
    Aspose.CAD.FileFormats.Cad.CadTables.CadBlockTableObject blockTableObjectReference = null;
    foreach (Aspose.CAD.FileFormats.Cad.CadTables.CadBlockTableObject tableObject in cadImage.BlocksTables)
    {
        if (string.Equals(tableObject.HardPointerToLayout, layout.ObjectHandle))
        {
            blockTableObjectReference = tableObject;
            break;
        }
    }

    // Collection cadBlockEntity.Entities contains information about all entities on specific layout
    // if this collection has no elements it means layout is a copy of Model layout and contains the same entities
    Aspose.CAD.FileFormats.Cad.CadObjects.CadBlockEntity cadBlockEntity = cadImage.BlockEntities[blockTableObjectReference.BlockName];
}

// export to pdf
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
rasterizationOptions.AutomaticLayoutsScaling = true;
rasterizationOptions.CenterDrawing = true;

// please, note: if cadBlockEntity collection mentioned above (for dwg) for selected layout or
// entitiesOnLayouts collection by layout's BlockTableRecordHandle (for dxf) is empty
// - export result file will be empty and you should draw Model layout instead
rasterizationOptions.Layouts = new[] { "Layout1" };

Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();

pdfOptions.VectorRasterizationOptions = rasterizationOptions;
cadImage.Save("sample_dwg_out.pdf", pdfOptions);
}

Support For Get Block Attribute Value Of External Reference

Aspose.CAD for .NET allows you to get block attribute value of external reference. Aspose.CAD for .Net now supports searching text in DWG file. Aspose.CAD API exposes XRefPathName property to get the external reference of a block attribute in a CadBlockDictionary collection. Below provided sample code demonstrate how to get block attribute value.


// Load an existing DWG file as CadImage.
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load("sample.dwg"))
{
    // Declare a boolean variable. 
    bool isExternalReferenceFoundCorrectly = false;

    // Access the block attribute value using property XRefPathName it will return a string. 
    // Now compare it. If both strings matched the set the boolean values to true that external reference found correctly.
    if (cadImage.BlockEntities["Drawing1"].XRefPathName == @".\Drawing1.dwg")
    {
        isExternalReferenceFoundCorrectly = true;
    }

    System.Console.WriteLine(image.BlockEntities["Drawing1"].XRefPathName);
}

Convert DGN AutoCAD Format To PDF

Aspose.CAD for .NET allows you to convert DGN AutoCAD format to PDF. Aspose.CAD.Image.Load method can be used to load DGN file, 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.


// load an existing DGN file as CadImage.
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load("Nikon_D90_Camera.dgn"))
{
    // Create an object of CadRasterizationOptions class and define/set different properties
    Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
    rasterizationOptions.PageWidth = 600;
    rasterizationOptions.PageHeight = 300;
    rasterizationOptions.CenterDrawing = true;
    rasterizationOptions.ScaleMethod = Aspose.CAD.FileFormats.Cad.ScaleType.None;
    rasterizationOptions.AutomaticLayoutsScaling = true;

    // Create an object of PdfOptions class as we are converting the image to PDF format and assign CadRasterizationOptions object to it.
    Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
    pdfOptions.VectorRasterizationOptions = rasterizationOptions;

    // Call the save method of the CadImage class object.
    cadImage.Save("Nikon_D90_Camera.pdf", pdfOptions);
}

Convert DGN AutoCAD Format To Raster Image Formats

Aspose.CAD for .NET allows you to convert DGN AutoCAD format to raster images. Aspose.CAD.Image.Load method can be used to load DGN file, 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.



// load an existing DGN file as CadImage.
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load("Nikon_D90_Camera.dgn"))
{
    // Create an object of DgnRasterizationOptions class and define/set different properties
    Aspose.CAD.ImageOptions.DgnRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.DgnRasterizationOptions();
    rasterizationOptions.PageWidth = 600;
    rasterizationOptions.PageHeight = 300;
    rasterizationOptions.CenterDrawing = true;
    rasterizationOptions.ScaleMethod = Aspose.CAD.FileFormats.Cad.ScaleType.None;
    rasterizationOptions.AutomaticLayoutsScaling = true;

    // 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("Nikon_D90_Camera.pdf", options);
}

Other Important Features

Following enhancements have been introduced in this release.

  • EULA link has been introduced in MSI file.

  • Memory management process while exporting CAD to BMP has been improved.

  • Process of accessing Face3D objects has been improved.

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

Aspose.CAD for .NET Resources

The resources, you may need to accomplish your tasks:

Join the Conversation

5 Comments

Leave a comment

Posted inAspose.CAD Product Family
 

Related Articles