Is there any way to make separate Model with layouts in a dwg file and save every layout separately in a different file. I am currently using Aspose.cad for dotnet. Is there is any other product that can help me do this ?
To save each layout from a DWG file as a separate file using Aspose.CAD for .NET, you can follow these steps:
- Load the DWG File: Use the
Image.Load
method to load your DWG file into aCadImage
object. - List Layouts: Retrieve the layouts from the
CadImage
object. - Export Each Layout: For each layout, create a
CadRasterizationOptions
object, set the layout to be exported, and then save it to a desired format (e.g., PDF, JPEG).
Here is a sample code snippet demonstrating this process:
using System;
using System.Collections.Generic;
using System.IO;
using Aspose.CAD;
using Aspose.CAD.FileFormats.Cad;
using Aspose.CAD.ImageOptions;
namespace Aspose.CAD.Examples
{
public class ExportLayouts
{
public static void Run()
{
// Path to the DWG file
string sourceFilePath = "path/to/your/file.dwg";
string outputDirectory = "path/to/output/directory/";
// Load the DWG file
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
// Iterate through each layout
foreach (var layout in cadImage.Layouts.Values)
{
// Create rasterization options
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions
{
Layouts = new string[] { layout.LayoutName },
PageWidth = 1600,
PageHeight = 1600
};
// Create PDF options
PdfOptions pdfOptions = new PdfOptions
{
VectorRasterizationOptions = rasterizationOptions
};
// Save each layout as a separate PDF file
string outputFilePath = Path.Combine(outputDirectory, $"{layout.LayoutName}.pdf");
cadImage.Save(outputFilePath, pdfOptions);
}
}
}
}
}
Explanation:
- The code loads a DWG file and retrieves all layouts.
- For each layout, it sets up the rasterization options and saves the layout as a PDF file in the specified output directory.
- You can adjust the
PageWidth
andPageHeight
properties as needed for your output files.
This approach allows you to create separate files for each layout in your DWG drawing. If you need to save in formats other than PDF, you can modify the PdfOptions
to use other image options like JpegOptions
or PngOptions
as required.
For more detailed information, you can refer to the Aspose.CAD documentation here.
If you are looking for alternative products, Aspose.CAD is specifically designed for handling CAD files, and it provides comprehensive support for various CAD formats. Other products may not offer the same level of functionality for CAD file manipulation.
Sources:
I dont want the image. i want the details of the entities of each layout.
@Asheesh32,
please provide some example of the input file and desired output file, so we can understand the requirement better.