Mit diesem Snippet bekommt man einen String zurück der alle Varianten des Makros auflistet und den dazugehörigen Beschreibungstext.
Der Beschreibungstext wird in einer Sprache angezeigt:
Wenn ??_?? nicht vorhanden dann de_DE sonst andere Sprache (zuerst gefundene). Dies kann in der Methode „EplanCleanMacroDescription“ angepasst werden. hier werden die Sprachenkenner entfernt. Im Screenshot habe ich die Sprache nur zu Testzwecken angegeben… diese wird später nicht angezeigt.
Ich hab den Fall mal vorgesehen, dass die Varianten irgendwann erweitert werden (A-Z).
Verwendung des Snippets: Methoden ins Projekt kopieren.
Beispiel:
1 2 |
string MakroVarianteUndBeschreibung = EplanGetMacroVariantAndDescription(@"C:\test\Beispielmakro.ema"); MessageBox.Show(MakroVarianteUndBeschreibung); |
Wie man sieht enthält der String dann die Informationen der Datei „Beispielmakro.ema“.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
using System.Xml; private string EplanGetMacroVariantAndDescription(string filename) { string FullDescription = string.Empty; string sDescription = string.Empty; string sVariant = string.Empty; XmlReader reader = XmlReader.Create(filename); while (reader.Read()) { // Variante if (reader.Name == "MacroVariant") { if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { // Variante if (reader.Name == "VariantId") { sVariant = reader.Value; sVariant = "Variante " + EplanLinkMacroVariants(sVariant) + "\n"; } // Beschreibung if (reader.Name == "Description") { sDescription = reader.Value; sDescription = EplanCleanMacroDescription(sDescription); } } } // Falls Beschreibung leer: unötigen Zeilenumbruch entfernen string temp = sVariant + sDescription + "\n"; if (temp.EndsWith("\n\n")) { temp = temp.Remove(temp.Length - 2, 1); } // Alle Beschreibungen FullDescription += temp; // Temp-Variablen löschen sVariant = string.Empty; sDescription = string.Empty; } } reader.Close(); // letzten Zeilenumbruch entfernen FullDescription = FullDescription.Remove(FullDescription.Length - 2, 2); return FullDescription; } private string EplanCleanMacroDescription(string description) { string[] slDescriptions = description.Split(';'); foreach (string s in slDescriptions) { if (s.StartsWith("??_??@")) { description = s; break; } else if (s.StartsWith("de_DE@")) { description = s; break; } else { if (!s.Equals("")) { description = s; } } } // Sprachenkenner entfernen if (description.Length >= 6) { description = description.Remove(0, 6); } return description; } private string EplanLinkMacroVariants(string variant) { switch (variant) { case "0": variant = "A"; break; case "1": variant = "B"; break; case "2": variant = "C"; break; case "3": variant = "D"; break; case "4": variant = "E"; break; case "5": variant = "F"; break; case "6": variant = "G"; break; case "7": variant = "H"; break; case "8": variant = "I"; break; case "9": variant = "J"; break; case "10": variant = "K"; break; case "11": variant = "L"; break; case "12": variant = "M"; break; case "13": variant = "N"; break; case "14": variant = "O"; break; case "15": variant = "P"; break; case "16": variant = "Q"; break; case "17": variant = "R"; break; case "18": variant = "S"; break; case "19": variant = "T"; break; case "20": variant = "U"; break; case "21": variant = "V"; break; case "22": variant = "W"; break; case "23": variant = "X"; break; case "24": variant = "Y"; break; case "25": variant = "Z"; break; } return variant; } |