CADのエクスポート

3D AutoCAD画像をPDFにエクスポートする

Aspose.CADを使用すると、3D AutoCAD画像をPDFにエクスポートできます。ImageOptions.CadRasterizationOptionsTypeOfEntities.Entities3Dを使用して、3Dエンティティをエクスポートすることを指定します。 以下のサンプルコードは、AutoCAD 3Dファイルを読み込み、それをPDFにエクスポートします。ファイルがPDFに変換されたら、お気に入りのPDFビューアで開くことができます。

以下のコードサンプルは、3D AutoCAD画像をPDFにエクスポートする方法を示しています。

// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(Export3DAutoCADImagesToPDF.class) + "ExportingCAD/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image cadImage = Image.load(srcFile);
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(500);
rasterizationOptions.setPageHeight(500);
rasterizationOptions.setTypeOfEntities(TypeOfEntities.Entities3D);
rasterizationOptions.setLayouts(new String[] {"Model"});
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save(dataDir + "Export3DImagestoPDF_out_.pdf", pdfOptions);

CADレイアウトをPDFにエクスポートする

Aspose.CAD for Javaを使用すると、CADレイアウトをPDFにエクスポートできます。CadImageクラスのsaveメソッドを使用して、レイアウトをPDF形式にエクスポートできます。 以下のサンプルコードは、CADファイルを読み込み、その「モデル」レイアウトをPDFにエクスポートします。ファイルがPDFに変換されたら、お気に入りのPDFビューアで開くことができます。

こちらがサンプルコードです。

// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(ExportCADLayoutsToPDF.class) + "ExportingCAD/";
String srcFile = dataDir + "conic_pyramid.dxf";
// Create an instance of CadImage class and load the file.
Image cadImage = Image.load(srcFile);
// Create an instance of CadRasterizationOptions class
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Set the Entities type property to Entities3D.
rasterizationOptions.setTypeOfEntities(TypeOfEntities.Entities3D);
rasterizationOptions.setScaleMethod(ScaleType.GrowToFit);
rasterizationOptions.setContentAsBitmap(true);
// Set Layouts
rasterizationOptions.setLayouts(new String[] {"Model"});
// Create an instance of PDF options class
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Set Graphics options
rasterizationOptions.getGraphicsOptions().setSmoothingMode(SmoothingMode.HighQuality);
rasterizationOptions.getGraphicsOptions().setTextRenderingHint(TextRenderingHint.AntiAliasGridFit);
rasterizationOptions.getGraphicsOptions().setInterpolationMode(InterpolationMode.HighQualityBicubic);
// Export to PDF by calling the Save method
cadImage.save(dataDir + "CADLayoutsToPDF_out_.pdf", pdfOptions);

エクスポート時のペン設定のサポート

Aspose.CAD for Javaを使用すると、CADのエクスポートプロパティにペンオプションを追加できます。rasterizationOptionsを使用して、ペンプロパティオプションを設定できます。

以下は、指定された要件を達成するためのサンプルコードです。

String dataDir = Utils.getDataDir(PenSupportInExport.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
CadImage cadImage = ((CadImage)(Image.load(srcFile)));
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(cadImage.getWidth() * 100);
rasterizationOptions.setPageHeight(cadImage.getHeight() * 100);
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).
PenOptions penOts = new PenOptions();
penOts.setStartCap(LineCap.Flat);
penOts.setEndCap(LineCap.Flat);
//rasterizationOptions.setPenOptions(penOts);
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save((dataDir+"9LHATT-A56_generated.pdf"),pdfOptions);

Cad Insertオブジェクトの分解

Aspose.CAD for Javaを使用すると、cadオブジェクトを分解し、挿入内の個別のエンティティを処理できます。以下は、指定された要件を達成するためのサンプルコードです。

String srcFile = dataDir + "conic_pyramid.dxf";
CadImage cadImage =(CadImage) Image.load(srcFile);
try
{
for (int i=0; i<cadImage.getEntities().length;i++)
{
if (cadImage.getEntities()[i].getTypeName() == CadEntityTypeName.INSERT)
{
CadBlockEntity block =
(CadBlockEntity)cadImage.getBlockEntities().get_Item(((CadInsertObject)cadImage.getEntities()[i]).getName());
for (CadBaseEntity blockChild : block.getEntities())
{
// process entities
}
}
}
}
finally
{
cadImage.dispose();
}

