导出 CAD

将 3D AutoCAD 图像导出为 PDF

Aspose.CAD 允许您将 3D AutoCAD 图像导出为 PDF。请使用 Aspose.CAD.ImageOptions.CadRasterizationOptions 指定您希望导出 3D 实体。

以下示例代码加载一个 AutoCAD 3D 文件并将其导出为 PDF。一旦文件转换为 PDF,您可以使用您喜欢的 PDF 查看器打开它。

// 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);
}

将 CAD 布局导出为 PDF

Aspose.CAD for .NET 允许您将 CAD 布局导出为 PDF。 Save 方法的 CadImage 类可以用于将布局导出为 PDF 格式。

以下示例代码加载一个 CAD 文件并将其“模型”布局导出为 PDF。一旦文件转换为 PDF,您可以使用您喜欢的 PDF 查看器打开它。

// 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);
}

支持在导出中设置笔

Aspose.CAD for .NET 允许您在 CAD 的导出属性中添加笔选项。通过使用 CadRasterizationOptions,我们可以设置笔属性选项。

下面是实现指定要求的示例代码。

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);

分解 CAD 插入对象

Aspose.CAD for .NET 允许您分解 CAD 对象并处理插入内部的单独实体。下面是实现指定要求的示例代码。

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
}
}
}

支持 ACAD 代理实体

Aspose.CAD for .NET 允许您读取和导出 ACAD_PROXY_ENTITY 实体。下面是实现指定要求的示例代码。

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);
}

集成 IGES 格式

Aspose.CAD for .NET 允许您读取和导出 IGES 格式。下面是实现指定要求的示例代码。

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);
}

支持网格模型

Aspose.CAD for .NET 允许您实现并计算使用多边形表示的边缘、顶点和面等网格模型。下面是实现指定要求的示例代码。

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);
}
}

设置自定义视角

Aspose.CAD for .NET 允许您为模型布局设置自定义视角。通过使用 VectorRasterizationOptions,您可以设置自定义视角。下面的代码示例展示了如何设置自定义视角。

// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCAD();
string sourceFilePath = MyDir + "conic_pyramid.dxf";
var outPath = Path.Combine(MyDir, "FreePointOfView_out.jpg");
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
JpegOptions options = new JpegOptions
{
VectorRasterizationOptions = new CadRasterizationOptions
{
PageWidth = 1500, PageHeight = 1500
}
};
float xAngle = 10; //Angle of rotation along the X axis
float yAngle = 30; //Angle of rotation along the Y axis
float zAngle = 40; //Angle of rotation along the Z axis
((CadRasterizationOptions)(options.VectorRasterizationOptions)).ObserverPoint = new ObserverPoint(xAngle, yAngle, zAngle);
cadImage.Save(outPath, options);
}