
Hi guys! I am back with all new blog to give you a walk through of latest Aspose.CAD for .NET/Java 19.7. As a standard practice, Aspose team publishes both .NET and Java based API having same features sets simultaneously. I will be giving you overview of what new features have been included in API along with example code to use them.
Loading Large DWG Files in C#
Aspose.CAD for .NET provides facility to open very large DWG files using CadImage class. Now you can easily open large files with the help of sample example given below.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DWGDrawings(); | |
string filePathDWG = MyDir + "TestBigFile.dwg"; | |
string filePathFinish = MyDir+ "TestBigFile.dwg.pdf"; | |
Stopwatch stopWatch = new Stopwatch(); | |
try | |
{ | |
stopWatch.Start(); | |
using (CadImage cadImage = (CadImage)Image.Load(filePathDWG)) | |
{ | |
stopWatch.Stop(); | |
// Get the elapsed time as a TimeSpan value. | |
TimeSpan ts = stopWatch.Elapsed; | |
// Format and display the TimeSpan value. | |
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", | |
ts.Hours, ts.Minutes, ts.Seconds, | |
ts.Milliseconds / 10); | |
Console.WriteLine("RunTime for loading " + elapsedTime); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
stopWatch = new Stopwatch(); | |
stopWatch.Start(); | |
cadImage.Save(filePathFinish, pdfOptions); | |
stopWatch.Stop(); | |
// Get the elapsed time as a TimeSpan value. | |
ts = stopWatch.Elapsed; | |
// Format and display the TimeSpan value. | |
elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", | |
ts.Hours, ts.Minutes, ts.Seconds, | |
ts.Milliseconds / 10); | |
Console.WriteLine("RunTime for converting " + elapsedTime); | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
Set Custom Point of View for Rendering in C# and Java
Aspose.CAD allows you to set custom point of view for Model layout. Using VectorRasterizationOptions you can set custom point of view. The following example shows how to set custom point of view.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_ConvertingCAD(); | |
string sourceFilePath = MyDir + "conic_pyramid.dxf"; | |
var outPath = Path.Combine(MyDir, "FreePointOfView_out.jpg"); | |
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath)) | |
{ | |
JpegOptions options = new JpegOptions | |
{ | |
VectorRasterizationOptions = new CadRasterizationOptions | |
{ | |
PageWidth = 1500, PageHeight = 1500 | |
} | |
}; | |
float xAngle = 10; //Angle of rotation along the X axis | |
float yAngle = 30; //Angle of rotation along the Y axis | |
float zAngle = 40; //Angle of rotation along the Z axis | |
((CadRasterizationOptions)(options.VectorRasterizationOptions)).ObserverPoint = new ObserverPoint(xAngle, yAngle, zAngle); | |
cadImage.Save(outPath, options); | |
} | |
The equivalent Java implementation for this is as under.
String dataDir = Utils.getDataDir(FreePointOfView.class) + "CADConversion/"; | |
// Path to source file | |
String sourceFilePath = dataDir+"conic_pyramid.dxf"; | |
// Load a CAD drawing in an instance of Image | |
com.aspose.cad.Image objImage = com.aspose.cad.Image.load(sourceFilePath); | |
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions(); | |
cadRasterizationOptions.setPageHeight(1500); | |
cadRasterizationOptions.setPageWidth(1500); | |
// Create an instance of JpegOptions class | |
com.aspose.cad.imageoptions.JpegOptions options = new com.aspose.cad.imageoptions.JpegOptions(); | |
options.setVectorRasterizationOptions(cadRasterizationOptions); | |
float xAngle = 10; //Angle of rotation along the X axis | |
float yAngle = 30; //Angle of rotation along the Y axis | |
float zAngle = 40; //Angle of rotation along the Z axis | |
ObserverPoint obvPoint = new ObserverPoint(xAngle,yAngle,zAngle); | |
cadRasterizationOptions.setObserverPoint(obvPoint); | |
options.setVectorRasterizationOptions(cadRasterizationOptions); | |
//Saving to Image | |
objImage.save(dataDir+"FreePointOfView_out.jpeg", options); |
You can check the official product release notes for many other issues and enhancement carried out in product as well. Here you can get the detail!
When time allows you can check out API examples at Github, talk about this release and other API related issues in our forum.