DWG 파일 읽기, 업데이트 및 쓰기
Contents
[
Hide
]DWG 파일 읽기, 업데이트 및 쓰기 방법
문제: DWG 파일을 읽고, 업데이트하며 쓰는 방법.
팁: 이를 위해 load 메소드를 사용하여 파일을 가져오고, 필요한 엔티티를 가져와서 시작 및 끝 점이나 선의 두께와 같은 변경을 할 수 있습니다.
참고: 이 코드 스니펫은 dwg 파일을 읽고 객체를 변경하는 예를 보여줍니다: 선, 원, 텍스트 값의 위치 (읽기/쓰기가 지원되는 다른 객체 및 해당 값에 대한 변경을 추가할 수 있음) 그리고 새 파일에 저장합니다. 그러므로 AutoCAD에서 새 파일을 열고 변경된 값의 객체를 볼 수 있습니다.
예제:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fileName = "TestDwg"; | |
var inputFile = BaseDataPath + fileName + ".dwg"; | |
var outFile = GetFileInOutputFolder(fileName + "-rewritten.dwg"); | |
using var cadImage = (CadImage) Image.Load(inputFile); | |
var cadLines = cadImage.Entities.OfType<CadLine>().ToList(); | |
if (cadLines.Any()) | |
{ | |
foreach (var cadLine in cadLines) | |
{ | |
cadLine.FirstPoint.X *= 2; | |
cadLine.FirstPoint.Y *= 2; | |
cadLine.SecondPoint.X *= 3; | |
cadLine.SecondPoint.Y *= 3; | |
} | |
} | |
var cadCircles = cadImage.Entities.OfType<CadCircle>().ToList(); | |
if (cadCircles.Any()) | |
{ | |
foreach (var cadCircle in cadCircles) | |
{ | |
cadCircle.CenterPoint.X *= 1.5; | |
cadCircle.CenterPoint.Y *= 1.5; | |
cadCircle.Radius *= 0.5; | |
} | |
} | |
var cadTexts = cadImage.Entities.OfType<CadText>().ToList(); | |
if (cadTexts.Any()) | |
{ | |
foreach (var cadText in cadTexts) | |
{ | |
cadText.DefaultValue = $"New {cadText.DefaultValue}"; | |
} | |
} | |
cadImage.Save(outFile); |