Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aspose.CAD for .NET
// load CF2 in an instance of Image via its Load method
using (var image = Aspose.CAD.Image.Load("template.cf2"))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// create an instance of TiffOptions
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export CF2 to TIFF
image.Save("output.tiff", options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
// load DGN in an instance of Image via its Load method
using (var image = Aspose.CAD.Image.Load("template.dgn"))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// create an instance of TiffOptions
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export DGN to TIFF
image.Save("output.tiff", options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".tiff";
// load DWF file in an instance of Image
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load("template.dwf"))
{
// create an instance of CadRasterizationOptions
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1200;
rasterizationOptions.PageHeight = 1200;
// create an instance of TiffOptions for the resultant image
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set VectorRasterizationOptions property
options.VectorRasterizationOptions = rasterizationOptions;
// save DWF as TIFF image
image.Save(output, options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
// load DWFX in an instance of Image via its Load method
using (var image = Aspose.CAD.Image.Load("template.dwfx"))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// create an instance of TiffOptions
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export DWFX to TIFF
image.Save("output.tiff", options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".tiff";
// load DWG file in an instance of Image
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load("template.dwg"))
{
// create an instance of CadRasterizationOptions
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1200;
rasterizationOptions.PageHeight = 1200;
// create an instance of TiffOptions for the resultant image
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set VectorRasterizationOptions property
options.VectorRasterizationOptions = rasterizationOptions;
// save DWG as TIFF image
image.Save(output, options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
// load DWT in an instance of Image via its Load method
using (var image = Aspose.CAD.Image.Load("template.dwt"))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// create an instance of TiffOptions
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export DWT to TIFF
image.Save("output.tiff", options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".tiff";
// load DXF file in an instance of Image
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load("template.dxf"))
{
// create an instance of CadRasterizationOptions
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1200;
rasterizationOptions.PageHeight = 1200;
// create an instance of TiffOptions for the resultant image
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set VectorRasterizationOptions property
options.VectorRasterizationOptions = rasterizationOptions;
// save DXF as TIFF image
image.Save(output, options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
// load FBX in an instance of Image via its Load method
using (var image = Aspose.CAD.Image.Load("template.fbx"))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// create an instance of TiffOptions
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export FBX to TIFF
image.Save("output.tiff", options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".tiff";
// load IFC file in an instance of Image
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load("template.ifc"))
{
// create an instance of CadRasterizationOptions
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1200;
rasterizationOptions.PageHeight = 1200;
// create an instance of TiffOptions for the resultant image
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set VectorRasterizationOptions property
options.VectorRasterizationOptions = rasterizationOptions;
// save IFC as TIFF image
image.Save(output, options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
// load IGEC in an instance of Image via its Load method
using (var image = Aspose.CAD.Image.Load("template.iges"))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// create an instance of TiffOptions
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export IGES to TIFF
image.Save("output.tiff", options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
// load OBJ in an instance of Image via its Load method
using (var image = Aspose.CAD.Image.Load("template.obj"))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// create an instance of TiffOptions
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export OBJ to TIFF
image.Save("output.tiff", options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
// load PLT in an instance of Image via its Load method
using (var image = Aspose.CAD.Image.Load("template.plt"))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// create an instance of TiffOptions
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export PLT to TIFF
image.Save("output.tiff", options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".tiff";
// load STL file in an instance of Image
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load("template.stl"))
{
// create an instance of CadRasterizationOptions
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1200;
rasterizationOptions.PageHeight = 1200;
// create an instance of TiffOptions for the resultant image
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set VectorRasterizationOptions property
options.VectorRasterizationOptions = rasterizationOptions;
// save STL as TIFF image
image.Save(output, options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
// load SVG in an instance of Image via its Load method
using (var image = Aspose.CAD.Image.Load("template.svg"))
{
// create an instance of CadRasterizationOptions and set page height & width
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// create an instance of TiffOptions
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// export SVG to TIFF
image.Save("output.tiff", options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".tiff";
// load DGN file in an instance of Image
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load("template.dgn"))
{
// create an instance of CadRasterizationOptions
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1200;
rasterizationOptions.PageHeight = 1200;
// create an instance of TiffOptions for the resultant image
var options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// set VectorRasterizationOptions property
options.VectorRasterizationOptions = rasterizationOptions;
// save DGN as TIFF image
image.Save(output, options);
}
// load resultant TIFF image in default application
System.Diagnostics.Process.Start();

// This Gist contains examples of Aspose.CAD for .NET

Gist for Aspose.CAD for .NET
// Set path of the license file, i.e. c:\temp\
string dataDir = @"c:\temp\";
License license = new License();
license.SetLicense(dataDir + "Aspose.CAD.lic");
// Set path of the license file, i.e. c:\temp\
string dataDir = @"c:\temp\";
// Load an existing file in the stream
FileStream LicStream = new FileStream(dataDir + "Aspose.CAD.lic", FileMode.Open);
License license = new License();
license.SetLicense(LicStream);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-.NET
// Access the setMeteredKey property and pass public and private keys as parameters
Aspose.CAD.Metered.SetMeteredKey("PublicKey", "PrivateKey");
// Get metered data amount before calling API
decimal amountbefore = Aspose.CAD.Metered.GetConsumptionQuantity();
// Display information
Console.WriteLine("Amount Consumed Before: " + amountbefore.ToString());
// Do processing
//Aspose.CAD.FileFormats.Cad.CadImage image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.load("BlockRefDgn.dwg");
// Get metered data amount After calling API
decimal amountafter = Aspose.CAD.Metered.GetConsumptionQuantity();
// Display information
Console.WriteLine("Amount Consumed After: " + amountafter.ToString());
// Access the setMeteredKey property and pass public and private keys as parameters
Aspose.CAD.Metered.SetMeteredKey("PublicKey", "PrivateKey");
// Get metered data amount before calling API
decimal amountbefore = Aspose.CAD.Metered.GetConsumptionQuantity();
// Display information
Console.WriteLine("Amount Consumed Before: " + amountbefore.ToString());
// Do processing
//Aspose.CAD.FileFormats.Cad.CadImage image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.load("BlockRefDgn.dwg");
// Get metered data amount After calling API
decimal amountafter = Aspose.CAD.Metered.GetConsumptionQuantity();
// Display information
Console.WriteLine("Amount Consumed After: " + amountafter.ToString());
// 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;
cadRasterizationOptions.CenterDrawing = true;
// 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);
}
// 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;
cadRasterizationOptions.CenterDrawing = true;
// Set the layouts property
cadRasterizationOptions.Layouts = new string[] { "Model" };
//Export layout to BMP format
string outPath = sourceFilePath + ".bmp";
image.Save(outPath, bmpOptions);
}
// 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;
cadRasterizationOptions.CenterDrawing = true;
// 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);
}
// 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;
cadRasterizationOptions.CenterDrawing = true;
// 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 path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of Image
using (var image = Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an instance of CadRasterizationOptions
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
// Set image width & height
rasterizationOptions.PageWidth = 500;
rasterizationOptions.PageHeight = 500;
// Set the drawing to render at the center of image
//rasterizationOptions.CenterDrawing = true;
// Add the layer name to the CadRasterizationOptions's layer list
rasterizationOptions.Layers= new string[] { "LayerA" };
// Create an instance of JpegOptions (or any ImageOptions for raster formats)
var options = new Aspose.CAD.ImageOptions.JpegOptions();
// Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
//Export each layer to Jpeg format
MyDir = MyDir + "CADLayersToRasterImageFormats_out.jpg";
image.Save(MyDir, options);
}
Console.WriteLine("\nCAD layers converted successfully to raster image format.\nFile saved at " + MyDir);
}
public static void ConvertAllLayersToRasterImageFormats()
{
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
using (var image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an instance of CadRasterizationOptions
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
// Set image width & height
rasterizationOptions.PageWidth = 500;
rasterizationOptions.PageHeight = 500;
// Set the drawing to render at the center of image
// rasterizationOptions.CenterDrawing = true;
// Get the layers in an instance of CadLayersDictionary
var layersList = image.Layers;
// Iterate over the layers
foreach (var layerName in layersList.GetLayersNames())
{
// Display layer name for tracking
Console.WriteLine("Start with " + layerName);
// Add the layer name to the CadRasterizationOptions's layer list
rasterizationOptions.Layers = new string[] { "LayerA" };
// Create an instance of JpegOptions (or any ImageOptions for raster formats)
var options = new Aspose.CAD.ImageOptions.JpegOptions();
// Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
//Export each layer to Jpeg format
image.Save(layerName + "_out.jpg", options);
}
}
Console.WriteLine("\nCAD all layers converted successfully to raster image format.");
// 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 + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
using (var image = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an instance of CadRasterizationOptions
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
// Set image width & height
rasterizationOptions.PageWidth = 500;
rasterizationOptions.PageHeight = 500;
// Set the drawing to render at the center of image
rasterizationOptions.CenterDrawing = true;
// Get the layers in an instance of CadLayersDictionary
var layersList = image.Layers;
// Iterate over the layers
foreach (var layerName in layersList.GetLayersNames())
{
// Display layer name for tracking
Console.WriteLine("Start with " + layerName);
// Add the layer name to the CadRasterizationOptions's layer list
rasterizationOptions.Layers.Add(layerName);
// Create an instance of JpegOptions (or any ImageOptions for raster formats)
var options = new Aspose.CAD.ImageOptions.JpegOptions();
// Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
//Export each layer to Jpeg format
image.Save(layerName + "_out.jpg", options);
}
}
// The path to the documents directory.
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);
}
// The path to the documents directory.
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;
// Specify a list of layout names
rasterizationOptions.Layouts = new string[] { "Model", "Layout1" };
// Create an instance of TiffOptions for the resultant image
ImageOptionsBase options = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// Set rasterization options
options.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "conic_pyramid_layoutstorasterimage_out.tiff";
// Save resultant image
image.Save(MyDir, options);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath))
{
MemoryStream stream = new MemoryStream();
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Create an instance of CadRasterizationOptions and set its various properties
Aspose.CAD.ImageOptions.CadRasterizationOptions cadRasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
pdfOptions.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.PageWidth = 800;
cadRasterizationOptions.PageHeight = 600;
image.Save(stream, pdfOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string[] sourceFilePaths = new[]
{
MyDir + "conic_pyramid.dxf",
MyDir + "Bottom_plate.dwg"
};
foreach (var sourceFilePath in sourceFilePaths)
{
string extension = Path.GetExtension(sourceFilePath);
using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
List<string> layouts = GetNotEmptyLayouts(cadImage, extension);
const double Epsilon = 0.00001;
foreach (string layout in layouts)
{
System.Console.WriteLine("Layout= " + layout);
using (FileStream fs = new FileStream(MyDir + "layout_" + extension + "_" + layout + ".jpg", FileMode.Create))
{
JpegOptions jpegOptions = new JpegOptions();
CadRasterizationOptions options = new CadRasterizationOptions();
options.Layouts = new string[] { layout };
CadLayout l = cadImage.Layouts[layout];
if ((Math.Abs(l.MaxExtents.Y) < Epsilon && Math.Abs(l.MaxExtents.X) < Epsilon)
|| (Math.Abs(l.MaxExtents.Y + 1E+20) < Epsilon
|| Math.Abs(l.MaxExtents.X + 1E+20) < Epsilon)
|| (Math.Abs(l.MinExtents.Y - 1E+20) < Epsilon
|| Math.Abs(l.MinExtents.X - 1E+20) < Epsilon))
{
// do nothing, we can automatically detect size
// we can not rely on PlotPaperUnits here too because it is PlotInInches by default
}
else
{
double sizeExtX = l.MaxExtents.X - l.MinExtents.X;
double sizeExtY = l.MaxExtents.Y - l.MinExtents.Y;
if (l.PlotPaperUnits == CadPlotPaperUnits.PlotInInches)
{
options.PageHeight = CommonHelper.INtoPixels(sizeExtY, CommonHelper.DPI);
options.PageWidth = CommonHelper.INtoPixels(sizeExtX, CommonHelper.DPI);
}
else
{
if (l.PlotPaperUnits == CadPlotPaperUnits.PlotInMillimeters)
{
options.PageHeight = CommonHelper.MMtoPixels(sizeExtY, CommonHelper.DPI);
options.PageWidth = CommonHelper.MMtoPixels(sizeExtX, CommonHelper.DPI);
}
else
{
options.PageHeight = (float)sizeExtY;
options.PageWidth = (float)sizeExtX;
}
}
}
//options.CenterDrawing = true;
jpegOptions.VectorRasterizationOptions = options;
cadImage.Save(fs, jpegOptions);
}
}
}
}
}
private static List<string> GetNotEmptyLayouts(Image cadImage, string extension)
{
List<string> nonEmptyLayouts = new List<string>();
if (cadImage == null)
return nonEmptyLayouts;
switch (extension)
{
case ".dwg":
nonEmptyLayouts = GetNotEmptyLayoutsForDwg((CadImage)cadImage);
break;
case ".dxf":
nonEmptyLayouts = GetNotEmptyLayoutsForDxf((CadImage)cadImage);
break;
}
return nonEmptyLayouts;
}
private static List<string> GetNotEmptyLayoutsForDwg(CadImage cadImage)
{
List<string> notEmptyLayouts = new List<string>();
foreach (CadLayout layout in cadImage.Layouts.Values)
{
foreach (CadBlockTableObject tableObject in cadImage.BlocksTables)
{
if (string.Equals(tableObject.HardPointerToLayout.Value, layout.ObjectHandle, StringComparison.InvariantCultureIgnoreCase))
{
if (cadImage.BlockEntities.ContainsKey(tableObject.BlockName))
{
CadBlockEntity cadBlockEntity = cadImage.BlockEntities[tableObject.BlockName];
if (cadBlockEntity.Entities.Length > 0)
notEmptyLayouts.Add(layout.LayoutName);
}
break;
}
}
}
return notEmptyLayouts;
}
private static List<string> GetNotEmptyLayoutsForDxf(CadImage cadImage)
{
List<string> notEmptyLayouts = new List<string>();
Dictionary<string, string> layoutBlockHandles = new Dictionary<string, string>();
foreach (CadLayout layout in cadImage.Layouts.Values)
{
if (layout.BlockTableRecordHandle != null)
layoutBlockHandles.Add(layout.BlockTableRecordHandle, layout.LayoutName);
}
foreach (CadBaseEntity entity in cadImage.Entities)
{
if (layoutBlockHandles.ContainsKey(entity.SoftOwner.Value))
{
string layoutName = layoutBlockHandles[entity.SoftOwner.Value];
if (!notEmptyLayouts.Contains(layoutName))
notEmptyLayouts.Add(layoutName);
}
}
return notEmptyLayouts;
}
string MyDir = RunExamples.GetDataDir_IGESDrawings();
string sourceFilePath = MyDir + ("figa2.igs");
string outPath = MyDir + ("meshes.pdf");
using (Image igesImage = Image.Load(sourceFilePath))
{
Aspose.CAD.ImageOptions.PdfOptions pdf = new Aspose.CAD.ImageOptions.PdfOptions();
pdf.VectorRasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
pdf.VectorRasterizationOptions.PageHeight = 1000;
pdf.VectorRasterizationOptions.PageWidth = 1000;
igesImage.Save("figa2.pdf", pdf);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath))
{
Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)image;
Aspose.CAD.FileFormats.Cad.CadLayoutDictionary layouts = cadImage.Layouts;
foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadLayout layout in layouts.Values)
{
Console.WriteLine("Layout " + layout.LayoutName);
}
}
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir+("meshes.dwg");
string outPath = MyDir+("meshes.pdf");
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
//rasterizationOptions.TypeOfEntities = TypeOfEntities.Entities3D;
rasterizationOptions.Layouts = new string[] { "Model" };
PdfOptions pdfOptions = new PdfOptions
{
VectorRasterizationOptions = rasterizationOptions
};
{
cadImage.Save(outPath, pdfOptions);
}
}
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
CadImage cadImage = (CadImage)Image.Load(sourceFilePath);
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
PdfOptions pdfOptions = new PdfOptions();
// Here user can change default start cap and end cap of pens when exporting CadImage object to
// image. It can be using for all image formats: pdf, png, bmp, gif, jpeg2000, jpeg, psd, tiff, wmf.
// If user doesn't use PenOptions, system will use its own default pens (different in defferent places).
rasterizationOptions.PenOptions = new PenOptions
{
StartCap = LineCap.Flat,
EndCap = LineCap.Flat
};
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
cadImage.Save(MyDir+"9LHATT-A56_generated.pdf", pdfOptions);
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
using (CadImage image = (CadImage)Image.Load(MyDir+"example.dwt"))
{
foreach (CadBaseEntity entity in image.Entities)
{
//do your work here
}
}
}
// The path to the documents directory.
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 and set its various properties
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
// Set Auto Layout Scaling
rasterizationOptions.AutomaticLayoutsScaling = true;
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "result_out.pdf";
//Export the CAD to PDF
image.Save(MyDir, pdfOptions);
}
// The path to the documents directory.
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 and set its various properties
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
rasterizationOptions.BackgroundColor = Aspose.CAD.Color.Beige;
rasterizationOptions.DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseDrawColor;
rasterizationOptions.DrawColor = Aspose.CAD.Color.Blue;
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
//Export CAD to PDF
image.Save(MyDir + "result_out.pdf", pdfOptions);
// Create an instance of TiffOptions
Aspose.CAD.ImageOptions.TiffOptions tiffOptions = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// Set the VectorRasterizationOptions property
tiffOptions.VectorRasterizationOptions = rasterizationOptions;
//Export CAD to TIFF
image.Save(MyDir + "result_out.tiff", tiffOptions);
}
// The path to the documents directory.
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 and set its various properties
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
rasterizationOptions.AutomaticLayoutsScaling = true;
rasterizationOptions.NoScaling = false;
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
//Export CAD to PDF
image.Save(MyDir + "result_out.pdf", pdfOptions);
// Create an instance of TiffOptions
Aspose.CAD.ImageOptions.TiffOptions tiffOptions = new Aspose.CAD.ImageOptions.TiffOptions(Aspose.CAD.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// Set the VectorRasterizationOptions property
tiffOptions.VectorRasterizationOptions = rasterizationOptions;
//Export CAD to TIFF
image.Save(MyDir + "result_out.tiff", tiffOptions);
}
// 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 + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
// Iterate over the items of CadStyleDictionary
foreach (CadStyleTableObject style in cadImage.Styles)
{
if (style.StyleName == "Roman")
{
// Specify the font for one particular style
style.PrimaryFontName = "Arial";
}
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
// Iterate over the items of CadStyleDictionary
foreach (CadStyleTableObject style in cadImage.Styles)
{
// Set the font name
style.PrimaryFontName = "Arial";
}
}
Console.WriteLine("\nFont changed successfully.");
}
public static void SubstitutingFontByName()
{
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
// Iterate over the items of CadStyleDictionary
foreach (CadStyleTableObject style in cadImage.Styles)
{
if (style.StyleName == "Roman")
{
// Specify the font for one particular style
style.PrimaryFontName = "Arial";
}
}
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWFDrawings();
string sourceFilePath = MyDir + "blocks_and_tables.dwf";
string extension = Path.GetExtension(sourceFilePath);
using (DwfImage image = (DwfImage)Aspose.CAD.Image.Load(sourceFilePath))
{
foreach (var page in image.Pages)
{
var layout = page.Name;
System.Console.WriteLine("Layout= " + layout);
using (FileStream fs = new FileStream(MyDir + "layout_" + layout + ".jpg", FileMode.Create))
{
JpegOptions jpegOptions = new JpegOptions();
CadRasterizationOptions options = new CadRasterizationOptions();
options.Layouts = new string[] { layout };
double sizeExtX = page.MaxPoint.X - page.MinPoint.X;
double sizeExtY = page.MaxPoint.Y - page.MinPoint.Y;
if (page.UnitType == UnitType.Inch)
{
options.PageHeight = CommonHelper.INtoPixels(sizeExtY, CommonHelper.DPI);
options.PageWidth = CommonHelper.INtoPixels(sizeExtX, CommonHelper.DPI);
}
else if (page.UnitType == UnitType.Millimeter)
{
options.PageHeight = CommonHelper.MMtoPixels(sizeExtY, CommonHelper.DPI);
options.PageWidth = CommonHelper.MMtoPixels(sizeExtX, CommonHelper.DPI);
}
else
{
options.PageHeight = (float)sizeExtY;
options.PageWidth = (float)sizeExtX;
}
//options.CenterDrawing = true;
jpegOptions.VectorRasterizationOptions = options;
image.Save(fs, jpegOptions);
}
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "for_layers_test.dwf";
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.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
// Add desired layers
rasterizationOptions.Layers= new string[] { "LayerA" };
//rasterizationOptions.CenterDrawing = true;
JpegOptions jpegOptions = new JpegOptions();
jpegOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "for_layers_test.jpg";
// Export the DXF to JPG
image.Save(MyDir, jpegOptions);
}
// Input file name and path
string fileName = "BlockRefDgn.dwg";
// Load an existing DWG file and convert it into CadImage
using (Aspose.CAD.FileFormats.Cad.CadImage image = (Aspose.CAD.FileFormats.Cad.CadImage)Image.Load(fileName))
{
// Go through each entity inside the DWG file
foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadBaseEntity entity in image.Entities)
{
// Check if entity is of CadDgnUnderlay type
if (entity is Aspose.CAD.FileFormats.Cad.CadObjects.CadDgnUnderlay)
{
// Access different underlay flags
Aspose.CAD.FileFormats.Cad.CadObjects.CadUnderlay underlay = entity as Aspose.CAD.FileFormats.Cad.CadObjects.CadUnderlay;
Console.WriteLine(underlay.UnderlayPath);
Console.WriteLine(underlay.UnderlayName);
Console.WriteLine(underlay.InsertionPoint.X);
Console.WriteLine(underlay.InsertionPoint.Y);
Console.WriteLine(underlay.RotationAngle);
Console.WriteLine(underlay.ScaleX);
Console.WriteLine(underlay.ScaleY);
Console.WriteLine(underlay.ScaleZ);
Console.WriteLine((underlay.Flags & Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.UnderlayIsOn) == Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.UnderlayIsOn);
Console.WriteLine((underlay.Flags & Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.ClippingIsOn) == Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.ClippingIsOn);
Console.WriteLine((underlay.Flags & Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.Monochrome) != Aspose.CAD.FileFormats.Cad.CadObjects.UnderlayFlags.Monochrome);
break;
}
}
}
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string dwgPathToFile = MyDir + "SimpleEntites.dwg";
using (Image image = Image.Load(dwgPathToFile))
{
CadText cadText = new CadText();
cadText.StyleType = "Standard";
cadText.DefaultValue = "Some custom text";
cadText.ColorId = 256;
cadText.LayerName = "0";
cadText.FirstAlignment.X = 47.90;
cadText.FirstAlignment.Y = 5.56;
cadText.TextHeight = 0.8;
cadText.ScaleX = 0.0;
CadImage cadImage = (CadImage)image;
cadImage.BlockEntities["*Model_Space"].AddEntity(cadText);
PdfOptions pdfOptions = new PdfOptions();
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
pdfOptions.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
//cadRasterizationOptions.CenterDrawing = true;
cadRasterizationOptions.PageHeight = 1600;
cadRasterizationOptions.PageWidth = 1600;
cadRasterizationOptions.Layouts = new string[] { "Model" };
image.Save(MyDir+"SimpleEntites_generated.pdf", pdfOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string inputFile = MyDir + "test1.dwg";
string outputFile = MyDir + "test1.png";
using (FileStream fs = new FileStream(inputFile, FileMode.Open))
{
using (FileStream output = new FileStream(outputFile, FileMode.Create))
{
Image document = Image.Load(fs);
PngOptions saveOptions = new PngOptions();
CadRasterizationOptions options = new CadRasterizationOptions();
options.NoScaling = false;
//options.CenterDrawing = true;
options.PageHeight = document.Height * 10;
options.PageWidth = document.Width * 10;
options.DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor;
saveOptions.VectorRasterizationOptions = options;
document.Save(output, saveOptions);
}
}
var formatTypeDwt = Image.GetFileFormat(GetFileFromDesktop("sample.dwt"));
Assert.IsTrue(formatTypeDwt.ToString().ToLower().Contains("dwt"));
var formatTypeDwg = Image.GetFileFormat(GetFileFromDesktop("sample.dwg"));
Assert.IsTrue(formatTypeDwg.ToString().ToLower().Contains("dwg"));
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "Bottom_plate.dwg";
// Create an instance of PdfOptions
PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions
{
VectorRasterizationOptions = rasterizationOptions
};
pdfOptions.CorePdfOptions = new PdfDocumentOptions();
pdfOptions.CorePdfOptions.Compliance = PdfCompliance.PdfA1a;
cadImage.Save(outPath, pdfOptions);
pdfOptions.CorePdfOptions.Compliance = PdfCompliance.PdfA1b;
cadImage.Save(outPath, pdfOptions);
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string inputFile = MyDir + "Line.dwg";
string outFile = MyDir + "Line_19.2.dxf";
using (var cadImage = (CadImage)Image.Load(inputFile))
{
cadImage.Save(outFile);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "Bottom_plate.dwg";
using (CadImage cadImage = (CadImage)Image.Load(fileName))
{
// export to pdf
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.Layouts = new string[] { "Model" };
bool currentUnitIsMetric = false;
double currentUnitCoefficient = 1.0;
DefineUnitSystem(cadImage.UnitType, out currentUnitIsMetric, out currentUnitCoefficient);
if (currentUnitIsMetric)
{
double metersCoeff = 1 / 1000.0;
double scaleFactor = metersCoeff / currentUnitCoefficient;
rasterizationOptions.PageWidth = (float)(210 * scaleFactor);
rasterizationOptions.PageHeight = (float)(297 * scaleFactor);
rasterizationOptions.UnitType = UnitType.Millimeter;
}
else
{
rasterizationOptions.PageWidth = (float)(8.27f / currentUnitCoefficient);
rasterizationOptions.PageHeight = (float)(11.69f / currentUnitCoefficient);
rasterizationOptions.UnitType = UnitType.Inch;
}
rasterizationOptions.AutomaticLayoutsScaling = true;
PdfOptions pdfOptions = new PdfOptions
{
VectorRasterizationOptions = rasterizationOptions
};
cadImage.Save(outPath, pdfOptions);
// export to raster
//A4 size at 300 DPI - 2480 x 3508
rasterizationOptions.PageHeight = 3508;
rasterizationOptions.PageWidth = 2480;
cadImage.Save(outPath.Replace("pdf", "png"), pngOptions);
private static void DefineUnitSystem(UnitType unitType, out bool isMetric, out double coefficient)
{
isMetric = false;
coefficient = 1.0;
switch (unitType)
{
case UnitType.Parsec:
coefficient = 3.0857 * 10000000000000000.0;
isMetric = true;
break;
case UnitType.LightYear:
coefficient = 9.4607 * 1000000000000000.0;
isMetric = true;
break;
case UnitType.AstronomicalUnit:
coefficient = 1.4960 * 100000000000.0;
isMetric = true;
break;
case UnitType.Gigameter:
coefficient = 1000000000.0;
isMetric = true;
break;
case UnitType.Kilometer:
coefficient = 1000.0;
isMetric = true;
break;
case UnitType.Decameter:
isMetric = true;
coefficient = 10.0;
break;
case UnitType.Hectometer:
isMetric = true;
coefficient = 100.0;
break;
case UnitType.Meter:
isMetric = true;
coefficient = 1.0;
break;
case UnitType.Centimenter:
isMetric = true;
coefficient = 0.01;
break;
case UnitType.Decimeter:
isMetric = true;
coefficient = 0.1;
break;
case UnitType.Millimeter:
isMetric = true;
coefficient = 0.001;
break;
case UnitType.Micrometer:
isMetric = true;
coefficient = 0.000001;
break;
case UnitType.Nanometer:
isMetric = true;
coefficient = 0.000000001;
break;
case UnitType.Angstrom:
isMetric = true;
coefficient = 0.0000000001;
break;
case UnitType.Inch:
coefficient = 1.0;
break;
case UnitType.MicroInch:
coefficient = 0.000001;
break;
case UnitType.Mil:
coefficient = 0.001;
break;
case UnitType.Foot:
coefficient = 12.0;
break;
case UnitType.Yard:
coefficient = 36.0;
break;
case UnitType.Mile:
coefficient = 63360.0;
break;
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "visualization_-_conference_room.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.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
// Specify desired layout name
rasterizationOptions.Layouts = new string[] { "Layout1" };
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "ExportSpecificLayoutToPDF_out.pdf";
//Export the DWG to PDF
image.Save(MyDir, pdfOptions);
}
// The path to the documents directory.
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);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
using (Image image = Image.Load(MyDir + "sample.dwg"))
{
var options = new SvgOptions();
options.ColorType = Aspose.CAD.ImageOptions.SvgOptionsParameters.SvgColorMode.Grayscale;
options.TextAsShapes = true;
image.Save(MyDir + "sample.svg");
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "sample.dwg";
// Load an existing DWG file as CadImage.
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
System.Console.WriteLine(cadImage.BlockEntities["*MODEL_SPACE"].XRefPathName);
}
string dwgPathToFile = MyDir +"Drawing11.dwg";
CadImage cadImage1 = (CadImage)Image.Load(dwgPathToFile);
// using (Image image = ImageLoader.Load(dwgPathToFile))
{
CadRasterImageDef cadRasterImageDef = new CadRasterImageDef();
cadRasterImageDef.ObjectHandle = "A3B4";
cadRasterImageDef.FileName = "road-sign-custom.png";
CadRasterImage cadRasterImage = new CadRasterImage();
cadRasterImage.ImageDefReference = "A3B4";
cadRasterImage.InsertionPoint.X = 26.77;
cadRasterImage.InsertionPoint.Y = 22.35;
cadRasterImage.DisplayFlags = 7;
cadRasterImage.ImageSizeU = 640;
cadRasterImage.ImageSizeV = 562;
cadRasterImage.UVector.X = 0.0061565450840500831;
cadRasterImage.UVector.Y = 0;
cadRasterImage.VVector.X = 0;
cadRasterImage.VVector.Y = 0.0061565450840500822;
cadRasterImage.ClippingState = 0;
cadRasterImage.ClipBoundaryVertexList.Add(new Cad2DPoint(-0.5, 0.5));
cadRasterImage.ClipBoundaryVertexList.Add(new Cad2DPoint(639.5, 561.5));
CadImage cadImage = (CadImage)cadImage1;
cadImage.BlockEntities["*Model_Space"].AddEntity(cadRasterImage);
List<CadBaseObject> list = new List<CadBaseObject>(cadImage.Objects);
list.Add(cadRasterImageDef);
cadImage.Objects = list.ToArray();
PdfOptions pdfOptions = new PdfOptions();
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
pdfOptions.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
//cadRasterizationOptions.CenterDrawing = true;
cadRasterizationOptions.PageHeight = 1600;
cadRasterizationOptions.PageWidth = 1600;
cadRasterizationOptions.Layouts = new string[] { "Model" };
cadImage1.Save(MyDir+"export2.pdf", pdfOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "meshes.dwg";
// Load an existing DWG file as CadImage.
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
foreach (var entity in cadImage.Entities)
{
if (entity is CadPolyFaceMesh)
{
CadPolyFaceMesh asFaceMesh = (CadPolyFaceMesh)entity;
if (asFaceMesh != null)
{
Console.WriteLine("Vetexes count: " + asFaceMesh.MeshMVertexCount);
}
}
else if (entity is CadPolygonMesh)
{
CadPolygonMesh asPolygonMesh = (CadPolygonMesh)entity;
if (asPolygonMesh != null)
{
Console.WriteLine("Vetexes count: " + asPolygonMesh.MeshMVertexCount);
}
}
}
}
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "visualization_-_conference_room.dwg";
var cadImage = (CadImage)Aspose.CAD.Image.Load(sourceFilePath);
CadBaseEntity[] entities = cadImage.Entities;
List<CadBaseEntity> filteredEntities = new List<CadBaseEntity>();
foreach (CadBaseEntity baseEntity in entities)
{
// selection or filtration of entities
if (baseEntity.TypeName == CadEntityTypeName.TEXT)
{
filteredEntities.Add(baseEntity);
}
}
cadImage.Entities = filteredEntities.ToArray();
// Create an instance of CadRasterizationOptions and set its various properties
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions =
new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
// Set Auto Layout Scaling
rasterizationOptions.AutomaticLayoutsScaling = true;
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
string outFile = MyDir + "result_out_generated.pdf";
// Export the CAD to PDF
cadImage.Save(outFile, pdfOptions);
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "Bottom_plate.dwg";
using (CadImage image = (CadImage)Image.Load(fileName))
{
foreach (CadBaseEntity entity in image.Entities)
{
if (entity is CadUnderlay)
{
//XREF entity with metadata
Cad3DPoint insertionPoint = ((CadUnderlay)entity).InsertionPoint;
string path = ((CadUnderlay)entity).UnderlayPath;
}
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "Bottom_plate.dwg";
using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.Layouts = new string[] { "Model" };
rasterizationOptions.NoScaling = true;
// note: preserving some empty borders around part of image is the responsibility of customer
// top left point of region to draw
Point topLeft = new Point(6156, 7053);
double width = 3108;
double height = 2489;
CadVportTableObject newView = new CadVportTableObject();
// note: exactly such table name is required for active view
newView.TableName = "*Active";
newView.CenterPoint.X = topLeft.X + width / 2f;
newView.CenterPoint.Y = topLeft.Y - height / 2f;
newView.ViewHeight.Value = height;
newView.ViewAspectRatio.Value = width / height;
// search for active viewport and replace it
for (int i = 0; i < cadImage.ViewPorts.Count; i++)
{
CadVportTableObject currentView = (CadVportTableObject)(cadImage.ViewPorts[i]);
if ((currentView.TableName == null && cadImage.ViewPorts.Count == 1) ||
string.Equals(currentView.TableName.ToLowerInvariant(), "*active"))
{
cadImage.ViewPorts[i] = newView;
break;
}
}
image.Save(MyDir, pdfOptions);
}