CAD开发:DWG合并,dwg转换为dxf
⼀、需求
有时候由于跨度⼤、数据量⼤,会将数据存储于多个dwg⽂件,⽐如⼀条铁路的设计图纸就存在⼏个甚⾄⼏⼗个dwg⽂件中。如果想合并为⼀个dwg⽂件,⼿动合并太⿇烦,所以就可以采⽤代码合并(不同度带的dwg直接合并没有意义,请⼤家注意)。本⽂使⽤teigha库进⾏编码。
⼆、直接上代码
[csharp]
1. /// <summary>
2. /// dwg⽂件转换为dxf⽂件,多个dwg⽂件合并为⼀个dxf或dwg⽂件
3. /// </summary>
4. /// <param name="pDWGFiles"></param>
5. /// <param name="pOutputFile">dxf或dwg保存路径</param>
6. /// <returns></returns>
7. public static bool MergeDWGFiles(List<string> pDWGFiles,string pOutputFile, DwgVersion pDWGVersion = DwgVersion.AC1024)
8. {
9. if (mRServices == null)
10. {
11. mRServices = new Services();
12. }
13. try
14. {
15. //需求:将多个dwg⽂件合并为⼀个dxf⽂件
16. Database destDB = new Database(false, false);
17. //打开⼀个dwg
18. destDB.ReadDwgFile(pDWGFiles[0], FileOpenMode.OpenForReadAndAllShare, false, string.Empty);
19.
20. for (int i = 1; i < pDWGFiles.Count; i++)
21. {
22. string pdwgFile = pDWGFiles[i];
dxf文件怎么打开23. ObjectIdCollection pObjIDsColl = new ObjectIdCollection();
24. Database srcDB = new Database(false, false);
25. srcDB.ReadDwgFile(pdwgFile, FileOpenMode.OpenForReadAndAllShare, false, string.Empty);
26.
27. TransactionManager srcTMgr = srcDB.TransactionManager;
28. using (Transaction pTransac = srcTMgr.StartTransaction())
29. {
30. BlockTable srcBTable = srcTMgr.GetObject(srcDB.BlockTableId, OpenMode.ForRead) as BlockTable;
31. ObjectId srcModelSpaceId = srcBTable[BlockTableRecord.ModelSpace];
32. BlockTableRecord pBTRecord = srcTMgr.GetObject(srcModelSpaceId, OpenMode.ForRead)
33. IEnumerator pIterator = pBTRecord.GetEnumerator();
34. while (pIterator.MoveNext())
35. {
36. ObjectId objId = (ObjectId)pIterator.Current;
37. pObjIDsColl.Add(objId);
38. //Entity pEntity = pTMgr.GetObject(objId, OpenMode.ForRead) as Entity;
39. }
40.
41. TransactionManager destTMgr = destDB.TransactionManager;
42. using (Transaction destTransac = destTMgr.StartTransaction())
43. {
44. BlockTable destBTable = destTMgr.GetObject(destDB.BlockTableId, OpenMode.ForRead)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论