| | | 1 | | using System; |
| | | 2 | | using System.Diagnostics; |
| | | 3 | | using System.Linq; |
| | | 4 | | using System.Windows.Forms; |
| | | 5 | | |
| | | 6 | | namespace SolidEdgeCommunity.Extensions; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// SolidEdgeFramework.Application extension methods. |
| | | 10 | | /// </summary> |
| | | 11 | | public static class ApplicationExtensions |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Creates a Solid Edge command control. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="application"></param> |
| | | 17 | | /// <param name="CmdFlags"></param> |
| | | 18 | | public static Command CreateCommand(this Application application, seCmdFlag CmdFlags) |
| | 0 | 19 | | => application.CreateCommand((int)CmdFlags); |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Returns the currently active document. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <remarks>An exception will be thrown if there is no active document.</remarks> |
| | 1 | 25 | | public static SolidEdgeDocument GetActiveDocument(this Application application) => application.GetActiveDocument(tru |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Returns the currently active document. |
| | | 29 | | /// </summary> |
| | | 30 | | public static SolidEdgeDocument GetActiveDocument(this Application application, bool throwOnError) |
| | | 31 | | { |
| | | 32 | | try |
| | | 33 | | { |
| | | 34 | | // ActiveDocument will throw an exception if no document is open. |
| | 3 | 35 | | return (SolidEdgeDocument)application.ActiveDocument; |
| | | 36 | | } |
| | 2 | 37 | | catch when (!throwOnError) |
| | | 38 | | { |
| | 1 | 39 | | } |
| | | 40 | | |
| | 1 | 41 | | return null; |
| | 1 | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Returns the currently active document. |
| | | 46 | | /// </summary> |
| | | 47 | | /// <typeparam name="T">The type to return.</typeparam> |
| | | 48 | | /// /// <remarks>An exception will be thrown if there is no active document or if the cast fails.</remarks> |
| | 1 | 49 | | public static T GetActiveDocument<T>(this Application application) where T : class => application.GetActiveDocument< |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Returns the currently active document. |
| | | 53 | | /// </summary> |
| | | 54 | | /// <typeparam name="T">The type to return.</typeparam> |
| | | 55 | | public static T GetActiveDocument<T>(this Application application, bool throwOnError) where T : class |
| | | 56 | | { |
| | | 57 | | try |
| | | 58 | | { |
| | | 59 | | // ActiveDocument will throw an exception if no document is open. |
| | 2 | 60 | | return (T)application.ActiveDocument; |
| | | 61 | | } |
| | 1 | 62 | | catch when (!throwOnError) |
| | | 63 | | { |
| | 1 | 64 | | } |
| | | 65 | | |
| | 1 | 66 | | return null; |
| | 1 | 67 | | } |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Returns the environment that belongs to the current active window of the document. |
| | | 71 | | /// </summary> |
| | | 72 | | public static Environment GetActiveEnvironment(this Application application) |
| | | 73 | | { |
| | 1 | 74 | | Environments environments = application.Environments; |
| | 1 | 75 | | return environments.Item(application.ActiveEnvironment); |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | ///// <summary> |
| | | 79 | | ///// Returns the application events. |
| | | 80 | | ///// </summary> |
| | | 81 | | //public static SolidEdgeFramework.ISEApplicationEvents_Event GetApplicationEvents(this SolidEdgeFramework.Applicati |
| | | 82 | | //{ |
| | | 83 | | // return (SolidEdgeFramework.ISEApplicationEvents_Event)application.ApplicationEvents; |
| | | 84 | | //} |
| | | 85 | | |
| | | 86 | | ///// <summary> |
| | | 87 | | ///// Returns the application window events. |
| | | 88 | | ///// </summary> |
| | | 89 | | //public static SolidEdgeFramework.ISEApplicationWindowEvents_Event GetApplicationWindowEvents(this SolidEdgeFramewo |
| | | 90 | | //{ |
| | | 91 | | // return (SolidEdgeFramework.ISEApplicationWindowEvents_Event)application.ApplicationWindowEvents; |
| | | 92 | | //} |
| | | 93 | | |
| | | 94 | | /// <summary> |
| | | 95 | | /// Returns an environment specified by CATID. |
| | | 96 | | /// </summary> |
| | | 97 | | public static Environment GetEnvironment(this Application application, string CATID) |
| | | 98 | | { |
| | 2 | 99 | | var guid1 = new Guid(CATID); |
| | 2 | 100 | | var environments = application.Environments; |
| | | 101 | | |
| | 6 | 102 | | for (int i = 1; i <= environments.Count; i++) |
| | | 103 | | { |
| | 2 | 104 | | var environment = environments.Item(i); |
| | 2 | 105 | | var guid2 = new Guid(environment.CATID); |
| | | 106 | | |
| | 2 | 107 | | if (guid1.Equals(guid2)) |
| | | 108 | | { |
| | 1 | 109 | | return environment; |
| | | 110 | | } |
| | | 111 | | } |
| | | 112 | | |
| | 1 | 113 | | return null; |
| | | 114 | | } |
| | | 115 | | |
| | | 116 | | ///// <summary> |
| | | 117 | | ///// Returns the feature library events. |
| | | 118 | | ///// </summary> |
| | | 119 | | //public static SolidEdgeFramework.ISEFeatureLibraryEvents_Event GetFeatureLibraryEvents(this SolidEdgeFramework.App |
| | | 120 | | //{ |
| | | 121 | | // return (SolidEdgeFramework.ISEFeatureLibraryEvents_Event)application.FeatureLibraryEvents; |
| | | 122 | | //} |
| | | 123 | | |
| | | 124 | | ///// <summary> |
| | | 125 | | ///// Returns the file UI events. |
| | | 126 | | ///// </summary> |
| | | 127 | | //public static SolidEdgeFramework.ISEFileUIEvents_Event GetFileUIEvents(this SolidEdgeFramework.Application applica |
| | | 128 | | //{ |
| | | 129 | | // return (SolidEdgeFramework.ISEFileUIEvents_Event)application.FileUIEvents; |
| | | 130 | | //} |
| | | 131 | | |
| | | 132 | | /// <summary> |
| | | 133 | | /// Returns the value of a specified global constant. |
| | | 134 | | /// </summary> |
| | | 135 | | public static object GetGlobalParameter(this Application application, ApplicationGlobalConstants globalConstant) |
| | | 136 | | { |
| | 1 | 137 | | object value = null; |
| | 1 | 138 | | application.GetGlobalParameter(globalConstant, ref value); |
| | 1 | 139 | | return value; |
| | | 140 | | } |
| | | 141 | | |
| | | 142 | | /// <summary> |
| | | 143 | | /// Returns the value of a specified global constant. |
| | | 144 | | /// </summary> |
| | | 145 | | /// <typeparam name="T">The type to return.</typeparam> |
| | | 146 | | public static T GetGlobalParameter<T>(this Application application, ApplicationGlobalConstants globalConstant) |
| | | 147 | | { |
| | 1 | 148 | | object value = null; |
| | 1 | 149 | | application.GetGlobalParameter(globalConstant, ref value); |
| | 1 | 150 | | return (T)value; |
| | | 151 | | } |
| | | 152 | | |
| | | 153 | | /// <summary> |
| | | 154 | | /// Returns a NativeWindow object that represents the main application window. |
| | | 155 | | /// </summary> |
| | 1 | 156 | | public static NativeWindow GetNativeWindow(this Application application) => NativeWindow.FromHandle(new IntPtr(appli |
| | | 157 | | |
| | | 158 | | ///// <summary> |
| | | 159 | | ///// Returns the new file UI events. |
| | | 160 | | ///// </summary> |
| | | 161 | | //public static SolidEdgeFramework.ISENewFileUIEvents_Event GetNewFileUIEvents(this SolidEdgeFramework.Application a |
| | | 162 | | //{ |
| | | 163 | | // return (SolidEdgeFramework.ISENewFileUIEvents_Event)application.NewFileUIEvents; |
| | | 164 | | //} |
| | | 165 | | |
| | | 166 | | ///// <summary> |
| | | 167 | | ///// Returns the SEEC events. |
| | | 168 | | ///// </summary> |
| | | 169 | | //public static SolidEdgeFramework.ISEECEvents_Event GetSEECEvents(this SolidEdgeFramework.Application application) |
| | | 170 | | //{ |
| | | 171 | | // return (SolidEdgeFramework.ISEECEvents_Event)application.SEECEvents; |
| | | 172 | | //} |
| | | 173 | | |
| | | 174 | | /// <summary> |
| | | 175 | | /// Returns a Process object that represents the application process. |
| | | 176 | | /// </summary> |
| | 1 | 177 | | public static Process GetProcess(this Application application) => Process.GetProcessById(application.ProcessID); |
| | | 178 | | |
| | | 179 | | ///// <summary> |
| | | 180 | | ///// Returns the shortcut menu events. |
| | | 181 | | ///// </summary> |
| | | 182 | | //public static SolidEdgeFramework.ISEShortCutMenuEvents_Event GetShortcutMenuEvents(this SolidEdgeFramework.Applica |
| | | 183 | | //{ |
| | | 184 | | // return (SolidEdgeFramework.ISEShortCutMenuEvents_Event)application.ShortcutMenuEvents; |
| | | 185 | | //} |
| | | 186 | | |
| | | 187 | | /// <summary> |
| | | 188 | | /// Returns a Version object that represents the application version. |
| | | 189 | | /// </summary> |
| | 1 | 190 | | public static Version GetVersion(this Application application) => new(application.Version); |
| | | 191 | | |
| | | 192 | | /// <summary> |
| | | 193 | | /// Returns a point object to the application main window. |
| | | 194 | | /// </summary> |
| | 1 | 195 | | public static IntPtr GetWindowHandle(this Application application) => new(application.hWnd); |
| | | 196 | | |
| | | 197 | | /// <summary> |
| | | 198 | | /// Activates a specified Solid Edge command. |
| | | 199 | | /// </summary> |
| | | 200 | | public static void StartCommand(this Application application, AssemblyCommandConstants CommandID) |
| | 1 | 201 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 202 | | |
| | | 203 | | /// <summary> |
| | | 204 | | /// Activates a specified Solid Edge command. |
| | | 205 | | /// </summary> |
| | | 206 | | public static void StartCommand(this Application application, CuttingPlaneLineCommandConstants CommandID) |
| | 1 | 207 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 208 | | |
| | | 209 | | /// <summary> |
| | | 210 | | /// Activates a specified Solid Edge command. |
| | | 211 | | /// </summary> |
| | | 212 | | public static void StartCommand(this Application application, DetailCommandConstants CommandID) |
| | 1 | 213 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 214 | | |
| | | 215 | | /// <summary> |
| | | 216 | | /// Activates a specified Solid Edge command. |
| | | 217 | | /// </summary> |
| | | 218 | | public static void StartCommand(this Application application, DrawingViewEditCommandConstants CommandID) |
| | 1 | 219 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 220 | | |
| | | 221 | | /// <summary> |
| | | 222 | | /// Activates a specified Solid Edge command. |
| | | 223 | | /// </summary> |
| | | 224 | | public static void StartCommand(this Application application, ExplodeCommandConstants CommandID) |
| | 1 | 225 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 226 | | |
| | | 227 | | /// <summary> |
| | | 228 | | /// Activates a specified Solid Edge command. |
| | | 229 | | /// </summary> |
| | | 230 | | public static void StartCommand(this Application application, LayoutCommandConstants CommandID) |
| | 1 | 231 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 232 | | |
| | | 233 | | /// <summary> |
| | | 234 | | /// Activates a specified Solid Edge command. |
| | | 235 | | /// </summary> |
| | | 236 | | public static void StartCommand(this Application application, LayoutInPartCommandConstants CommandID) |
| | 1 | 237 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 238 | | |
| | | 239 | | /// <summary> |
| | | 240 | | /// Activates a specified Solid Edge command. |
| | | 241 | | /// </summary> |
| | | 242 | | public static void StartCommand(this Application application, MotionCommandConstants CommandID) |
| | 1 | 243 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 244 | | |
| | | 245 | | /// <summary> |
| | | 246 | | /// Activates a specified Solid Edge command. |
| | | 247 | | /// </summary> |
| | | 248 | | public static void StartCommand(this Application application, PartCommandConstants CommandID) |
| | 1 | 249 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 250 | | |
| | | 251 | | /// <summary> |
| | | 252 | | /// Activates a specified Solid Edge command. |
| | | 253 | | /// </summary> |
| | | 254 | | public static void StartCommand(this Application application, ProfileCommandConstants CommandID) |
| | 1 | 255 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 256 | | |
| | | 257 | | /// <summary> |
| | | 258 | | /// Activates a specified Solid Edge command. |
| | | 259 | | /// </summary> |
| | | 260 | | public static void StartCommand(this Application application, ProfileHoleCommandConstants CommandID) |
| | 1 | 261 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 262 | | |
| | | 263 | | /// <summary> |
| | | 264 | | /// Activates a specified Solid Edge command. |
| | | 265 | | /// </summary> |
| | | 266 | | public static void StartCommand(this Application application, ProfilePatternCommandConstants CommandID) |
| | 1 | 267 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 268 | | |
| | | 269 | | /// <summary> |
| | | 270 | | /// Activates a specified Solid Edge command. |
| | | 271 | | /// </summary> |
| | | 272 | | public static void StartCommand(this Application application, ProfileRevolvedCommandConstants CommandID) |
| | 1 | 273 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 274 | | |
| | | 275 | | /// <summary> |
| | | 276 | | /// Activates a specified Solid Edge command. |
| | | 277 | | /// </summary> |
| | | 278 | | public static void StartCommand(this Application application, SheetMetalCommandConstants CommandID) |
| | 1 | 279 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 280 | | |
| | | 281 | | /// <summary> |
| | | 282 | | /// Activates a specified Solid Edge command. |
| | | 283 | | /// </summary> |
| | | 284 | | public static void StartCommand(this Application application, SimplifyCommandConstants CommandID) |
| | 1 | 285 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 286 | | |
| | | 287 | | /// <summary> |
| | | 288 | | /// Activates a specified Solid Edge command. |
| | | 289 | | /// </summary> |
| | | 290 | | public static void StartCommand(this Application application, SolidEdgeConstants.SolidEdgeCommandConstants CommandID |
| | 0 | 291 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 292 | | |
| | | 293 | | /// <summary> |
| | | 294 | | /// Activates a specified Solid Edge command. |
| | | 295 | | /// </summary> |
| | | 296 | | public static void StartCommand(this Application application, StudioCommandConstants CommandID) |
| | 1 | 297 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 298 | | |
| | | 299 | | /// <summary> |
| | | 300 | | /// Activates a specified Solid Edge command. |
| | | 301 | | /// </summary> |
| | | 302 | | public static void StartCommand(this Application application, TubingCommandConstants CommandID) |
| | 1 | 303 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 304 | | |
| | | 305 | | /// <summary> |
| | | 306 | | /// Activates a specified Solid Edge command. |
| | | 307 | | /// </summary> |
| | | 308 | | public static void StartCommand(this Application application, WeldmentCommandConstants CommandID) |
| | 1 | 309 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 310 | | |
| | | 311 | | /// <summary> |
| | | 312 | | /// Activates a specified Solid Edge command. |
| | | 313 | | /// </summary> |
| | | 314 | | public static void StartCommand(this Application application, SolidEdgeCommandConstants CommandID) |
| | 0 | 315 | | => application.StartCommand((SolidEdgeCommandConstants)CommandID); |
| | | 316 | | |
| | | 317 | | /// <summary> |
| | | 318 | | /// Shows the form with the application main window as the owner. |
| | | 319 | | /// </summary> |
| | | 320 | | public static void Show(this Application application, Form form) |
| | | 321 | | { |
| | 0 | 322 | | ArgumentNullException.ThrowIfNull(form); |
| | | 323 | | |
| | 0 | 324 | | form.Show(application.GetNativeWindow()); |
| | 0 | 325 | | } |
| | | 326 | | |
| | | 327 | | /// <summary> |
| | | 328 | | /// Shows the form as a modal dialog box with the application main window as the owner. |
| | | 329 | | /// </summary> |
| | | 330 | | public static DialogResult ShowDialog(this Application application, Form form) |
| | 0 | 331 | | => form == null ? throw new ArgumentNullException(nameof(form)) : form.ShowDialog(application.GetNativeWindow()) |
| | | 332 | | |
| | | 333 | | /// <summary> |
| | | 334 | | /// Shows the form as a modal dialog box with the application main window as the owner. |
| | | 335 | | /// </summary> |
| | | 336 | | public static DialogResult ShowDialog(this Application application, CommonDialog dialog) |
| | 1 | 337 | | => dialog == null ? throw new ArgumentNullException(nameof(dialog)) : dialog.ShowDialog(application.GetNativeWin |
| | | 338 | | } |