Adjusting CAD Drawing Size
Adjusting CAD drawing size
Aspose.CAD for .NET provides the UnitType enumeration to adjust the size of the drawing during the conversion of the CAD format. There are two ways to adjust the drawing size.
- Automatic size adjustment.
- Adjust size by using the UnitType enumeration of the Aspose.CAD.ImageOptions class
For automatically adjusting the size, developers do not need to provide the Width and Height properties of the CadRasterizationOptions class. Below provided code snippet is an example of automatic sizing.
// 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_ConvertingCAD(); | |
string sourceFilePath = MyDir + "sample.dwg"; | |
// Load a CAD drawing in an instance of Image | |
using (var image = Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of BmpOptions class | |
Aspose.CAD.ImageOptions.BmpOptions bmpOptions = new Aspose.CAD.ImageOptions.BmpOptions(); | |
// Create an instance of CadRasterizationOptions and set its various properties | |
Aspose.CAD.ImageOptions.CadRasterizationOptions cadRasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
bmpOptions.VectorRasterizationOptions = cadRasterizationOptions; | |
// Set the UnitType property | |
cadRasterizationOptions.UnitType = Aspose.CAD.ImageOptions.UnitType.Centimenter; | |
// Set the layouts property | |
cadRasterizationOptions.Layouts = new string[] { "Model" }; | |
// Export layout to BMP format | |
string outPath = sourceFilePath + ".bmp"; | |
image.Save(outPath, bmpOptions); | |
} |
The UnitType enumeration gives the ability to adjust scaling when Width and Height properties are not set. Below provided code snippet demonstrate how to use UnitType.
// 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_ConvertingCAD(); | |
string sourceFilePath = MyDir + "sample.dwg"; | |
// Load a CAD drawing in an instance of Image | |
using (var image = Aspose.CAD.Image.Load(sourceFilePath)) | |
{ | |
// Create an instance of BmpOptions class | |
Aspose.CAD.ImageOptions.BmpOptions bmpOptions = new Aspose.CAD.ImageOptions.BmpOptions(); | |
// Create an instance of CadRasterizationOptions and set its various properties | |
Aspose.CAD.ImageOptions.CadRasterizationOptions cadRasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); | |
bmpOptions.VectorRasterizationOptions = cadRasterizationOptions; | |
// Set the UnitType property | |
cadRasterizationOptions.UnitType = Aspose.CAD.ImageOptions.UnitType.Centimenter; | |
// Set the layouts property | |
cadRasterizationOptions.Layouts = new string[] { "Model" }; | |
// Export layout to BMP format | |
string outPath = sourceFilePath + ".bmp"; | |
image.Save(outPath, bmpOptions); | |
} |