ACADプロキシエンティティのサポート

Aspose.CAD for Javaを使用すると、ACAD_PROXY_ENTITYエンティティを読み込み、およびエクスポートできます。以下は、指定された要件を達成するためのサンプルコードです。

String dataDir = Utils.getDataDir(PenSupportInExport.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
CadImage cadImage = ((CadImage)(Image.load(srcFile)));
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(cadImage.getWidth() * 100);
rasterizationOptions.setPageHeight(cadImage.getHeight() * 100);
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).
PenOptions penOts = new PenOptions();
penOts.setStartCap(LineCap.Flat);
penOts.setEndCap(LineCap.Flat);
//rasterizationOptions.setPenOptions(penOts);
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save((dataDir+"9LHATT-A56_generated.pdf"),pdfOptions);

IGES形式の統合

Aspose.CAD for Javaを使用すると、IGES形式を読み込み、およびエクスポートできます。以下は、指定された要件を達成するためのサンプルコードです。

String dataDir = Utils.getDataDir(ExportIGEStoPDF.class) + "IGESDrawings/";
String PLTPathToFile = dataDir + "figa2.igs";
Image image = Image.load(PLTPathToFile);
//Setting PDF Options
PdfOptions pdfOptions = new PdfOptions();
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);
cadRasterizationOptions.setPageHeight(1000);
cadRasterizationOptions.setPageWidth(1000);
pdfOptions.setVectorRasterizationOptions(cadRasterizationOptions);
//Saving to PDF
image.save(dataDir+"figa2.pdf", pdfOptions);

メッシュモデルのサポート

Aspose.CAD for Javaを使用すると、エッジ、頂点、および面を持つポリゴン表現を使用してメッシュモデルを実装し、カウントできます。以下は、指定された要件を達成するためのサンプルコードです。

String srcFile = dataDir + "meshes.dwg";
// com.aspose.cad. objImage = com.aspose.cad.CImage.load(srcFile);
CadImage cadImage =(CadImage) com.aspose.cad.Image.load(srcFile);
try
{
for (CadBaseEntity entity : cadImage.getEntities())
{
if (entity instanceof CadPolyFaceMesh)
{
CadPolyFaceMesh asFaceMesh= (CadPolyFaceMesh)entity;
if (asFaceMesh != null)
{
System.out.println("Vetexes count: " + asFaceMesh.getMeshMVertexCount());
}
}
else if (entity instanceof CadPolygonMesh)
{
CadPolygonMesh asPolygonMesh= (CadPolygonMesh)entity;
if (asPolygonMesh != null)
{
System.out.println("Vetexes count: " + asPolygonMesh.getMeshMVertexCount());
}
}
}
}
finally
{
cadImage.dispose();
}

カスタム視点の設定

Aspose.CAD for Javaを使用すると、モデルレイアウトのカスタム視点を設定できます。vectorRasterizationOptionsを使用して、カスタム視点を設定できます。以下のコードサンプルは、カスタム視点を設定する方法を示しています。

String dataDir = Utils.getDataDir(FreePointOfView.class) + "CADConversion/";
// Path to source file
String sourceFilePath = dataDir+"conic_pyramid.dxf";
// Load a CAD drawing in an instance of Image
com.aspose.cad.Image objImage = com.aspose.cad.Image.load(sourceFilePath);
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
cadRasterizationOptions.setPageHeight(1500);
cadRasterizationOptions.setPageWidth(1500);
// Create an instance of JpegOptions class
com.aspose.cad.imageoptions.JpegOptions options = new com.aspose.cad.imageoptions.JpegOptions();
options.setVectorRasterizationOptions(cadRasterizationOptions);
float xAngle = 10; //Angle of rotation along the X axis
float yAngle = 30; //Angle of rotation along the Y axis
float zAngle = 40; //Angle of rotation along the Z axis
ObserverPoint obvPoint = new ObserverPoint(xAngle,yAngle,zAngle);
cadRasterizationOptions.setObserverPoint(obvPoint);
options.setVectorRasterizationOptions(cadRasterizationOptions);
//Saving to Image
objImage.save(dataDir+"FreePointOfView_out.jpeg", options);