DWG 도면
DWG 도면을 PDF로 내보내기
Aspose.CAD for .NET API는 AutoCAD 도면을 DWG 형식으로 로드하고 이를 PDF로 변환할 수 있습니다. 이 주제에서는 간단한 단계를 통해 DWG를 PDF 형식으로 변환하는 Aspose.CAD API의 사용법을 설명합니다.
이 API는 다음의 AutoCAD DWG 버전을 지원합니다:
- DWG 2004 버전 16.0 릴리스 18
- DWG 2005 버전 16.1
- DWG 2010 버전 18.0
- DWG 2013 버전 19.0
DWG 파일 형식
DWG는 벡터 이미지 데이터와 메타데이터를 포함하는 이진 파일입니다. 벡터 이미지 데이터는 CAD 애플리케이션에 DWG를 어떻게 표시할 것인지에 대한 지침을 제공합니다. 메타데이터는 파일에 대한 다양한 정보를 포함할 수 있으며, 여기에는 위치 관련 데이터와 클라이언트 데이터도 포함됩니다. DWG 파일 형식에 대한 공개 사양은 이 PDF 문서에서 찾을 수 있습니다.
DWG 파일을 PDF로 변환하기
다음의 간단한 단계가 필요합니다 DWG를 PDF로 변환하기 위해:
- Image 인스턴스에 DWG 파일을 로드합니다.
- CadRasterizationOptions 클래스의 객체를 생성하고 PageHeight 및 PageWidth 속성을 설정합니다.
- PdfOptions 클래스의 객체를 생성하고 VectorRasterizationOptions 속성을 설정합니다.
- Image.Save를 호출하며, PdfOptions 객체를 두 번째 매개변수로 전달합니다.
아래 코드 샘플은 DWG 도면을 PDF로 내보내는 방법을 보여줍니다.
// 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); | |
} |
다양한 레이아웃 크기로 하나의 PDF 생성하기
Aspose.CAD for .NET은 DWG 파일을 다양한 레이아웃 크기로 하나의 PDF로 변환할 수 있습니다. 이 방법은 다음과 같이 작동합니다:
- Aspose.CAD.Image.Load 팩토리 메서드를 사용하여 DWG 파일을 로드합니다.
- CadRasterizationOptions 클래스의 인스턴스를 생성하고 결과 페이지 높이 및 너비를 설정합니다.
- CadRasterizationOptions 객체에 필요한 LayoutPageSizes를 추가합니다.
- PdfOptions 클래스의 인스턴스를 생성하고 그 VectorRasterizationOptions 속성을 설정합니다.
- Image.Save() 메서드를 사용하여 이미지를 PDF로 내보냅니다.
아래 코드 샘플은 다양한 레이아웃으로 하나의 PDF를 만드는 방법을 보여줍니다.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DWGDrawings(); | |
using (CadImage cadImage = (CadImage)Image.Load(MyDir + "City skyway map.dwg")) | |
{ | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.PageWidth = 1000; | |
rasterizationOptions.PageHeight = 1000; | |
//custom sizes for several layouts | |
rasterizationOptions.LayoutPageSizes.Add("ANSI C Plot", new SizeF(500, 1000)); | |
rasterizationOptions.LayoutPageSizes.Add("8.5 x 11 Plot", new SizeF(1000, 100)); | |
PdfOptions pdfOptions = new PdfOptions() { VectorRasterizationOptions = rasterizationOptions }; | |
cadImage.Save(MyDir + "singlePDF_out.pdf", pdfOptions); | |
} | |
지원되는 AutoCAD 프리미티브
다음의 AutoCAD 프리미티브가 지원됩니다.
- TEXT
- MTEXT
- ATTDEF
- ATTRIB
- ARC
- ELLIPSE
- HATCH
- LEADER
- POINT
- VERTEX 2D
- VERTEX 3D
- POLYLINE 2D
- LWPOLYLINE
- RAY
- CIRCLE
- DIMENSION ORDINATE
- DIMENSION LINEAR
- DIMENSION ALIGNED
- DIMENSION ANG 3Pt
- DIMENSION ANG 2Ln
- DIMENSION RADIUS
- DIMENSION DIAMETER
- SHAPE
- SOLID
- SPLINE
- MLINE
- LINE
- XLINE
- STYLE
- DIMSTYLE
- LTYPE
- MLINESTYLE
- LAYER
- VIEWPORT
- LAYOUT
특정 DWG 레이아웃을 PDF로 내보내기
이 방법은 다음과 같이 작동합니다:
- Aspose.CAD.Image.Load 팩토리 메서드를 사용하여 DWG 파일을 로드합니다.
- CadRasterizationOptions 클래스의 인스턴스를 생성하고 결과 페이지 높이 및 너비를 설정합니다.
- CadRasterizationOptions 객체에 대한 Layouts 속성을 설정합니다.
- PdfOptions 클래스의 인스턴스를 생성하고 그 VectorRasterizationOptions 속성을 설정합니다.
- Image.Save() 메서드를 사용하여 이미지를 PDF로 내보냅니다.
아래 코드 샘플은 특정 DWG 레이아웃을 PDF로 변환하는 방법을 보여줍니다.
// 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); | |
} |
좌표를 지정하여 DWG 문서 렌더링
Aspose.CAD for .NET API는 이제 문서의 너비와 높이의 좌표를 제공하여 DWG 문서를 렌더링하는 기능을 제공합니다.
아래 코드 샘플은 DWG 문서를 렌더링하는 방법을 보여줍니다.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DWGDrawings(); | |
string sourceFilePath = MyDir + "Bottom_plate.dwg"; | |
using (CadImage cadImage = (CadImage)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.Name.Value = "*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.Name.Value == null && cadImage.ViewPorts.Count == 1) || | |
string.Equals(currentView.Name.Value.ToLowerInvariant(), "*active")) | |
{ | |
cadImage.ViewPorts[i] = newView; | |
break; | |
} | |
} | |
PdfOptions pdfOptions = new PdfOptions(); | |
rasterizationOptions.Layouts = new string[] { "Model" }; | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
cadImage.Save(MyDir, pdfOptions); | |
} |
고정 크기를 사용하여 DWG를 래스터 또는 PDF로 내보내기
Aspose.CAD for .NET API는 DWG 형식의 AutoCAD 도면을 로드하고 고정 크기를 사용하여 PDF 또는 래스터로 변환할 수 있습니다.
아래 코드 샘플은 이 기능을 구현하는 방법을 보여줍니다.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DWGDrawings(); | |
string sourceFilePath = MyDir + "Bottom_plate.dwg"; | |
string outPath = MyDir + "Bottom_plate.pdf"; | |
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath)) | |
{ | |
// 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; | |
PngOptions pngOptions = new PngOptions | |
{ | |
VectorRasterizationOptions = rasterizationOptions | |
}; | |
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; | |
} | |
} |
DWG를 PDF/A 및 PDF/E로 내보내기
이 방법은 다음과 같이 작동합니다:
- Aspose.CAD.Image.Load 팩토리 메서드를 사용하여 DWG 파일을 로드합니다.
- CadRasterizationOptions 클래스의 인스턴스를 생성합니다.
- PdfOptions 클래스의 인스턴스를 생성하고 그 VectorRasterizationOptions 속성을 설정합니다.
- PDF 준수 속성을 설정하고 저장합니다.
- Image.Save() 메서드를 사용하여 이미지를 PDF로 내보냅니다.
아래 코드 샘플은 DWG 파일을 PDF/A 및 PDF/E로 변환하는 방법을 보여줍니다.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DWGDrawings(); | |
string sourceFilePath = MyDir + "Bottom_plate.dwg"; | |
Aspose.CAD.Image cadImage = 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 | |
PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions | |
{ | |
VectorRasterizationOptions = rasterizationOptions | |
}; | |
pdfOptions.CorePdfOptions = new PdfDocumentOptions(); | |
pdfOptions.CorePdfOptions.Compliance = PdfCompliance.PdfA1a; | |
cadImage.Save(MyDir + "PDFA1_A.pdf", pdfOptions); | |
pdfOptions.CorePdfOptions.Compliance = PdfCompliance.PdfA1b; | |
cadImage.Save(MyDir + "PDFA1_B.pdf", pdfOptions); |
DWG/DXF를 BMP 및 PDF로 내보낼 때 라운드 숨은 선 지원
이 방법은 다음과 같이 작동합니다:
- Aspose.CAD.Image.Load 팩토리 메서드를 사용하여 DWG 파일을 로드합니다.
- CadRasterizationOptions 클래스의 인스턴스를 생성하고 결과 페이지 높이 및 너비를 설정합니다.
- PdfOptions 클래스의 인스턴스를 생성하고 그 VectorRasterizationOptions 속성을 설정합니다.
- Image.Save() 메서드를 사용하여 이미지를 PDF로 내보냅니다.
아래 코드 샘플은 이 기능을 구현하는 방법을 보여줍니다.
내보낸 PDF에서 DWG 이미지의 인쇄 영역 설정 지원
Aspose.CAD for .NET API는 DWG 형식의 AutoCAD 도면을 로드하고 PDF로 변환할 수 있습니다. 이 주제에서는 내보낸 PDF에서 DWG 이미지에 대한 인쇄 영역 설정 지원을 달성하는 Aspose.CAD API의 사용법을 설명합니다.
아래 코드 샘플은 이 기능을 구현하는 방법을 보여줍니다.
// 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); | |
} |
DWG 파일의 XREF 메타데이터 읽기 지원
- Aspose.CAD.Image.Load 팩토리 메서드를 사용하여 DWG 파일을 로드합니다.
- 모든 이미지 개체를 순회합니다.
- 개체가 CadUnderlay인 경우 메타데이터가 있는 XREF 개체입니다.
아래 코드 샘플은 이 기능을 달성하는 방법을 보여줍니다.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DWGDrawings(); | |
string sourceFilePath = MyDir + "Bottom_plate.dwg"; | |
using (CadImage image = (CadImage)Image.Load(sourceFilePath)) | |
{ | |
foreach (CadBaseEntity entity in image.Entities) | |
{ | |
if (entity is CadUnderlay) | |
{ | |
//XREF entity with metadata | |
Cad3DPoint insertionPoint = ((CadUnderlay)entity).InsertionPoint; | |
string path = ((CadUnderlay)entity).UnderlayPath; | |
} | |
} | |
} |
CadRasterizationOptions.Layouts 속성은 문자열 배열 형식이므로 PDF 형식으로 가능한 변환을 위해 한 번에 여러 개의 레이아웃을 지정할 수 있습니다. CadRasterizationOptions.Layouts 속성에 대해 여러 레이아웃을 지정할 때 결과 PDF에는 여러 페이지가 포함되며, 각 페이지는 개별 AutoCAD 레이아웃을 나타냅니다.
모든 레이아웃 목록
다음 코드 스니펫을 사용하여 AutoCAD 도면에 존재하는 모든 레이아웃을 나열할 수 있습니다.
// 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); | |
} | |
} |
DWG 형식에 대한 언더레이 플래그 접근 지원
Aspose.CAD for .NET은 DWG 형식에 대한 언더레이 플래그를 구현하였으며, 개발자가 이를 액세스할 수 있도록 허용합니다. 다음은 간단한 코드 데모입니다.
// 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; | |
} | |
} | |
} |
DWG 개체 지원
Aspose.CAD for .NET API는 DWG 형식의 AutoCAD 도면을 로드하고 다양한 개체를 지원하여 작업할 수 있습니다.
MLeader 개체에 대한 지원
DWG는 벡터 이미지 데이터와 메타데이터를 포함하는 이진 파일입니다. DWG 파일에는 다양한 개체가 있습니다. 다음 섹션에서는 DWG 파일 내에서 MLeader 개체와 작업하는 예를 설명합니다.
// 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); | |
} |
DWG 개체를 이미지로 내보내는 지원
DWG는 벡터 이미지 데이터와 메타데이터를 포함하는 이진 파일입니다. DWG 파일에는 다양한 개체가 있습니다. 다음 섹션에서는 특정 DWG 개체를 이미지로 내보내는 예를 설명합니다.
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); | |
DWG에 텍스트 추가 지원
Aspose.CAD for .NET API는 DWG 형식의 AutoCAD 도면을 로드하고 다양한 개체를 지원하여 작업할 수 있습니다. DWG는 벡터 이미지 데이터와 메타데이터를 포함하는 이진 파일입니다. DWG 파일에는 다양한 개체가 있습니다. 다음 섹션에서는 DWG 파일 내에 텍스트를 추가하는 방법을 설명합니다.
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.PageHeight = 1600; | |
cadRasterizationOptions.PageWidth = 1600; | |
cadRasterizationOptions.Layouts = new string[] { "Model" }; | |
image.Save(MyDir+"SimpleEntites_generated.pdf", pdfOptions); | |
} | |
DWG 파일에 이미지 가져오기 지원
Aspose.CAD for .NET API는 DWG 형식의 AutoCAD 도면을 로드하고 다양한 개체를 지원하여 작업할 수 있습니다. DWG는 벡터 이미지 데이터와 메타데이터를 포함하는 이진 파일입니다. DWG 파일에는 다양한 개체가 있습니다. 다음 섹션에서는 DWG 파일 내에 이미지를 가져오는 방법을 설명합니다.
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-.NET | |
string dwgPathToFile = MyDir + "Drawing11.dwg"; | |
CadImage cadImage1 = (CadImage)Image.Load(dwgPathToFile); | |
CadRasterImageDef cadRasterImageDef = new CadRasterImageDef("road-sign-custom.png", 640, 562); | |
cadRasterImageDef.ObjectHandle = "A3B4"; | |
Cad3DPoint insertionPoint = new Cad3DPoint(26.77, 22.35); | |
Cad3DPoint uVector = new Cad3DPoint(0.0061565450840500831, 0); | |
Cad3DPoint vVector = new Cad3DPoint(0, 0.0061565450840500822); | |
CadRasterImage cadRasterImage = new CadRasterImage(cadRasterImageDef, insertionPoint, uVector, vVector); | |
cadRasterImage.ImageDefReference = "A3B4"; | |
cadRasterImage.DisplayFlags = 7; | |
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.PageHeight = 1600; | |
cadRasterizationOptions.PageWidth = 1600; | |
cadRasterizationOptions.Layouts = new string[] { "Model" }; | |
cadImage1.Save(MyDir + "export2.pdf", pdfOptions); |
DWG에서 메시 지원
Aspose.CAD for .NET API는 이제 CadPolyFaceMesh 및 CadPolygonMesh 유형을 포함한 메시를 지원하는 엔티티에 접근할 수 있습니다. 다음 예제는 메시 유형에 접근하는 방법을 설명합니다.
// 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); | |
} | |
} | |
} | |
} |
DWG 도면을 DXF로 변환하기
Aspose.CAD는 AutoCAD DWG 파일을 로드하고 DXF 형식으로 내보내는 기능을 제공합니다. DWG에서 DXF로 변환하는 방법은 다음과 같습니다:
- Image.Load 팩토리 메서드를 사용하여 DWG 도면 파일을 로드합니다.
- Image.Save() 메서드를 사용하여 DWG 도면을 DXF로 내보냅니다.
아래 코드 샘플은 DWG 파일을 DXF 형식으로 변환하는 방법을 보여줍니다.
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); | |
} | |
DWG 도면을 SVG로 변환하기
Aspose.CAD for .NET API는 DWG 형식의 AutoCAD 도면을 로드하고 이를 SVG로 변환할 수 있습니다. 이 주제에서는 간단한 단계를 통해 DWG를 SVG 형식으로 변환하는 Aspose.CAD API의 사용법을 설명합니다.
- Image 인스턴스에 DWG 파일을 로드합니다.
- SvgOptions 클래스의 객체를 생성하고 필요한 속성을 설정합니다.
- Image.Save() 메서드를 사용하여 DWG 도면을 SVG로 내보냅니다.
아래 코드 샘플은 DWG 파일을 SVG 형식으로 변환하는 방법을 보여줍니다.
// 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"); | |
} |
대형 DWG 파일 로드하기
Aspose.CAD for .NET은 Image 클래스를 사용하여 매우 큰 DWG 파일을 열 수 있는 기능을 제공합니다. 이제 아래의 샘플 코드를 통해 대형 파일을 쉽게 열 수 있습니다.
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DWGDrawings(); | |
string filePathDWG = MyDir + "TestBigFile.dwg"; | |
string filePathFinish = MyDir+ "TestBigFile.dwg.pdf"; | |
Stopwatch stopWatch = new Stopwatch(); | |
try | |
{ | |
stopWatch.Start(); | |
using (CadImage cadImage = (CadImage)Image.Load(filePathDWG)) | |
{ | |
stopWatch.Stop(); | |
// Get the elapsed time as a TimeSpan value. | |
TimeSpan ts = stopWatch.Elapsed; | |
// Format and display the TimeSpan value. | |
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", | |
ts.Hours, ts.Minutes, ts.Seconds, | |
ts.Milliseconds / 10); | |
Console.WriteLine("RunTime for loading " + elapsedTime); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
stopWatch = new Stopwatch(); | |
stopWatch.Start(); | |
cadImage.Save(filePathFinish, pdfOptions); | |
stopWatch.Stop(); | |
// Get the elapsed time as a TimeSpan value. | |
ts = stopWatch.Elapsed; | |
// Format and display the TimeSpan value. | |
elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", | |
ts.Hours, ts.Minutes, ts.Seconds, | |
ts.Milliseconds / 10); | |
Console.WriteLine("RunTime for converting " + elapsedTime); | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |