Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aspose.CAD for .NET

// 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);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "search.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))
{
// 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
IterateCADNodes(entity);
}
// 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;
}
}
if (blockTableObjectReference !=null)
{
// 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(MyDir + "SearchText_out.pdf", pdfOptions);
}
}
public static void SearchTextInDWGAutoCADFile()
{
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "search.dwg";
// Load an existing DWG file as CadImage.
CadImage cadImage = (CadImage) Image.Load(sourceFilePath);
// Search for text in the entities section
foreach (var entity in cadImage.Entities) {
IterateCADNodes(entity);
}
// Search for text in the block section
foreach (CadBlockEntity blockEntity in cadImage.BlockEntities.Values) {
foreach (var entity in blockEntity.Entities) {
IterateCADNodes(entity);
}
}
}
private static void IterateCADNodes(CadBaseEntity obj)
{
switch (obj.TypeName) {
case CadEntityTypeName.TEXT:
CadText childObjectText = (CadText) obj;
Console.WriteLine(childObjectText.DefaultValue);
break;
case CadEntityTypeName.MTEXT:
CadMText childObjectMText = (CadMText) obj;
Console.WriteLine(childObjectMText.Text);
break;
case CadEntityTypeName.INSERT:
CadInsertObject childInsertObject = (CadInsertObject) obj;
foreach (var tempobj in childInsertObject.ChildObjects) {
IterateCADNodes(tempobj);
}
break;
case CadEntityTypeName.ATTDEF:
CadAttDef attDef = (CadAttDef) obj;
Console.WriteLine(attDef.DefaultString);
break;
case CadEntityTypeName.ATTRIB:
CadAttrib attAttrib = (CadAttrib) obj;
Console.WriteLine(attAttrib.DefaultText);
break;
}
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "Bottom_plate.dwg";
using (CadImage cadImage = (CadImage)Image.Load(fileName))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.PageHeight = cadImage.Height;
rasterizationOptions.PageWidth = cadImage.Width;
rasterizationOptions.Layers.Add("Print");
rasterizationOptions.Layers.Add("L1_RegMark");
rasterizationOptions.Layers.Add("L2_RegMark");
PdfOptions pdfOptions = new PdfOptions();
rasterizationOptions.Layouts = new string[] { "Model" };
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
cadImage.Save(outDir, pdfOptions);
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string file = MyDir + "sample.dwg";
using (Image image = Image.Load(file))
{
// Test
FileFormats.Cad.CadImage cadImage = (FileFormats.Cad.CadImage)image;
Assert.AreNotEqual(cadImage.Entities.Length, 0);
CadMLeader cadMLeader = (CadMLeader)cadImage.Entities[0];
Assert.AreEqual(cadMLeader.StyleDescription, "Standard");
Assert.AreEqual(cadMLeader.LeaderStyleId, "12E");
Assert.AreEqual(cadMLeader.ArrowHeadId1, "639");
Assert.AreEqual(cadMLeader.LeaderLineTypeID, "14");
CadMLeaderContextData context = cadMLeader.ContextData;
Assert.AreEqual(context.ArrowHeadSize, 30.0, 0.1);
Assert.AreEqual(context.BasePoint.X, 481, 1);
Assert.AreEqual(context.ContentScale, 1.0, 0.01);
Assert.AreEqual(context.DefaultText.Value, "This is multileader with huge text\\P{\\H1.5x;6666666666666666666666666666\\P}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
Assert.AreEqual(context.HasMText, true);
CadMLeaderNode mleaderNode = context.LeaderNode;
Assert.AreEqual(mleaderNode.LastLeaderLinePoint.X, 473, 1);
CadMLeaderLine leaderLine = mleaderNode.LeaderLine;
Assert.AreEqual(leaderLine.BreakEndPoint, null);
Assert.AreEqual(leaderLine.BreakPointIndex.Value, 0);
Assert.AreEqual(leaderLine.BreakStartPoint, null);
Assert.AreEqual(leaderLine.LeaderLineIndex.Value, 0);
Assert.AreEqual(leaderLine.LeaderPoints.Count, 4);
Assert.AreEqual(mleaderNode.BranchIndex, 0);
Assert.AreEqual(mleaderNode.DogLegLength, 8.0, 0.1);
Assert.AreEqual(context.HasMText, true);
Assert.AreEqual(context.TextAttachmentType.Value, 1);
Assert.AreEqual(context.TextBackgroundColor.Value, 18);
Assert.AreEqual(context.TextHeight, 20.0, 0.1);
Assert.AreEqual(context.TextStyleID.Value, "11");
Assert.AreEqual(context.TextRotation.Value, 0.0, 0.01);
Assert.AreEqual(cadMLeader.ArrowHeadId1, "639");
Assert.AreEqual(cadMLeader.LeaderType, 1);
Assert.AreEqual(cadMLeader.BlockContentColor, 0);
Assert.AreEqual(cadMLeader.LeaderLineColor, 0);
Assert.AreEqual(cadMLeader.TextHeight, 1.0, 0.01);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
List<CadBaseEntity> mtextList = new List<CadBaseEntity>();
List<CadBaseEntity> attribList = new List<CadBaseEntity>();
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
foreach (var entity in cadImage.Entities)
{
if (entity.TypeName == CadEntityTypeName.MTEXT)
{
mtextList.Add(entity);
}
if (entity.TypeName == CadEntityTypeName.INSERT)
{
foreach (var childObject in entity.ChildObjects)
{
if (childObject.TypeName == CadEntityTypeName.ATTRIB)
{
attribList.Add(childObject);
}
}
}
}
Assert.AreEqual(6, mtextList.Count);
Assert.AreEqual(34, attribList.Count);
}
}
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
using (Image image = Image.Load(MyDir + "conic_pyramid.dxf"))
{
using (FileStream stream = new FileStream(MyDir + "output_conic_pyramid.pdf", FileMode.Create))
{
PdfOptions pdfOptions = new PdfOptions();
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
pdfOptions.VectorRasterizationOptions = cadRasterizationOptions;
cadRasterizationOptions.PageWidth = 800;
cadRasterizationOptions.PageHeight = 600;
int idxError = 1;
cadRasterizationOptions.RenderResult += new CadRasterizationOptions.CadRenderHandler(
delegate (CadRenderResult result)
{
Console.WriteLine("Tracking results of exporting");
if (result.IsRenderComplete)
return;
Console.WriteLine("Have some problems:");
foreach (RenderResult rr in result.Failures)
Console.WriteLine(string.Format("{0}. {1}, {2}", idxError++, rr.RenderCode.ToString(),
rr.Message));
});
Console.WriteLine("Exporting to pdf format");
image.Save(stream, pdfOptions);
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
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;
// Add desired layers
rasterizationOptions.Layers = new string[] { "LayerA" };
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "conic_pyramid_layer_out.pdf";
//Export the DXF to PDF
image.Save(MyDir, pdfOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
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;
// Specify desired layout name
rasterizationOptions.Layouts = new string[] { "Model" };
// Create an instance of PdfOptions
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "conic_pyramid_layout_out.pdf";
//Export the DXF to PDF
image.Save(MyDir, pdfOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
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.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 + "conic_pyramid_out.pdf";
//Export the DXF to PDF
image.Save(MyDir, pdfOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (var image = Image.Load("NRB-GRID-BLOCK-MD-PROVALVDK-241000-162000-45400.dgn"))
{
var vectorOptions = new CadRasterizationOptions();
vectorOptions.AutomaticLayoutsScaling = true;
vectorOptions.BackgroundColor = Color.Black;
vectorOptions.PageWidth = 500;
vectorOptions.PageHeight = 500;
WmfOptions wmfOptions = new WmfOptions()
{
VectorRasterizationOptions = vectorOptions
};
image.Save("NRB-GRID-BLOCK-MD-PROVALVDK-241000-162000-45400.dgn.wmf", vectorOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (CadImage cadImage = (CadImage)Image.Load(fileName))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.Layouts = new[] { "Model" };
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
cadImage.Save(outDir + fileName + ".pdf", pdfOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
foreach (var file in new DirectoryInfo(MyDir).EnumerateFiles("*.dxf"))
{
// ****************************
// Set new font per document
// ****************************
using (var cadImage = (CadImage)Image.Load(file.FullName))
{
// Iterate over the items of CadStyleTableObject
foreach (CadStyleTableObject style in cadImage.Styles)
{
// Set font name
style.PrimaryFontName = "Broadway";
}
cadImage.Save(file.FullName + "_font.dxf");
}
// ****************************
// Hide all "straight" lines
// ****************************
using (var cadImage = (CadImage)Image.Load(file.FullName))
{
foreach (var entity in cadImage.Entities)
{
// Make lines invisible
if (entity.TypeName == CadEntityTypeName.LINE)
{
entity.Visible = 0;
}
}
cadImage.Save(file.FullName + "_lines.dxf");
}
// ****************************
// Manipulations with text
// ****************************
using (var cadImage = (CadImage)Image.Load(file.FullName))
{
foreach (var entity in cadImage.Entities)
{
if (entity.TypeName == CadEntityTypeName.TEXT)
{
((CadText)entity).DefaultValue = "New text here!!! :)";
break;
}
}
cadImage.Save(file.FullName + "_text.dxf");
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (CadImage image = (CadImage)Image.Load(fileName);
{
ImageOptionsBase options = new JpegOptions();
options.VectorRasterizationOptions = new CadRasterizationOptions() {PdfProductLocation = "C:\PDF" /*path to pdf product and licence*/ };
options.VectorRasterizationOptions.PageHeight = 1000;
options.VectorRasterizationOptions.PageWidth = 1000;
image.Save(outPath, options);
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
// any entities updates
cadImage.Save(MyDir+"conic.dxf");
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DXFDrawings();
string inputFile = MyDir + "SLS-CW-CD-CE001-R01_blockClip.dxf";
string outputFile = MyDir + "SLS-CW-CD-CE001-R01_blockClip.pdf";
using (CadImage cadImage = (CadImage)Image.Load(inputFile))
{
var rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions
{
BackgroundColor = Aspose.CAD.Color.White,
DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor,
PageWidth = 1200,
PageHeight = 1600,
BorderX = 30,
BorderY = 5,
//CenterDrawing = true,
Layouts = new string[] { "Model" }
};
PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions
{
VectorRasterizationOptions = rasterizationOptions
};
cadImage.Save(outputFile, pdfOptions);
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.UnitType = UnitType.Inch;
rasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor;
rasterizationOptions.BackgroundColor = Color.Black;
rasterizationOptions.Layouts = new string[] { "Model" };
PdfOptions pdfOptions = new PdfOptions
{
VectorRasterizationOptions = rasterizationOptions
};
cadImage.Save(MyDir+"output.pdf", pdfOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
// Create an instance of CadImage class and load the file.
using (Aspose.CAD.Image cadImage = (Aspose.CAD.Image)Image.Load(sourceFilePath))
{
// Create an instance of CadRasterizationOptions class
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.PageWidth = 1600;
rasterizationOptions.PageHeight = 1600;
// Set the Entities type property to Entities3D.
//rasterizationOptions.TypeOfEntities = TypeOfEntities.Entities3D;
rasterizationOptions.AutomaticLayoutsScaling = true;
rasterizationOptions.NoScaling = false;
rasterizationOptions.ContentAsBitmap = true;
// Set Layouts
rasterizationOptions.Layouts = new string[] { "Model" };
// Create an instance of PDF options class
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "CADLayoutsToPDF_out.pdf";
// Set Graphics options
rasterizationOptions.GraphicsOptions.SmoothingMode = SmoothingMode.HighQuality;
rasterizationOptions.GraphicsOptions.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
rasterizationOptions.GraphicsOptions.InterpolationMode = InterpolationMode.HighQualityBicubic;
//Export to PDF by calling the Save method
cadImage.Save(MyDir, pdfOptions);
}
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
for (int i = 0; i < cadImage.Entities.Length; i++)
{
if (cadImage.Entities[i].TypeName == CadEntityTypeName.INSERT)
{
CadBlockEntity block = cadImage.BlockEntities[(cadImage.Entities[i] as CadInsertObject).Name];
foreach (CadBaseEntity baseEntity in block.Entities)
{
// processing of entities
}
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
using (Aspose.CAD.Image cadImage = Aspose.CAD.Image.Load(sourceFilePath))
{
Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions();
rasterizationOptions.PageWidth = 500;
rasterizationOptions.PageHeight = 500;
// rasterizationOptions.TypeOfEntities = TypeOfEntities.Entities3D;
rasterizationOptions.Layouts = new string[] { "Model" };
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
MyDir = MyDir + "Export3DImagestoPDF_out.pdf";
cadImage.Save(MyDir, pdfOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string fileName = MyDir + "18-12-11 9644 - site.dwf";
using (Image image = Image.Load(fileName))
{
CadRasterizationOptions dwfRasterizationOptions = new CadRasterizationOptions();
//dwfRasterizationOptions.CenterDrawing = true;
dwfRasterizationOptions.PageHeight = 500;
dwfRasterizationOptions.PageWidth = 500;
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = dwfRasterizationOptions;
// export
string outPath = MyDir + "18-12-11 9644 - site.pdf";
image.Save(outPath, pdfOptions);
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string inputFile = MyDir + "18-12-11 9644 - site.dwf";
using (Image image = Image.Load(inputFile))
{
BmpOptions bmpOptions = new BmpOptions();
var dwfRasterizationOptions = new CadRasterizationOptions();
bmpOptions.VectorRasterizationOptions = dwfRasterizationOptions;
//dwfRasterizationOptions.CenterDrawing = true;
dwfRasterizationOptions.PageHeight = 500;
dwfRasterizationOptions.PageWidth = 500;
// export
string outPath = MyDir + "18-12-11 9644 - site.bmp";
image.Save(outPath, bmpOptions);
}
public static void Run()
{
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "themepark.plt";
Image image = Image.Load((sourceFilePath));
ImageOptionsBase imageOptions = new JpegOptions();
CadRasterizationOptions options = new CadRasterizationOptions
{
PageHeight = 500,
PageWidth = 1000,
//CenterDrawing = true
};
imageOptions.VectorRasterizationOptions = options;
image.Save((MyDir+"themepark.jpg"), imageOptions);
}
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ExportingDGN();
string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn";
// Load an existing DGN file as CadImage.
using (DgnImage dgnImage = (DgnImage)Image.Load(file))
{
var options = new PdfOptions
{
VectorRasterizationOptions = new CadRasterizationOptions
{
PageWidth = 1500,
PageHeight = 1500,
CenterDrawing = true,
AutomaticLayoutsScaling = true,
BackgroundColor = Color.Black,
Layouts = new string[] { "1", "2", "3", "9" }//only export 4 (1,2,3 and 9) views
}
};
dgnImage.Save(outFile, options);
}
// Input and Output file paths
string fileName = "BlockRefDgn.dwg";
string outPath = fileName + ".pdf";
// Create an instance of PdfOptions class as we are exporting the DWG file to PDF format
Aspose.CAD.ImageOptions.PdfOptions exportOptions = new Aspose.CAD.ImageOptions.PdfOptions();
// Load any existing DWG file as image and convert it to CadImage type
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Image.Load(fileName))
{
// Go through each entity inside the DWG file
foreach (Aspose.CAD.FileFormats.Cad.CadObjects.CadBaseEntity baseEntity in cadImage.Entities)
{
// Check if entity is an image definition
if (baseEntity.TypeName == Aspose.CAD.FileFormats.Cad.CadConsts.CadEntityTypeName.DGNUNDERLAY)
{
Aspose.CAD.FileFormats.Cad.CadObjects.CadDgnUnderlay dgnFile = (Aspose.CAD.FileFormats.Cad.CadObjects.CadDgnUnderlay)baseEntity;
// Get external reference to object
System.Console.WriteLine(dgnFile.UnderlayPath);
}
}
// Define settings for CadRasterizationOptions object
exportOptions.VectorRasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600,
//CenterDrawing = true,
Layouts = new string[] { "Model" },
AutomaticLayoutsScaling = false,
NoScaling = true,
BackgroundColor = Color.Black,
DrawType = Aspose.CAD.FileFormats.Cad.CadDrawTypeMode.UseObjectColor
};
//Export the DWG to PDF by calling Save method
cadImage.Save(outPath, exportOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ExportingDGN();
string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn";
// Load an existing DGN file as CadImage.
using (Aspose.CAD.FileFormats.Dgn.DgnImage cadImage = (Aspose.CAD.FileFormats.Dgn.DgnImage)Aspose.CAD.Image.Load(sourceFilePath))
{
// 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.NoScaling = true;
rasterizationOptions.AutomaticLayoutsScaling = false;
// 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(MyDir + "ExportDGNToPdf_out.pdf", pdfOptions);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ExportingDGN();
string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn";
// Load an existing DGN file as CadImage.
using (Aspose.CAD.FileFormats.Cad.CadImage cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load(sourceFilePath))
{
// Create an object of DgnRasterizationOptions 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.NoScaling = true;
rasterizationOptions.AutomaticLayoutsScaling = false;
// 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(MyDir + "ExportDGNToRasterImage_out.pdf", options);
}
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ExportingDGN();
string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn";
// Load an existing DGN file as CadImage.
using (DgnImage dgnImage = (DgnImage)Image.Load(file))
{
foreach (DgnDrawingElementBase element in dgnImage.Elements)
{
switch (element.Metadata.Type)
{
case DgnElementType.Line:
case DgnElementType.Ellipse:
case DgnElementType.Curve:
case DgnElementType.BSplineCurveHeader:
case DgnElementType.Arc:
case DgnElementType.Shape:
case DgnElementType.PolyLine:
case DgnElementType.TextNode:
case DgnElementType.Text:
case DgnElementType.ComplexShapeHeader:
case DgnElementType.ComplexChainHeader:
{
//previously supported entities, now supported also for 3D
break;
}
case DgnElementType.SolidHeader3D:
case DgnElementType.Cone:
case DgnElementType.CellHeader:
{
//supported 3D entities
break;
}
}
}
}
// The path to the documents directory.
string MyDir = RunExamples.