Author Topic: AutoCAD 2013: encoding of Document.Editor output  (Read 1556 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
AutoCAD 2013: encoding of Document.Editor output
« on: March 28, 2013, 07:04:30 AM »
Windows 7 x64, AutoCAD 2013 SP1.1.
This problem are exists in AutoCAD 2013 only (look the screen below). In the AutoCAD 2009-2012 it works fine.
Code - C#: [Select]
  1.             String _args = sb.ToString();
  2.             String exeName = new FileInfo(Path.Combine(curDir, @"..\..\recovery")).FullName;
  3.             Process proc = new Process();
  4.             ProcessStartInfo info = new ProcessStartInfo();
  5.             info.CreateNoWindow = true;
  6.             info.RedirectStandardOutput = true;
  7.             info.UseShellExecute = false;
  8.             Int32 codepage = CultureInfo.CurrentCulture.TextInfo.OEMCodePage;
  9.             info.StandardOutputEncoding = Encoding.GetEncoding(codepage);
  10.             info.FileName = exeName;
  11.             info.Arguments = String.Format("{0} -clear", _args);
  12.             info.WorkingDirectory = new DirectoryInfo(Path.Combine(curDir, @"..\..\")).FullName;
  13.             proc.StartInfo = info;
  14.  
  15.             proc.Start();
  16.  
  17.             String outputText = String.Empty;
  18.  
  19. #if acad2013
  20.             Encoding enc = Encoding.Unicode; // What encoding I must point here?
  21.             Int32 b;
  22.             List<Byte> bytes = new List<Byte>();
  23.             while ((b = proc.StandardOutput.BaseStream.ReadByte()) != -1)
  24.                 bytes.Add((Byte) b);
  25.             Byte[] bytes2 = Encoding.Convert(Encoding.GetEncoding(codepage), enc, bytes.ToArray());
  26.             outputText = enc.GetString(bytes2);
  27. #else
  28.             outputText = proc.StandardOutput.ReadToEnd();
  29. #endif
  30.  
  31.             if (doc != null) {
  32.                 if (printMsg) {
  33.                     doc.Editor.WriteMessage(outputText);
  34.                     doc.Editor.WriteMessage(Environment.NewLine);
  35.                     doc.Editor.WriteMessage("&#1054;&#1087;&#1077;&#1088;&#1072;&#1094;&#1080;&#1103; &#1079;&#1072;&#1074;&#1077;&#1088;&#1096;&#1077;&#1085;&#1072;."); // Operation is complete (ru-RU)
  36.                     doc.Editor.WriteMessage(Environment.NewLine);
  37.                 }
  38.             }
  39.  
In the AutoCAD 2013 the result looks so (look attached screen below)...

I have tried to look all encodings results:
Code - C#: [Select]
  1. Int32 b;
  2. List<Byte> bytes = new List<Byte>();
  3. while ((b = proc.StandardOutput.BaseStream.ReadByte()) != -1)
  4.     bytes.Add((Byte) b);
  5. // Look for each encoding...
  6. // I look in parts
  7. Int32 skip = 120; // I have tried the next values: 0, 20, 40, 60, ..., 120
  8. Int32 take = 20;
  9. Int32 count = Encoding.GetEncodings().Length; // 140
  10.  
  11. foreach (EncodingInfo item in Encoding.GetEncodings().Skip(skip).Take(take)) {
  12.     Encoding x = item.GetEncoding();
  13.     Byte[] bytes2 = Encoding.Convert(Encoding.GetEncoding(codepage), x, bytes.ToArray());
  14.     outputText = x.GetString(bytes2);
  15.     if (doc != null) {
  16.         if (printMsg) {                        
  17.             doc.Editor.WriteMessage("\nEncoding: {0}, CodePage = {1}\n", x.EncodingName, x.CodePage);
  18.             doc.Editor.WriteMessage(outputText);
  19.             doc.Editor.WriteMessage(Environment.NewLine);
  20.             doc.Editor.WriteMessage(new String('*', 20));                        
  21.         }
  22.     }
  23. }
  24.  
But I receive incorrect result always. :(
Where is the problem?
« Last Edit: March 28, 2013, 07:48:22 AM by Andrey »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: AutoCAD 2013: encoding of Document.Editor output
« Reply #1 on: March 28, 2013, 09:18:47 AM »
I found the reason of problem:
Code - C#: [Select]
  1.             String _args = sb.ToString();
  2.             String exeName = new FileInfo(Path.Combine(curDir, @"..\..\recovery")).FullName;
  3.             Process proc = new Process();
  4.             ProcessStartInfo info = new ProcessStartInfo();
  5.             info.CreateNoWindow = true;
  6.             info.RedirectStandardOutput = true;
  7.             info.UseShellExecute = false;
  8. #if acad2013
  9.             Int32 codepage = 866; /* The CultureInfo.CurrentCulture.TextInfo.OEMCodePage in the
  10.                                    * AutoCAD 2013 Enu returns 437 (OEM United States). It is
  11.                                    * invalid encoding. */
  12. #else
  13.             Int32 codepage = CultureInfo.CurrentCulture.TextInfo.OEMCodePage;//866 (Cyrillic (DOS))
  14. #endif
  15.             info.StandardOutputEncoding = Encoding.GetEncoding(codepage);
  16.             info.FileName = exeName;
  17.             info.Arguments = String.Format("{0} -clear", _args);
  18.             info.WorkingDirectory = new DirectoryInfo(Path.Combine(curDir, @"..\..\")).FullName;
  19.             proc.StartInfo = info;
  20.             Encoding enc2 = Encoding.GetEncoding(866);
  21.             proc.Start();
  22.  
  23.             String outputText = String.Empty;
  24.             outputText = proc.StandardOutput.ReadToEnd();
  25.  
  26.             if (doc != null) {
  27.                 if (printMsg) {
  28.                     doc.Editor.WriteMessage(outputText);
  29.                     doc.Editor.WriteMessage(Environment.NewLine);
  30.                     doc.Editor.WriteMessage("&#1054;&#1087;&#1077;&#1088;&#1072;&#1094;&#1080;&#1103; &#1079;&#1072;&#1074;&#1077;&#1088;&#1096;&#1077;&#1085;&#1072;."); // Operation is complete (ru-RU)
  31.                     doc.Editor.WriteMessage(Environment.NewLine);
  32.                 }
  33.             }
  34.  
Problem is solved
« Last Edit: March 28, 2013, 09:21:55 AM by Andrey »