@@ -24,6 +24,19 @@ public void EmptyDwgToDxf()
2424 this . writeDxfFile ( pathOut , doc , true ) ;
2525 }
2626
27+ [ Theory ]
28+ [ MemberData ( nameof ( DwgFilePaths ) ) ]
29+ public void DwgToDwg ( string test )
30+ {
31+ CadDocument doc = DwgReader . Read ( test ) ;
32+
33+ string file = Path . GetFileNameWithoutExtension ( test ) ;
34+ string pathOut = Path . Combine ( _samplesOutFolder , $ "{ file } _out.dwg") ;
35+
36+ //accoreconsole always fails because cannot recover the file
37+ this . writeDwgFile ( pathOut , doc , false ) ;
38+ }
39+
2740 [ Theory ]
2841 [ MemberData ( nameof ( DwgFilePaths ) ) ]
2942 public void DwgToDxf ( string test )
@@ -48,7 +61,28 @@ public void DxfToDxf(string test)
4861
4962 [ Theory ]
5063 [ MemberData ( nameof ( DwgFilePaths ) ) ]
51- public void DwgEntitiesToNewFile ( string test )
64+ public void DwgEntitiesToDwgFile ( string test )
65+ {
66+ CadDocument doc = DwgReader . Read ( test ) ;
67+
68+ CadDocument transfer = new CadDocument ( ) ;
69+ transfer . Header . Version = doc . Header . Version ;
70+
71+ List < Entity > entities = new List < Entity > ( doc . Entities ) ;
72+ foreach ( var item in entities )
73+ {
74+ Entity e = doc . Entities . Remove ( item ) ;
75+ transfer . Entities . Add ( e ) ;
76+ }
77+
78+ string file = Path . GetFileNameWithoutExtension ( test ) ;
79+ string pathOut = Path . Combine ( _samplesOutFolder , $ "{ file } _moved_out.dwg") ;
80+ this . writeDwgFile ( pathOut , transfer , false ) ;
81+ }
82+
83+ [ Theory ]
84+ [ MemberData ( nameof ( DwgFilePaths ) ) ]
85+ public void DwgEntitiesToDxfFile ( string test )
5286 {
5387 CadDocument doc = DwgReader . Read ( test ) ;
5488
@@ -67,6 +101,33 @@ public void DwgEntitiesToNewFile(string test)
67101 this . writeDxfFile ( pathOut , transfer , true ) ;
68102 }
69103
104+ private void writeCadFile ( string file , CadWriterBase writer , bool check )
105+ {
106+ using ( writer )
107+ {
108+ writer . OnNotification += this . onNotification ;
109+ writer . Write ( ) ;
110+ }
111+
112+ if ( check )
113+ this . checkDxfDocumentInAutocad ( Path . GetFullPath ( file ) ) ;
114+ }
115+
116+ private void writeDwgFile ( string file , CadDocument doc , bool check )
117+ {
118+ if ( doc . Header . Version < ACadVersion . AC1014 || doc . Header . Version > ACadVersion . AC1018 )
119+ return ;
120+
121+ using ( DwgWriter writer = new DwgWriter ( file , doc ) )
122+ {
123+ writer . OnNotification += this . onNotification ;
124+ writer . Write ( ) ;
125+ }
126+
127+ if ( check )
128+ this . checkDwgDocumentInAutocad ( Path . GetFullPath ( file ) ) ;
129+ }
130+
70131 private void writeDxfFile ( string file , CadDocument doc , bool check )
71132 {
72133 using ( DxfWriter writer = new DxfWriter ( file , doc , false ) )
@@ -78,5 +139,17 @@ private void writeDxfFile(string file, CadDocument doc, bool check)
78139 if ( check )
79140 this . checkDxfDocumentInAutocad ( Path . GetFullPath ( file ) ) ;
80141 }
142+
143+ private void writeDwgFile ( string file , CadDocument doc )
144+ {
145+ if ( doc . Header . Version > ACadVersion . AC1018 )
146+ return ;
147+
148+ using ( DwgWriter writer = new DwgWriter ( file , doc ) )
149+ {
150+ writer . OnNotification += this . onNotification ;
151+ writer . Write ( ) ;
152+ }
153+ }
81154 }
82155}
0 commit comments