├── .gitignore ├── LICENSE.md ├── README.md ├── media ├── ExtensionMethodIntellisense.png ├── ExtensionMethods.png ├── Install.png ├── InstallCommandLine.png ├── InstallCommandLineVersion.png └── icon.png └── src ├── QA ├── Program.cs └── QA.csproj ├── SolidEdge.Community.sln └── SolidEdge.Community ├── ConnectionPointController.cs ├── ConnectionPointControllerBase.cs ├── EventSink.cs ├── Extensions ├── ApplicationExtensions.cs ├── Arc3DExtensions.cs ├── AssemblyDocumentExtensions.cs ├── DocumentsExtensions.cs ├── DraftDocumentExtensions.cs ├── DrawingViewExtensions.cs ├── EnvironmentExtensions.cs ├── Line3DExtensions.cs ├── MouseExtensions.cs ├── OccurrenceExtensions.cs ├── PartDocumentExtensions.cs ├── PropertiesExtensions.cs ├── PropertySetsExtensions.cs ├── RefPlanesExtensions.cs ├── SectionExtensions.cs ├── SheetExtensions.cs ├── SheetMetalDocumentExtensions.cs ├── SolidEdgeDocumentExtensions.cs ├── WeldmentDocumentExtensions.cs └── WindowExtensions.cs ├── IsolatedTask.cs ├── IsolatedTaskProxy.cs ├── OleMessageFilter.cs ├── Properties └── AssemblyInfo.cs ├── Runtime └── InteropServices │ ├── ComObject.cs │ └── ComTypes │ └── IDispatch.cs ├── SolidEdge.Community.csproj └── SolidEdgeUtils.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | #build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | #build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | 217 | # Added by Jason Newell 218 | .exe 219 | .dll 220 | /.vs 221 | /src/.vs 222 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Solid Edge Community 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SolidEdge.Community Repostiory 2 | ================ 3 | 4 | This is the central repository for the [SolidEdge.Community](http://www.nuget.org/packages/SolidEdge.Community) NuGet package. 5 | 6 | ### Latest Releases 7 | |Library |Version |Downloads | 8 | |:-----------------|:-----------------|:-----------------| 9 | |**SolidEdge.Community**|[![Nuget count](http://img.shields.io/nuget/v/SolidEdge.Community.svg)](https://www.nuget.org/packages/SolidEdge.Community/)|[![Nuget downloads](http://img.shields.io/nuget/dt/SolidEdge.Community.svg)](https://www.nuget.org/packages/SolidEdge.Community/)| 10 | |**SolidEdge.Community.AddIn**|[![Nuget count](http://img.shields.io/nuget/v/SolidEdge.Community.AddIn.svg)](https://www.nuget.org/packages/SolidEdge.Community.AddIn/)|[![Nuget downloads](http://img.shields.io/nuget/dt/SolidEdge.Community.AddIn.svg)](https://www.nuget.org/packages/SolidEdge.Community.AddIn/)| 11 | 12 | --- 13 | 14 | ## Overview 15 | The core functionality of this package is the SolidEdge.Community.dll. This assembly extends the [Interop.SolidEdge](http://www.nuget.org/packages/Interop.SolidEdge) NuGet package and enhances the development experience. For examples of how to use the package, see the [SolidEdgeCommunity / Samples](https://github.com/SolidEdgeCommunity/Samples) repository. 16 | 17 | ## Documentation 18 | Please refer to the [SolidEdge.Community Wiki](https://github.com/SolidEdgeCommunity/SolidEdge.Community/wiki) for detailed information about the [SolidEdge.Community](http://www.nuget.org/packages/SolidEdge.Community) NuGet package. 19 | -------------------------------------------------------------------------------- /media/ExtensionMethodIntellisense.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SolidEdgeCommunity/SolidEdge.Community/7d7ebcfc1fec4774c46033883c4a52e5edb5f38a/media/ExtensionMethodIntellisense.png -------------------------------------------------------------------------------- /media/ExtensionMethods.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SolidEdgeCommunity/SolidEdge.Community/7d7ebcfc1fec4774c46033883c4a52e5edb5f38a/media/ExtensionMethods.png -------------------------------------------------------------------------------- /media/Install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SolidEdgeCommunity/SolidEdge.Community/7d7ebcfc1fec4774c46033883c4a52e5edb5f38a/media/Install.png -------------------------------------------------------------------------------- /media/InstallCommandLine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SolidEdgeCommunity/SolidEdge.Community/7d7ebcfc1fec4774c46033883c4a52e5edb5f38a/media/InstallCommandLine.png -------------------------------------------------------------------------------- /media/InstallCommandLineVersion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SolidEdgeCommunity/SolidEdge.Community/7d7ebcfc1fec4774c46033883c4a52e5edb5f38a/media/InstallCommandLineVersion.png -------------------------------------------------------------------------------- /media/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SolidEdgeCommunity/SolidEdge.Community/7d7ebcfc1fec4774c46033883c4a52e5edb5f38a/media/icon.png -------------------------------------------------------------------------------- /src/QA/Program.cs: -------------------------------------------------------------------------------- 1 | using SolidEdgeCommunity; 2 | using System; 3 | 4 | namespace QA 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var application = SolidEdgeUtils.Connect(true); 11 | application.Visible = true; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/QA/QA.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | NET40 5 | 6 | Exe 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/SolidEdge.Community.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2005 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QA", "QA\QA.csproj", "{9D948FED-8E3E-4DA5-8E44-0F6AD7DD46CE}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SolidEdge.Community", "SolidEdge.Community\SolidEdge.Community.csproj", "{49DAFAF3-C18C-4B3D-9006-BBFBFEEBBCB4}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {49DAFAF3-C18C-4B3D-9006-BBFBFEEBBCB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {49DAFAF3-C18C-4B3D-9006-BBFBFEEBBCB4}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {49DAFAF3-C18C-4B3D-9006-BBFBFEEBBCB4}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {49DAFAF3-C18C-4B3D-9006-BBFBFEEBBCB4}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {9D948FED-8E3E-4DA5-8E44-0F6AD7DD46CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {9D948FED-8E3E-4DA5-8E44-0F6AD7DD46CE}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {9D948FED-8E3E-4DA5-8E44-0F6AD7DD46CE}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {9D948FED-8E3E-4DA5-8E44-0F6AD7DD46CE}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {6FBC4A16-50F3-4031-9EB8-663F23A3B1E1} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/ConnectionPointController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices.ComTypes; 5 | using System.Text; 6 | using System.Threading; 7 | 8 | namespace SolidEdgeCommunity 9 | { 10 | /// 11 | /// Default controller that handles connecting\disconnecting to COM events via IConnectionPointContainer and IConnectionPoint interfaces. 12 | /// 13 | public class ConnectionPointController 14 | { 15 | private object _sink; 16 | private Dictionary _connectionPointDictionary = new Dictionary(); 17 | 18 | public ConnectionPointController(object sink) 19 | { 20 | if (sink == null) throw new ArgumentNullException("sink"); 21 | _sink = sink; 22 | } 23 | 24 | /// 25 | /// Establishes a connection between a connection point object and the client's sink. 26 | /// 27 | /// Interface type of the outgoing interface whose connection point object is being requested. 28 | /// An object that implements the IConnectionPointContainer inferface. 29 | public void AdviseSink(object container) where TInterface : class 30 | { 31 | bool lockTaken = false; 32 | 33 | try 34 | { 35 | Monitor.Enter(this, ref lockTaken); 36 | 37 | // Prevent multiple event Advise() calls on same sink. 38 | if (IsSinkAdvised(container)) 39 | { 40 | return; 41 | } 42 | 43 | IConnectionPointContainer cpc = null; 44 | IConnectionPoint cp = null; 45 | int cookie = 0; 46 | 47 | cpc = (IConnectionPointContainer)container; 48 | cpc.FindConnectionPoint(typeof(TInterface).GUID, out cp); 49 | 50 | if (cp != null) 51 | { 52 | cp.Advise(_sink, out cookie); 53 | _connectionPointDictionary.Add(cp, cookie); 54 | } 55 | } 56 | finally 57 | { 58 | if (lockTaken) 59 | { 60 | Monitor.Exit(this); 61 | } 62 | } 63 | } 64 | 65 | /// 66 | /// Determines if a connection between a connection point object and the client's sink is established. 67 | /// 68 | /// An object that implements the IConnectionPointContainer inferface. 69 | public bool IsSinkAdvised(object container) where TInterface : class 70 | { 71 | bool lockTaken = false; 72 | 73 | try 74 | { 75 | Monitor.Enter(this, ref lockTaken); 76 | 77 | IConnectionPointContainer cpc = null; 78 | IConnectionPoint cp = null; 79 | int cookie = 0; 80 | 81 | cpc = (IConnectionPointContainer)container; 82 | cpc.FindConnectionPoint(typeof(TInterface).GUID, out cp); 83 | 84 | if (cp != null) 85 | { 86 | if (_connectionPointDictionary.ContainsKey(cp)) 87 | { 88 | cookie = _connectionPointDictionary[cp]; 89 | return true; 90 | } 91 | } 92 | } 93 | finally 94 | { 95 | if (lockTaken) 96 | { 97 | Monitor.Exit(this); 98 | } 99 | } 100 | 101 | return false; 102 | } 103 | 104 | /// 105 | /// Terminates an advisory connection previously established between a connection point object and a client's sink. 106 | /// 107 | /// Interface type of the interface whose connection point object is being requested to be removed. 108 | /// An object that implements the IConnectionPointContainer inferface. 109 | public void UnadviseSink(object container) where TInterface : class 110 | { 111 | bool lockTaken = false; 112 | 113 | try 114 | { 115 | Monitor.Enter(this, ref lockTaken); 116 | 117 | IConnectionPointContainer cpc = null; 118 | IConnectionPoint cp = null; 119 | int cookie = 0; 120 | 121 | cpc = (IConnectionPointContainer)container; 122 | cpc.FindConnectionPoint(typeof(TInterface).GUID, out cp); 123 | 124 | if (cp != null) 125 | { 126 | if (_connectionPointDictionary.ContainsKey(cp)) 127 | { 128 | cookie = _connectionPointDictionary[cp]; 129 | cp.Unadvise(cookie); 130 | _connectionPointDictionary.Remove(cp); 131 | } 132 | } 133 | } 134 | finally 135 | { 136 | if (lockTaken) 137 | { 138 | Monitor.Exit(this); 139 | } 140 | } 141 | } 142 | 143 | /// 144 | /// Terminates all advisory connections previously established. 145 | /// 146 | public void UnadviseAllSinks() 147 | { 148 | bool lockTaken = false; 149 | 150 | try 151 | { 152 | Monitor.Enter(this, ref lockTaken); 153 | Dictionary.Enumerator enumerator = _connectionPointDictionary.GetEnumerator(); 154 | while (enumerator.MoveNext()) 155 | { 156 | enumerator.Current.Key.Unadvise(enumerator.Current.Value); 157 | } 158 | } 159 | finally 160 | { 161 | _connectionPointDictionary.Clear(); 162 | 163 | if (lockTaken) 164 | { 165 | Monitor.Exit(this); 166 | } 167 | } 168 | } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/ConnectionPointControllerBase.cs: -------------------------------------------------------------------------------- 1 | //using System; 2 | //using System.Collections.Generic; 3 | //using System.Linq; 4 | //using System.Runtime.InteropServices.ComTypes; 5 | //using System.Text; 6 | //using System.Threading; 7 | 8 | //namespace SolidEdgeCommunity 9 | //{ 10 | // /// 11 | // /// Controller base class that handles connecting\disconnecting to COM events via IConnectionPointContainer and IConnectionPoint interfaces. 12 | // /// 13 | // public abstract class ConnectionPointControllerBase 14 | // { 15 | // private Dictionary _connectionPointDictionary = new Dictionary(); 16 | 17 | // /// 18 | // /// Establishes a connection between a connection point object and the client's sink. 19 | // /// 20 | // /// Interface type of the outgoing interface whose connection point object is being requested. 21 | // /// An object that implements the IConnectionPointContainer inferface. 22 | // protected void AdviseSink(object container) where TInterface : class 23 | // { 24 | // bool lockTaken = false; 25 | 26 | // try 27 | // { 28 | // Monitor.Enter(this, ref lockTaken); 29 | 30 | // // Prevent multiple event Advise() calls on same sink. 31 | // if (IsSinkAdvised(container)) 32 | // { 33 | // return; 34 | // } 35 | 36 | // IConnectionPointContainer cpc = null; 37 | // IConnectionPoint cp = null; 38 | // int cookie = 0; 39 | 40 | // cpc = (IConnectionPointContainer)container; 41 | // cpc.FindConnectionPoint(typeof(TInterface).GUID, out cp); 42 | 43 | // if (cp != null) 44 | // { 45 | // cp.Advise(this, out cookie); 46 | // _connectionPointDictionary.Add(cp, cookie); 47 | // } 48 | // } 49 | // finally 50 | // { 51 | // if (lockTaken) 52 | // { 53 | // Monitor.Exit(this); 54 | // } 55 | // } 56 | // } 57 | 58 | // /// 59 | // /// Determines if a connection between a connection point object and the client's sink is established. 60 | // /// 61 | // /// An object that implements the IConnectionPointContainer inferface. 62 | // protected bool IsSinkAdvised(object container) where TInterface : class 63 | // { 64 | // bool lockTaken = false; 65 | 66 | // try 67 | // { 68 | // Monitor.Enter(this, ref lockTaken); 69 | 70 | // IConnectionPointContainer cpc = null; 71 | // IConnectionPoint cp = null; 72 | // int cookie = 0; 73 | 74 | // cpc = (IConnectionPointContainer)container; 75 | // cpc.FindConnectionPoint(typeof(TInterface).GUID, out cp); 76 | 77 | // if (cp != null) 78 | // { 79 | // if (_connectionPointDictionary.ContainsKey(cp)) 80 | // { 81 | // cookie = _connectionPointDictionary[cp]; 82 | // return true; 83 | // } 84 | // } 85 | // } 86 | // finally 87 | // { 88 | // if (lockTaken) 89 | // { 90 | // Monitor.Exit(this); 91 | // } 92 | // } 93 | 94 | // return false; 95 | // } 96 | 97 | // /// 98 | // /// Terminates an advisory connection previously established between a connection point object and a client's sink. 99 | // /// 100 | // /// Interface type of the interface whose connection point object is being requested to be removed. 101 | // /// An object that implements the IConnectionPointContainer inferface. 102 | // protected void UnadviseSink(object container) where TInterface : class 103 | // { 104 | // bool lockTaken = false; 105 | 106 | // try 107 | // { 108 | // Monitor.Enter(this, ref lockTaken); 109 | 110 | // IConnectionPointContainer cpc = null; 111 | // IConnectionPoint cp = null; 112 | // int cookie = 0; 113 | 114 | // cpc = (IConnectionPointContainer)container; 115 | // cpc.FindConnectionPoint(typeof(TInterface).GUID, out cp); 116 | 117 | // if (cp != null) 118 | // { 119 | // if (_connectionPointDictionary.ContainsKey(cp)) 120 | // { 121 | // cookie = _connectionPointDictionary[cp]; 122 | // cp.Unadvise(cookie); 123 | // _connectionPointDictionary.Remove(cp); 124 | // } 125 | // } 126 | // } 127 | // finally 128 | // { 129 | // if (lockTaken) 130 | // { 131 | // Monitor.Exit(this); 132 | // } 133 | // } 134 | // } 135 | 136 | // /// 137 | // /// Terminates all advisory connections previously established. 138 | // /// 139 | // protected void UnadviseAllSinks() 140 | // { 141 | // bool lockTaken = false; 142 | 143 | // try 144 | // { 145 | // Monitor.Enter(this, ref lockTaken); 146 | // Dictionary.Enumerator enumerator = _connectionPointDictionary.GetEnumerator(); 147 | // while (enumerator.MoveNext()) 148 | // { 149 | // enumerator.Current.Key.Unadvise(enumerator.Current.Value); 150 | // } 151 | // } 152 | // finally 153 | // { 154 | // _connectionPointDictionary.Clear(); 155 | 156 | // if (lockTaken) 157 | // { 158 | // Monitor.Exit(this); 159 | // } 160 | // } 161 | // } 162 | 163 | // /// 164 | // /// Establishes or terminates a connection between a connection point object and the client's sink. 165 | // /// 166 | // /// Interface type of the interface whose connection point object is being requested to be updated. 167 | // /// An object that implements the IConnectionPointContainer inferface. 168 | // /// Flag indicating whether to advise or unadvise. 169 | // //protected void UpdateSink(object container, bool advise) where TInterface : class 170 | // //{ 171 | // // if (advise) 172 | // // { 173 | // // AdviseSink(container); 174 | // // } 175 | // // else 176 | // // { 177 | // // UnadviseSink(container); 178 | // // } 179 | // //} 180 | // } 181 | //} 182 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/EventSink.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Runtime.InteropServices.ComTypes; 6 | using System.Text; 7 | using System.Threading; 8 | 9 | namespace SolidEdgeCommunity 10 | { 11 | public abstract class EventSink : IDisposable where T : class 12 | { 13 | private IConnectionPoint _connectionPoint; 14 | private int _cookie; 15 | 16 | public EventSink() 17 | { 18 | } 19 | 20 | /// 21 | /// Establishes a connection between a connection point object and the client's sink. 22 | /// 23 | /// An event source that implements IConnectionPointContainer. 24 | public EventSink(object source) 25 | { 26 | // If event source is specified, automatically connect. 27 | Connect(source); 28 | } 29 | 30 | /// 31 | /// 32 | /// 33 | public void Dispose() 34 | { 35 | Dispose(true); 36 | GC.SuppressFinalize(this); 37 | } 38 | 39 | protected virtual void Dispose(bool disposing) 40 | { 41 | if (disposing) 42 | { 43 | // Clean up all managed resources 44 | } 45 | 46 | Disconnect(); 47 | } 48 | 49 | /// 50 | /// Establishes a connection between a connection point object and the client's sink. 51 | /// 52 | /// An event source that implements IConnectionPointContainer. 53 | public void Connect(object source) 54 | { 55 | bool lockTaken = false; 56 | IConnectionPointContainer container = null; 57 | 58 | try 59 | { 60 | Monitor.Enter(this, ref lockTaken); 61 | 62 | // If previous call was made, disconnect existing connection. 63 | if (container != null) 64 | { 65 | Disconnect(); 66 | } 67 | 68 | // QueryInterface for IConnectionPointContainer. 69 | container = (IConnectionPointContainer)source; 70 | 71 | // Find the connection point by the GUID of type T. 72 | container.FindConnectionPoint(typeof(T).GUID, out _connectionPoint); 73 | 74 | if (_connectionPoint != null) 75 | { 76 | // Establish the sink connection. 77 | _connectionPoint.Advise(this, out _cookie); 78 | } 79 | } 80 | finally 81 | { 82 | if (lockTaken) 83 | { 84 | Monitor.Exit(this); 85 | } 86 | } 87 | } 88 | 89 | /// 90 | /// Terminates the advisory connection between a connection point and a client's sink. 91 | /// 92 | public void Disconnect() 93 | { 94 | bool lockTaken = false; 95 | 96 | try 97 | { 98 | Monitor.Enter(this, ref lockTaken); 99 | 100 | if (_connectionPoint != null) 101 | { 102 | // Terminate the sink connection. 103 | _connectionPoint.Unadvise(_cookie); 104 | } 105 | } 106 | finally 107 | { 108 | if (_connectionPoint != null) 109 | { 110 | try 111 | { 112 | var count = Marshal.ReleaseComObject(_connectionPoint); 113 | } 114 | catch 115 | { 116 | } 117 | 118 | _connectionPoint = null; 119 | _cookie = 0; 120 | } 121 | 122 | if (lockTaken) 123 | { 124 | Monitor.Exit(this); 125 | } 126 | } 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/ApplicationExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Windows.Forms; 7 | 8 | namespace SolidEdgeCommunity.Extensions 9 | { 10 | /// 11 | /// SolidEdgeFramework.Application extension methods. 12 | /// 13 | public static class ApplicationExtensions 14 | { 15 | /// 16 | /// Creates a Solid Edge command control. 17 | /// 18 | /// 19 | /// 20 | public static SolidEdgeFramework.Command CreateCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.seCmdFlag CmdFlags) 21 | { 22 | return application.CreateCommand((int)CmdFlags); 23 | } 24 | 25 | /// 26 | /// Returns the currently active document. 27 | /// 28 | /// An exception will be thrown if there is no active document. 29 | public static SolidEdgeFramework.SolidEdgeDocument GetActiveDocument(this SolidEdgeFramework.Application application) 30 | { 31 | return application.GetActiveDocument(true); 32 | } 33 | 34 | /// 35 | /// Returns the currently active document. 36 | /// 37 | public static SolidEdgeFramework.SolidEdgeDocument GetActiveDocument(this SolidEdgeFramework.Application application, bool throwOnError) 38 | { 39 | try 40 | { 41 | // ActiveDocument will throw an exception if no document is open. 42 | return (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument; 43 | } 44 | catch 45 | { 46 | if (throwOnError) throw; 47 | } 48 | 49 | return null; 50 | } 51 | 52 | /// 53 | /// Returns the currently active document. 54 | /// 55 | /// The type to return. 56 | /// /// An exception will be thrown if there is no active document or if the cast fails. 57 | public static T GetActiveDocument(this SolidEdgeFramework.Application application) where T : class 58 | { 59 | return application.GetActiveDocument(true); 60 | } 61 | 62 | /// 63 | /// Returns the currently active document. 64 | /// 65 | /// The type to return. 66 | public static T GetActiveDocument(this SolidEdgeFramework.Application application, bool throwOnError) where T : class 67 | { 68 | try 69 | { 70 | // ActiveDocument will throw an exception if no document is open. 71 | return (T)application.ActiveDocument; 72 | } 73 | catch 74 | { 75 | if (throwOnError) throw; 76 | } 77 | 78 | return null; 79 | } 80 | 81 | /// 82 | /// Returns the environment that belongs to the current active window of the document. 83 | /// 84 | public static SolidEdgeFramework.Environment GetActiveEnvironment(this SolidEdgeFramework.Application application) 85 | { 86 | SolidEdgeFramework.Environments environments = application.Environments; 87 | return environments.Item(application.ActiveEnvironment); 88 | } 89 | 90 | ///// 91 | ///// Returns the application events. 92 | ///// 93 | //public static SolidEdgeFramework.ISEApplicationEvents_Event GetApplicationEvents(this SolidEdgeFramework.Application application) 94 | //{ 95 | // return (SolidEdgeFramework.ISEApplicationEvents_Event)application.ApplicationEvents; 96 | //} 97 | 98 | ///// 99 | ///// Returns the application window events. 100 | ///// 101 | //public static SolidEdgeFramework.ISEApplicationWindowEvents_Event GetApplicationWindowEvents(this SolidEdgeFramework.Application application) 102 | //{ 103 | // return (SolidEdgeFramework.ISEApplicationWindowEvents_Event)application.ApplicationWindowEvents; 104 | //} 105 | 106 | /// 107 | /// Returns an environment specified by CATID. 108 | /// 109 | public static SolidEdgeFramework.Environment GetEnvironment(this SolidEdgeFramework.Application application, string CATID) 110 | { 111 | var guid1 = new Guid(CATID); 112 | 113 | foreach (var environment in application.Environments.OfType()) 114 | { 115 | var guid2 = new Guid(environment.CATID); 116 | if (guid1.Equals(guid2)) 117 | { 118 | return environment; 119 | } 120 | } 121 | 122 | return null; 123 | } 124 | 125 | ///// 126 | ///// Returns the feature library events. 127 | ///// 128 | //public static SolidEdgeFramework.ISEFeatureLibraryEvents_Event GetFeatureLibraryEvents(this SolidEdgeFramework.Application application) 129 | //{ 130 | // return (SolidEdgeFramework.ISEFeatureLibraryEvents_Event)application.FeatureLibraryEvents; 131 | //} 132 | 133 | ///// 134 | ///// Returns the file UI events. 135 | ///// 136 | //public static SolidEdgeFramework.ISEFileUIEvents_Event GetFileUIEvents(this SolidEdgeFramework.Application application) 137 | //{ 138 | // return (SolidEdgeFramework.ISEFileUIEvents_Event)application.FileUIEvents; 139 | //} 140 | 141 | /// 142 | /// Returns the value of a specified global constant. 143 | /// 144 | public static object GetGlobalParameter(this SolidEdgeFramework.Application application, SolidEdgeFramework.ApplicationGlobalConstants globalConstant) 145 | { 146 | object value = null; 147 | application.GetGlobalParameter(globalConstant, ref value); 148 | return value; 149 | } 150 | 151 | /// 152 | /// Returns the value of a specified global constant. 153 | /// 154 | /// The type to return. 155 | public static T GetGlobalParameter(this SolidEdgeFramework.Application application, SolidEdgeFramework.ApplicationGlobalConstants globalConstant) 156 | { 157 | object value = null; 158 | application.GetGlobalParameter(globalConstant, ref value); 159 | return (T)value; 160 | } 161 | 162 | /// 163 | /// Returns a NativeWindow object that represents the main application window. 164 | /// 165 | public static NativeWindow GetNativeWindow(this SolidEdgeFramework.Application application) 166 | { 167 | return NativeWindow.FromHandle(new IntPtr(application.hWnd)); 168 | } 169 | 170 | ///// 171 | ///// Returns the new file UI events. 172 | ///// 173 | //public static SolidEdgeFramework.ISENewFileUIEvents_Event GetNewFileUIEvents(this SolidEdgeFramework.Application application) 174 | //{ 175 | // return (SolidEdgeFramework.ISENewFileUIEvents_Event)application.NewFileUIEvents; 176 | //} 177 | 178 | ///// 179 | ///// Returns the SEEC events. 180 | ///// 181 | //public static SolidEdgeFramework.ISEECEvents_Event GetSEECEvents(this SolidEdgeFramework.Application application) 182 | //{ 183 | // return (SolidEdgeFramework.ISEECEvents_Event)application.SEECEvents; 184 | //} 185 | 186 | /// 187 | /// Returns a Process object that represents the application prcoess. 188 | /// 189 | public static Process GetProcess(this SolidEdgeFramework.Application application) 190 | { 191 | return Process.GetProcessById(application.ProcessID); 192 | } 193 | 194 | ///// 195 | ///// Returns the shortcut menu events. 196 | ///// 197 | //public static SolidEdgeFramework.ISEShortCutMenuEvents_Event GetShortcutMenuEvents(this SolidEdgeFramework.Application application) 198 | //{ 199 | // return (SolidEdgeFramework.ISEShortCutMenuEvents_Event)application.ShortcutMenuEvents; 200 | //} 201 | 202 | /// 203 | /// Returns a Version object that represents the application version. 204 | /// 205 | public static Version GetVersion(this SolidEdgeFramework.Application application) 206 | { 207 | return new Version(application.Version); 208 | } 209 | 210 | /// 211 | /// Returns a point object to the application main window. 212 | /// 213 | public static IntPtr GetWindowHandle(this SolidEdgeFramework.Application application) 214 | { 215 | return new IntPtr(application.hWnd); 216 | } 217 | 218 | /// 219 | /// Activates a specified Solid Edge command. 220 | /// 221 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.AssemblyCommandConstants CommandID) 222 | { 223 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 224 | } 225 | 226 | /// 227 | /// Activates a specified Solid Edge command. 228 | /// 229 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.CuttingPlaneLineCommandConstants CommandID) 230 | { 231 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 232 | } 233 | 234 | /// 235 | /// Activates a specified Solid Edge command. 236 | /// 237 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.DetailCommandConstants CommandID) 238 | { 239 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 240 | } 241 | 242 | /// 243 | /// Activates a specified Solid Edge command. 244 | /// 245 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.DrawingViewEditCommandConstants CommandID) 246 | { 247 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 248 | } 249 | 250 | /// 251 | /// Activates a specified Solid Edge command. 252 | /// 253 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.ExplodeCommandConstants CommandID) 254 | { 255 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 256 | } 257 | 258 | /// 259 | /// Activates a specified Solid Edge command. 260 | /// 261 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.LayoutCommandConstants CommandID) 262 | { 263 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 264 | } 265 | 266 | /// 267 | /// Activates a specified Solid Edge command. 268 | /// 269 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.LayoutInPartCommandConstants CommandID) 270 | { 271 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 272 | } 273 | 274 | /// 275 | /// Activates a specified Solid Edge command. 276 | /// 277 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.MotionCommandConstants CommandID) 278 | { 279 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 280 | } 281 | 282 | /// 283 | /// Activates a specified Solid Edge command. 284 | /// 285 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.PartCommandConstants CommandID) 286 | { 287 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 288 | } 289 | 290 | /// 291 | /// Activates a specified Solid Edge command. 292 | /// 293 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.ProfileCommandConstants CommandID) 294 | { 295 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 296 | } 297 | 298 | /// 299 | /// Activates a specified Solid Edge command. 300 | /// 301 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.ProfileHoleCommandConstants CommandID) 302 | { 303 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 304 | } 305 | 306 | /// 307 | /// Activates a specified Solid Edge command. 308 | /// 309 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.ProfilePatternCommandConstants CommandID) 310 | { 311 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 312 | } 313 | 314 | /// 315 | /// Activates a specified Solid Edge command. 316 | /// 317 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.ProfileRevolvedCommandConstants CommandID) 318 | { 319 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 320 | } 321 | 322 | /// 323 | /// Activates a specified Solid Edge command. 324 | /// 325 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.SheetMetalCommandConstants CommandID) 326 | { 327 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 328 | } 329 | 330 | /// 331 | /// Activates a specified Solid Edge command. 332 | /// 333 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.SimplifyCommandConstants CommandID) 334 | { 335 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 336 | } 337 | 338 | /// 339 | /// Activates a specified Solid Edge command. 340 | /// 341 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.SolidEdgeCommandConstants CommandID) 342 | { 343 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 344 | } 345 | 346 | /// 347 | /// Activates a specified Solid Edge command. 348 | /// 349 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.StudioCommandConstants CommandID) 350 | { 351 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 352 | } 353 | 354 | /// 355 | /// Activates a specified Solid Edge command. 356 | /// 357 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.TubingCommandConstants CommandID) 358 | { 359 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 360 | } 361 | 362 | /// 363 | /// Activates a specified Solid Edge command. 364 | /// 365 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeConstants.WeldmentCommandConstants CommandID) 366 | { 367 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 368 | } 369 | 370 | /// 371 | /// Activates a specified Solid Edge command. 372 | /// 373 | public static void StartCommand(this SolidEdgeFramework.Application application, SolidEdgeFramework.SolidEdgeCommandConstants CommandID) 374 | { 375 | application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)CommandID); 376 | } 377 | 378 | /// 379 | /// Shows the form with the application main window as the owner. 380 | /// 381 | public static void Show(this SolidEdgeFramework.Application application, System.Windows.Forms.Form form) 382 | { 383 | if (form == null) throw new ArgumentNullException("form"); 384 | 385 | form.Show(application.GetNativeWindow()); 386 | } 387 | 388 | /// 389 | /// Shows the form as a modal dialog box with the application main window as the owner. 390 | /// 391 | public static DialogResult ShowDialog(this SolidEdgeFramework.Application application, System.Windows.Forms.Form form) 392 | { 393 | if (form == null) throw new ArgumentNullException("form"); 394 | 395 | return form.ShowDialog(application.GetNativeWindow()); 396 | } 397 | 398 | /// 399 | /// Shows the form as a modal dialog box with the application main window as the owner. 400 | /// 401 | public static DialogResult ShowDialog(this SolidEdgeFramework.Application application, CommonDialog dialog) 402 | { 403 | if (dialog == null) throw new ArgumentNullException("dialog"); 404 | return dialog.ShowDialog(application.GetNativeWindow()); 405 | } 406 | } 407 | } 408 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/Arc3DExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgePart.Arc3D extension methods. 10 | /// 11 | public static class Arc3DExtensions 12 | { 13 | public static double[] SafeGetKeypointPosition(this SolidEdgePart.Arc3D arc3d, SolidEdgePart.Sketch3DKeypointType KeypointType, bool throwOnError = false) 14 | { 15 | var position = Array.CreateInstance(typeof(double), 0); 16 | 17 | try 18 | { 19 | // GetKeypointPosition may throw an exception so wrap in try\catch. 20 | arc3d.GetKeypointPosition(KeypointType, ref position); 21 | } 22 | catch 23 | { 24 | if (throwOnError) throw; 25 | } 26 | 27 | return position.OfType().ToArray(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/AssemblyDocumentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgeAssembly.AssemblyDocument extension methods. 10 | /// 11 | public static class AssemblyDocumentExtensions 12 | { 13 | /// 14 | /// Returns the version of Solid Edge that was used to create the referenced document. 15 | /// 16 | /// 17 | /// 18 | public static Version GetCreatedVersion(this SolidEdgeAssembly.AssemblyDocument document) 19 | { 20 | return new Version(document.CreatedVersion); 21 | } 22 | 23 | /// 24 | /// Returns the version of Solid Edge that was used the last time the referenced document was saved. 25 | /// 26 | /// 27 | /// 28 | public static Version GetLastSavedVersion(this SolidEdgeAssembly.AssemblyDocument document) 29 | { 30 | return new Version(document.LastSavedVersion); 31 | } 32 | 33 | /// 34 | /// Returns the properties for the referenced document. 35 | /// 36 | /// 37 | /// 38 | public static SolidEdgeFramework.PropertySets GetProperties(this SolidEdgeAssembly.AssemblyDocument document) 39 | { 40 | return document.Properties as SolidEdgeFramework.PropertySets; 41 | } 42 | 43 | /// 44 | /// Returns the summary information property set for the referenced document. 45 | /// 46 | /// 47 | /// 48 | public static SolidEdgeFramework.SummaryInfo GetSummaryInfo(this SolidEdgeAssembly.AssemblyDocument document) 49 | { 50 | return document.SummaryInfo as SolidEdgeFramework.SummaryInfo; 51 | } 52 | 53 | /// 54 | /// Returns a collection of variables for the referenced document. 55 | /// 56 | /// 57 | /// 58 | public static SolidEdgeFramework.Variables GetVariables(this SolidEdgeAssembly.AssemblyDocument document) 59 | { 60 | return document.Variables as SolidEdgeFramework.Variables; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/DocumentsExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | 7 | namespace SolidEdgeCommunity.Extensions 8 | { 9 | /// 10 | /// SolidEdgeFramework.Documents extension methods. 11 | /// 12 | public static class DocumentsExtensions 13 | { 14 | /// 15 | /// Creates a new document. 16 | /// 17 | internal static TDocumentType Add(this SolidEdgeFramework.Documents documents, string progId) where TDocumentType : class 18 | { 19 | return (TDocumentType)documents.Add(progId); 20 | } 21 | 22 | /// 23 | /// Creates a new document. 24 | /// 25 | internal static TDocumentType Add(this SolidEdgeFramework.Documents documents, string progId, object TemplateDoc) where TDocumentType : class 26 | { 27 | return (TDocumentType)documents.Add(progId, TemplateDoc); 28 | } 29 | 30 | /// 31 | /// Creates a new document. 32 | /// 33 | /// SolidEdgeAssembly.AssemblyDocument, SolidEdgeDraft.DraftDocument, SolidEdgePart.PartDocument or SolidEdgePart.SheetMetalDocument. 34 | /// 35 | /// 36 | public static TDocumentType Add(this SolidEdgeFramework.Documents documents) where TDocumentType : class 37 | { 38 | var t = typeof(TDocumentType); 39 | 40 | if (t.Equals(typeof(SolidEdgeAssembly.AssemblyDocument))) 41 | { 42 | return (TDocumentType)documents.AddAssemblyDocument(); 43 | } 44 | else if (t.Equals(typeof(SolidEdgeDraft.DraftDocument))) 45 | { 46 | return (TDocumentType)documents.AddDraftDocument(); 47 | } 48 | else if (t.Equals(typeof(SolidEdgePart.PartDocument))) 49 | { 50 | return (TDocumentType)documents.AddPartDocument(); 51 | } 52 | else if (t.Equals(typeof(SolidEdgePart.SheetMetalDocument))) 53 | { 54 | return (TDocumentType)documents.AddSheetMetalDocument(); 55 | } 56 | else 57 | { 58 | throw new NotSupportedException(); 59 | } 60 | } 61 | 62 | /// 63 | /// Creates a new assembly document. 64 | /// 65 | public static SolidEdgeAssembly.AssemblyDocument AddAssemblyDocument(this SolidEdgeFramework.Documents documents) 66 | { 67 | return documents.Add(SolidEdgeSDK.PROGID.SolidEdge_AssemblyDocument); 68 | } 69 | 70 | /// 71 | /// Creates a new assembly document. 72 | /// 73 | public static SolidEdgeAssembly.AssemblyDocument AddAssemblyDocument(this SolidEdgeFramework.Documents documents, object TemplateDoc) 74 | { 75 | return documents.Add(SolidEdgeSDK.PROGID.SolidEdge_AssemblyDocument, TemplateDoc); 76 | } 77 | 78 | /// 79 | /// Creates a new draft document. 80 | /// 81 | public static SolidEdgeDraft.DraftDocument AddDraftDocument(this SolidEdgeFramework.Documents documents) 82 | { 83 | return documents.Add(SolidEdgeSDK.PROGID.SolidEdge_DraftDocument); 84 | } 85 | 86 | /// 87 | /// Creates a new draft document. 88 | /// 89 | public static SolidEdgeDraft.DraftDocument AddDraftDocument(this SolidEdgeFramework.Documents documents, object TemplateDoc) 90 | { 91 | return documents.Add(SolidEdgeSDK.PROGID.SolidEdge_DraftDocument, TemplateDoc); 92 | } 93 | 94 | /// 95 | /// Creates a new part document. 96 | /// 97 | public static SolidEdgePart.PartDocument AddPartDocument(this SolidEdgeFramework.Documents documents) 98 | { 99 | return documents.Add(SolidEdgeSDK.PROGID.SolidEdge_PartDocument); 100 | } 101 | 102 | /// 103 | /// Creates a new part document. 104 | /// 105 | public static SolidEdgePart.PartDocument AddPartDocument(this SolidEdgeFramework.Documents documents, object TemplateDoc) 106 | { 107 | return documents.Add(SolidEdgeSDK.PROGID.SolidEdge_PartDocument, TemplateDoc); 108 | } 109 | 110 | /// 111 | /// Creates a new sheetmetal document. 112 | /// 113 | public static SolidEdgePart.SheetMetalDocument AddSheetMetalDocument(this SolidEdgeFramework.Documents documents) 114 | { 115 | return documents.Add(SolidEdgeSDK.PROGID.SolidEdge_SheetMetalDocument); 116 | } 117 | 118 | /// 119 | /// Creates a new sheetmetal document. 120 | /// 121 | public static SolidEdgePart.SheetMetalDocument AddSheetMetalDocument(this SolidEdgeFramework.Documents documents, object TemplateDoc) 122 | { 123 | return documents.Add(SolidEdgeSDK.PROGID.SolidEdge_SheetMetalDocument, TemplateDoc); 124 | } 125 | 126 | /// 127 | /// Opens an existing Solid Edge document. 128 | /// 129 | public static TDocumentType Open(this SolidEdgeFramework.Documents documents, string Filename) where TDocumentType : class 130 | { 131 | return (TDocumentType)documents.Open(Filename); 132 | } 133 | 134 | /// 135 | /// Opens an existing Solid Edge document. 136 | /// 137 | public static TDocumentType Open(this SolidEdgeFramework.Documents documents, string Filename, object DocRelationAutoServer, object AltPath, object RecognizeFeaturesIfPartTemplate, object RevisionRuleOption, object StopFileOpenIfRevisionRuleNotApplicable) 138 | { 139 | return (TDocumentType)documents.Open(Filename, DocRelationAutoServer, AltPath, RecognizeFeaturesIfPartTemplate, RevisionRuleOption, StopFileOpenIfRevisionRuleNotApplicable); 140 | } 141 | 142 | /// 143 | /// Opens an existing Solid Edge document in the background with no window. 144 | /// 145 | public static TDocumentType OpenInBackground(this SolidEdgeFramework.Documents documents, string Filename) 146 | { 147 | ulong JDOCUMENTPROP_NOWINDOW = 0x00000008; 148 | return (TDocumentType)documents.Open(Filename, JDOCUMENTPROP_NOWINDOW); 149 | } 150 | 151 | /// 152 | /// Opens an existing Solid Edge document in the background with no window. 153 | /// 154 | public static TDocumentType OpenInBackground(this SolidEdgeFramework.Documents documents, string Filename, object AltPath, object RecognizeFeaturesIfPartTemplate, object RevisionRuleOption, object StopFileOpenIfRevisionRuleNotApplicable) 155 | { 156 | ulong JDOCUMENTPROP_NOWINDOW = 0x00000008; 157 | return (TDocumentType)documents.Open(Filename, JDOCUMENTPROP_NOWINDOW, AltPath, RecognizeFeaturesIfPartTemplate, RevisionRuleOption, StopFileOpenIfRevisionRuleNotApplicable); 158 | } 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/DraftDocumentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgeDraft.DraftDocument extensions. 10 | /// 11 | public static class DraftDocumentExtensions 12 | { 13 | /// 14 | /// Returns an enumerable collection of drawing objects. 15 | /// 16 | /// 17 | /// 18 | public static IEnumerable EnumerateDrawingObjects(this SolidEdgeDraft.DraftDocument document) 19 | { 20 | foreach (SolidEdgeDraft.Section section in document.Sections) 21 | { 22 | foreach (var drawingObject in section.EnumerateDrawingObjects()) 23 | { 24 | yield return drawingObject; 25 | } 26 | } 27 | } 28 | 29 | /// 30 | /// Returns an enumerable collection of drawing objects of the specified type. 31 | /// 32 | /// 33 | /// 34 | public static IEnumerable EnumerateDrawingObjects(this SolidEdgeDraft.DraftDocument document) where T : class 35 | { 36 | foreach (SolidEdgeDraft.Section section in document.Sections) 37 | { 38 | foreach (var drawingObject in section.EnumerateDrawingObjects()) 39 | { 40 | yield return drawingObject; 41 | } 42 | } 43 | } 44 | 45 | /// 46 | /// Returns an enumerable collection of drawing objects in the specified section. 47 | /// 48 | /// 49 | /// 50 | /// 51 | public static IEnumerable EnumerateDrawingObjects(this SolidEdgeDraft.DraftDocument document, SolidEdgeDraft.SheetSectionTypeConstants sectionType) 52 | { 53 | foreach (SolidEdgeDraft.Section section in document.Sections) 54 | { 55 | if (section.Type == sectionType) 56 | { 57 | foreach (var drawingObject in section.EnumerateDrawingObjects()) 58 | { 59 | yield return drawingObject; 60 | } 61 | } 62 | } 63 | } 64 | 65 | /// 66 | /// Returns an enumerable collection of drawing objects of the specified type in the specified section. 67 | /// 68 | /// 69 | /// 70 | /// 71 | public static IEnumerable EnumerateDrawingObjects(this SolidEdgeDraft.DraftDocument document, SolidEdgeDraft.SheetSectionTypeConstants sectionType) where T : class 72 | { 73 | foreach (SolidEdgeDraft.Section section in document.Sections) 74 | { 75 | if (section.Type == sectionType) 76 | { 77 | foreach (var drawingObject in section.EnumerateDrawingObjects()) 78 | { 79 | yield return drawingObject; 80 | } 81 | } 82 | } 83 | } 84 | 85 | /// 86 | /// Returns an enumerable collection of drawing views. 87 | /// 88 | /// 89 | /// 90 | public static IEnumerable EnumerateDrawingViews(this SolidEdgeDraft.DraftDocument document) 91 | { 92 | foreach (SolidEdgeDraft.Sheet sheet in document.Sheets) 93 | { 94 | foreach (SolidEdgeDraft.DrawingView drawingView in sheet.DrawingViews) 95 | { 96 | yield return drawingView; 97 | } 98 | } 99 | } 100 | 101 | /// 102 | /// Returns an enumerable collection of drawing views in the specified section. 103 | /// 104 | /// 105 | /// 106 | /// 107 | public static IEnumerable EnumerateDrawingViews(this SolidEdgeDraft.DraftDocument document, SolidEdgeDraft.SheetSectionTypeConstants sectionType) 108 | { 109 | foreach (SolidEdgeDraft.Section section in document.Sections) 110 | { 111 | if (section.Type == sectionType) 112 | { 113 | foreach (SolidEdgeDraft.DrawingView drawingView in section.EnumerateDrawingViews()) 114 | { 115 | yield return drawingView; 116 | } 117 | } 118 | } 119 | } 120 | 121 | /// 122 | /// Returns the version of Solid Edge that was used to create the referenced document. 123 | /// 124 | /// 125 | /// 126 | public static Version GetCreatedVersion(this SolidEdgeDraft.DraftDocument document) 127 | { 128 | return new Version(document.CreatedVersion); 129 | } 130 | 131 | /// 132 | /// Returns the version of Solid Edge that was used the last time the referenced document was saved. 133 | /// 134 | /// 135 | /// 136 | public static Version GetLastSavedVersion(this SolidEdgeDraft.DraftDocument document) 137 | { 138 | return new Version(document.LastSavedVersion); 139 | } 140 | 141 | /// 142 | /// Returns the properties for the referenced document. 143 | /// 144 | /// 145 | /// 146 | public static SolidEdgeFramework.PropertySets GetProperties(this SolidEdgeDraft.DraftDocument document) 147 | { 148 | return document.Properties as SolidEdgeFramework.PropertySets; 149 | } 150 | 151 | /// 152 | /// Returns the summary information property set for the referenced document. 153 | /// 154 | /// 155 | /// 156 | public static SolidEdgeFramework.SummaryInfo GetSummaryInfo(this SolidEdgeDraft.DraftDocument document) 157 | { 158 | return document.SummaryInfo as SolidEdgeFramework.SummaryInfo; 159 | } 160 | 161 | /// 162 | /// Returns a collection of variables for the referenced document. 163 | /// 164 | /// 165 | /// 166 | public static SolidEdgeFramework.Variables GetVariables(this SolidEdgeDraft.DraftDocument document) 167 | { 168 | return document.Variables as SolidEdgeFramework.Variables; 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/DrawingViewExtensions.cs: -------------------------------------------------------------------------------- 1 | //using System; 2 | //using System.Collections.Generic; 3 | //using System.Linq; 4 | //using System.Text; 5 | 6 | //namespace SolidEdgeCommunity.Extensions 7 | //{ 8 | // /// 9 | // /// SolidEdgeDraft.DrawingView extension methods. 10 | // /// 11 | // public static class DrawingViewExtensions 12 | // { 13 | // /// 14 | // /// Returns the origin of the drawing view. 15 | // /// 16 | // public static System.Windows.Point GetOrigin(this SolidEdgeDraft.DrawingView drawingView) 17 | // { 18 | // var x = 0.0; 19 | // var y = 0.0; 20 | // drawingView.GetOrigin(out x, out y); 21 | // return new System.Windows.Point(x, y); 22 | // } 23 | // } 24 | //} 25 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/EnvironmentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgeFramework.Environment extension methods. 10 | /// 11 | public static class EnvironmentExtensions 12 | { 13 | /// 14 | /// Returns a Guid representing the environment category. 15 | /// 16 | public static Guid GetCategoryId(this SolidEdgeFramework.Environment environment) 17 | { 18 | return new Guid(environment.CATID); 19 | } 20 | 21 | /// 22 | /// Returns a Type representing the corresponding command constants for a particular environment. 23 | /// 24 | /// 25 | /// 26 | public static Type GetCommandConstantType(this SolidEdgeFramework.Environment environment) 27 | { 28 | var categoryId = environment.GetCategoryId(); 29 | 30 | if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Application)) 31 | { 32 | return typeof(SolidEdgeConstants.SolidEdgeCommandConstants); 33 | } 34 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Assembly)) 35 | { 36 | return typeof(SolidEdgeConstants.AssemblyCommandConstants); 37 | } 38 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.DMAssembly)) 39 | { 40 | return typeof(SolidEdgeConstants.AssemblyCommandConstants); 41 | } 42 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.CuttingPlaneLine)) 43 | { 44 | return typeof(SolidEdgeConstants.CuttingPlaneLineCommandConstants); 45 | } 46 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Draft)) 47 | { 48 | return typeof(SolidEdgeConstants.DetailCommandConstants); 49 | } 50 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.DrawingViewEdit)) 51 | { 52 | return typeof(SolidEdgeConstants.DrawingViewEditCommandConstants); 53 | } 54 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Explode)) 55 | { 56 | return typeof(SolidEdgeConstants.ExplodeCommandConstants); 57 | } 58 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Layout)) 59 | { 60 | return typeof(SolidEdgeConstants.LayoutCommandConstants); 61 | } 62 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Sketch)) 63 | { 64 | return typeof(SolidEdgeConstants.LayoutInPartCommandConstants); 65 | } 66 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Motion)) 67 | { 68 | return typeof(SolidEdgeConstants.MotionCommandConstants); 69 | } 70 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Part)) 71 | { 72 | return typeof(SolidEdgeConstants.PartCommandConstants); 73 | } 74 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.DMPart)) 75 | { 76 | return typeof(SolidEdgeConstants.PartCommandConstants); 77 | } 78 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Profile)) 79 | { 80 | return typeof(SolidEdgeConstants.ProfileCommandConstants); 81 | } 82 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.ProfileHole)) 83 | { 84 | return typeof(SolidEdgeConstants.ProfileHoleCommandConstants); 85 | } 86 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.ProfilePattern)) 87 | { 88 | return typeof(SolidEdgeConstants.ProfilePatternCommandConstants); 89 | } 90 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.ProfileRevolved)) 91 | { 92 | return typeof(SolidEdgeConstants.ProfileRevolvedCommandConstants); 93 | } 94 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.SheetMetal)) 95 | { 96 | return typeof(SolidEdgeConstants.SheetMetalCommandConstants); 97 | } 98 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.DMSheetMetal)) 99 | { 100 | return typeof(SolidEdgeConstants.SheetMetalCommandConstants); 101 | } 102 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Simplify)) 103 | { 104 | return typeof(SolidEdgeConstants.SimplifyCommandConstants); 105 | } 106 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Studio)) 107 | { 108 | return typeof(SolidEdgeConstants.StudioCommandConstants); 109 | } 110 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.XpresRoute)) 111 | { 112 | return typeof(SolidEdgeConstants.TubingCommandConstants); 113 | } 114 | else if (categoryId.Equals(SolidEdgeSDK.EnvironmentCategories.Weldment)) 115 | { 116 | return typeof(SolidEdgeConstants.WeldmentCommandConstants); 117 | } 118 | 119 | return null; 120 | } 121 | 122 | /// 123 | /// Returns a SolidEdgeFramework.Environment by name. 124 | /// 125 | public static SolidEdgeFramework.Environment LookupByName(this SolidEdgeFramework.Environments environments, string name) 126 | { 127 | for (int i = 1; i <= environments.Count; i++) 128 | { 129 | var environment = environments.Item(i); 130 | if (environment.Name.Equals(name)) 131 | { 132 | return environment; 133 | } 134 | } 135 | 136 | return null; 137 | } 138 | 139 | /// 140 | /// Returns a SolidEdgeFramework.Environment by category id.. 141 | /// 142 | public static SolidEdgeFramework.Environment LookupByCategoryId(this SolidEdgeFramework.Environments environments, Guid categoryId) 143 | { 144 | for (int i = 1; i <= environments.Count; i++) 145 | { 146 | var environment = environments.Item(i); 147 | if (environment.GetCategoryId().Equals(categoryId)) 148 | { 149 | return environment; 150 | } 151 | } 152 | 153 | return null; 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/Line3DExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgePart.Line3D extension methods. 10 | /// 11 | public static class Line3DExtensions 12 | { 13 | public static double[] SafeGetKeypointPosition(this SolidEdgePart.Line3D line3d, SolidEdgePart.Sketch3DKeypointType KeypointType, bool throwOnError = false) 14 | { 15 | var position = Array.CreateInstance(typeof(double), 0); 16 | 17 | try 18 | { 19 | // GetKeypointPosition may throw an exception so wrap in try\catch. 20 | line3d.GetKeypointPosition(KeypointType, ref position); 21 | } 22 | catch 23 | { 24 | if (throwOnError) throw; 25 | } 26 | 27 | return position.OfType().ToArray(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/MouseExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgeFramework.Mouse extension methods. 10 | /// 11 | public static class MouseExtensions 12 | { 13 | /// 14 | /// Specifies what types of objects the Mouse can locate. 15 | /// 16 | /// 17 | /// 18 | public static void AddToLocateFilter(this SolidEdgeFramework.Mouse mouse, SolidEdgeConstants.seLocateFilterConstants filter) 19 | { 20 | mouse.AddToLocateFilter((int)filter); 21 | } 22 | 23 | /// 24 | /// Sets the locate mode for the referenced object. 25 | /// 26 | /// 27 | /// 28 | public static void SetLocateMode(this SolidEdgeFramework.Mouse mouse, SolidEdgeConstants.seLocateModes mode) 29 | { 30 | mouse.LocateMode = (int)mode; 31 | } 32 | 33 | /// 34 | /// Returns the locate mode for the referenced object. 35 | /// 36 | /// 37 | /// 38 | /// 39 | public static SolidEdgeConstants.seLocateModes GetLocateMode(this SolidEdgeFramework.Mouse mouse, SolidEdgeConstants.seLocateModes mode) 40 | { 41 | return (SolidEdgeConstants.seLocateModes)mouse.LocateMode; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/OccurrenceExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgePart.WeldmentDocument extension methods. 10 | /// 11 | public static class OccurrenceExtensions 12 | { 13 | /// 14 | /// Returns the version of Solid Edge that was used to create the referenced document. 15 | /// 16 | /// 17 | /// 18 | public static SolidEdgeFramework.SolidEdgeDocument GetOccurrenceDocument(this SolidEdgeAssembly.Occurrence occurrence) 19 | { 20 | return occurrence as SolidEdgeFramework.SolidEdgeDocument; 21 | } 22 | 23 | /// 24 | /// Returns a strongly typed occurrence document. 25 | /// 26 | /// The type to return. 27 | public static T GetOccurrenceDocument(this SolidEdgeAssembly.Occurrence occurrence) where T : class 28 | { 29 | return occurrence.GetOccurrenceDocument(true); 30 | } 31 | 32 | /// 33 | /// Returns a strongly typed occurrence document. 34 | /// 35 | /// The type to return. 36 | public static T GetOccurrenceDocument(this SolidEdgeAssembly.Occurrence occurrence, bool throwOnError) where T : class 37 | { 38 | try 39 | { 40 | return (T)occurrence.OccurrenceDocument; 41 | } 42 | catch 43 | { 44 | if (throwOnError) throw; 45 | } 46 | 47 | return null; 48 | } 49 | 50 | /// 51 | /// Converts Array from GetBodyInversionMatrix() to double[]. 52 | /// 53 | public static double[] GetBodyInversionMatrix(this SolidEdgeAssembly.Occurrence occurrence) 54 | { 55 | Array matrix = Array.CreateInstance(typeof(double), 0); 56 | occurrence.GetBodyInversionMatrix(ref matrix); 57 | return matrix.OfType().ToArray(); 58 | } 59 | 60 | /// 61 | /// Converts Array from GetExplodeMatrix() to double[]. 62 | /// 63 | public static double[] GetExplodeMatrix(this SolidEdgeAssembly.Occurrence occurrence) 64 | { 65 | Array matrix = Array.CreateInstance(typeof(double), 0); 66 | occurrence.GetExplodeMatrix(ref matrix); 67 | return matrix.OfType().ToArray(); 68 | } 69 | 70 | /// 71 | /// Converts Array from GetMatrix() to double[]. 72 | /// 73 | public static double[] GetMatrix(this SolidEdgeAssembly.Occurrence occurrence) 74 | { 75 | Array matrix = Array.CreateInstance(typeof(double), 0); 76 | occurrence.GetMatrix(ref matrix); 77 | return matrix.OfType().ToArray(); 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/PartDocumentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgePart.PartDocument extension methods. 10 | /// 11 | public static class PartDocumentExtensions 12 | { 13 | /// 14 | /// Returns the version of Solid Edge that was used to create the referenced document. 15 | /// 16 | /// 17 | /// 18 | public static Version GetCreatedVersion(this SolidEdgePart.PartDocument document) 19 | { 20 | return new Version(document.CreatedVersion); 21 | } 22 | 23 | /// 24 | /// Returns the version of Solid Edge that was used the last time the referenced document was saved. 25 | /// 26 | /// 27 | /// 28 | public static Version GetLastSavedVersion(this SolidEdgePart.PartDocument document) 29 | { 30 | return new Version(document.LastSavedVersion); 31 | } 32 | 33 | /// 34 | /// Returns the properties for the referenced document. 35 | /// 36 | /// 37 | /// 38 | public static SolidEdgeFramework.PropertySets GetProperties(this SolidEdgePart.PartDocument document) 39 | { 40 | return document.Properties as SolidEdgeFramework.PropertySets; 41 | } 42 | 43 | /// 44 | /// Returns the summary information property set for the referenced document. 45 | /// 46 | /// 47 | /// 48 | public static SolidEdgeFramework.SummaryInfo GetSummaryInfo(this SolidEdgePart.PartDocument document) 49 | { 50 | return document.SummaryInfo as SolidEdgeFramework.SummaryInfo; 51 | } 52 | 53 | /// 54 | /// Returns a collection of variables for the referenced document. 55 | /// 56 | /// 57 | /// 58 | public static SolidEdgeFramework.Variables GetVariables(this SolidEdgePart.PartDocument document) 59 | { 60 | return document.Variables as SolidEdgeFramework.Variables; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/PropertiesExtensions.cs: -------------------------------------------------------------------------------- 1 | //using System; 2 | //using System.Collections.Generic; 3 | //using System.Linq; 4 | //using System.Text; 5 | 6 | //namespace SolidEdgeCommunity.Extensions 7 | //{ 8 | // /// 9 | // /// SolidEdgeFileProperties.Properties extensions. 10 | // /// 11 | // public static class PropertiesExtensions 12 | // { 13 | // /// 14 | // /// Returns all properties of a given property set as an IEnumerable. 15 | // /// 16 | // /// 17 | // public static IEnumerable AsEnumerable(this SolidEdgeFileProperties.Properties properties) 18 | // { 19 | // List list = new List(); 20 | 21 | // foreach (var property in properties) 22 | // { 23 | // list.Add((SolidEdgeFileProperties.Property)property); 24 | // } 25 | 26 | // return list.AsEnumerable(); 27 | // } 28 | // } 29 | //} 30 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/PropertySetsExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgeFileProperties.PropertySets extensions. 10 | /// 11 | public static class PropertySetsExtensions 12 | { 13 | ///// 14 | ///// Returns all property sets as an IEnumerable. 15 | ///// 16 | ///// 17 | //public static IEnumerable AsEnumerable(this SolidEdgeFileProperties.PropertySets propertySets) 18 | //{ 19 | // List list = new List(); 20 | 21 | // foreach (var properties in propertySets) 22 | // { 23 | // list.Add((SolidEdgeFileProperties.Properties)properties); 24 | // } 25 | 26 | // return list.AsEnumerable(); 27 | //} 28 | 29 | /// 30 | /// Closes an open document with the option to save changes. 31 | /// 32 | /// 33 | /// 34 | public static void Close(this SolidEdgeFileProperties.PropertySets propertySets, bool saveChanges) 35 | { 36 | if (saveChanges) 37 | { 38 | propertySets.Save(); 39 | } 40 | 41 | propertySets.Close(); 42 | } 43 | 44 | /// 45 | /// Adds or modifies a custom property. 46 | /// 47 | internal static SolidEdgeFileProperties.Property InternalUpdateCustomProperty(this SolidEdgeFileProperties.PropertySets propertySets, string propertyName, object propertyValue) 48 | { 49 | SolidEdgeFileProperties.Properties customPropertySet = null; 50 | SolidEdgeFileProperties.Property property = null; 51 | 52 | try 53 | { 54 | // Get a reference to the custom property set. 55 | customPropertySet = (SolidEdgeFileProperties.Properties)propertySets["Custom"]; 56 | 57 | // Attempt to get the custom property. 58 | property = (SolidEdgeFileProperties.Property)customPropertySet[propertyName]; 59 | 60 | // If we get here, the custom property exists so update the value. 61 | property.Value = propertyValue; 62 | } 63 | catch (System.Runtime.InteropServices.COMException) 64 | { 65 | // If we get here, the custom property does not exist so add it. 66 | property = (SolidEdgeFileProperties.Property)customPropertySet.Add(propertyName, propertyValue); 67 | } 68 | catch 69 | { 70 | throw; 71 | } 72 | 73 | return property; 74 | } 75 | 76 | /// 77 | /// Adds or modifies a custom property. 78 | /// 79 | public static SolidEdgeFileProperties.Property UpdateCustomProperty(this SolidEdgeFileProperties.PropertySets propertySets, string propertyName, bool propertyValue) 80 | { 81 | return propertySets.InternalUpdateCustomProperty(propertyName, propertyValue); 82 | } 83 | 84 | /// 85 | /// Adds or modifies a custom property. 86 | /// 87 | public static SolidEdgeFileProperties.Property UpdateCustomProperty(this SolidEdgeFileProperties.PropertySets propertySets, string propertyName, DateTime propertyValue) 88 | { 89 | return propertySets.InternalUpdateCustomProperty(propertyName, propertyValue); 90 | } 91 | 92 | /// 93 | /// Adds or modifies a custom property. 94 | /// 95 | public static SolidEdgeFileProperties.Property UpdateCustomProperty(this SolidEdgeFileProperties.PropertySets propertySets, string propertyName, double propertyValue) 96 | { 97 | return propertySets.InternalUpdateCustomProperty(propertyName, propertyValue); 98 | } 99 | 100 | /// 101 | /// Adds or modifies a custom property. 102 | /// 103 | public static SolidEdgeFileProperties.Property UpdateCustomProperty(this SolidEdgeFileProperties.PropertySets propertySets, string propertyName, int propertyValue) 104 | { 105 | return propertySets.InternalUpdateCustomProperty(propertyName, propertyValue); 106 | } 107 | 108 | /// 109 | /// Adds or modifies a custom property. 110 | /// 111 | public static SolidEdgeFileProperties.Property UpdateCustomProperty(this SolidEdgeFileProperties.PropertySets propertySets, string propertyName, string propertyValue) 112 | { 113 | return propertySets.InternalUpdateCustomProperty(propertyName, propertyValue); 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/RefPlanesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgePart.RefPlanes extension methods. 10 | /// 11 | public static class RefPlanesExtensions 12 | { 13 | /// 14 | /// Returns a SolidEdgePart.RefPlane representing the default top plane. 15 | /// 16 | public static SolidEdgePart.RefPlane GetTopPlane(this SolidEdgePart.RefPlanes refPlanes) 17 | { 18 | return refPlanes.Item(1); 19 | } 20 | 21 | /// 22 | /// Returns a SolidEdgePart.RefPlane representing the default right plane. 23 | /// 24 | public static SolidEdgePart.RefPlane GetRightPlane(this SolidEdgePart.RefPlanes refPlanes) 25 | { 26 | return refPlanes.Item(2); 27 | } 28 | 29 | /// 30 | /// Returns a SolidEdgePart.RefPlane representing the default front plane. 31 | /// 32 | public static SolidEdgePart.RefPlane GetFrontPlane(this SolidEdgePart.RefPlanes refPlanes) 33 | { 34 | return refPlanes.Item(3); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/SectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgeDraft.Section extensions. 10 | /// 11 | public static class SectionExtensions 12 | { 13 | /// 14 | /// Returns an enumerable collection of drawing objects. 15 | /// 16 | /// 17 | /// 18 | public static IEnumerable EnumerateDrawingObjects(this SolidEdgeDraft.Section section) 19 | { 20 | foreach (var drawingObject in EnumerateDrawingObjects(section)) 21 | { 22 | yield return drawingObject; 23 | } 24 | } 25 | 26 | /// 27 | /// Returns an enumerable collection of drawing objects of the specified type. 28 | /// 29 | /// 30 | /// 31 | public static IEnumerable EnumerateDrawingObjects(this SolidEdgeDraft.Section section) where T : class 32 | { 33 | foreach (SolidEdgeDraft.Sheet sheet in section.Sheets) 34 | { 35 | // The following section types are hidden and should not be used. 36 | if (sheet.SectionType == SolidEdgeDraft.SheetSectionTypeConstants.igDrawingViewSection) continue; 37 | if (sheet.SectionType == SolidEdgeDraft.SheetSectionTypeConstants.igBlockViewSection) continue; 38 | 39 | // Should work but throws an exception... 40 | //foreach (var drawingObject in sheet.DrawingObjects) 41 | 42 | var drawingObjects = sheet.DrawingObjects; 43 | 44 | for (int i = 1; i <= drawingObjects.Count; i++) 45 | { 46 | var drawingObject = drawingObjects.Item(i); 47 | 48 | if (drawingObject is T) 49 | { 50 | yield return (T)drawingObject; 51 | } 52 | } 53 | } 54 | } 55 | 56 | /// 57 | /// Returns an enumerable collection of drawing views. 58 | /// 59 | /// 60 | /// 61 | public static IEnumerable EnumerateDrawingViews(this SolidEdgeDraft.Section section) 62 | { 63 | foreach (SolidEdgeDraft.Sheet sheet in section.Sheets) 64 | { 65 | foreach (SolidEdgeDraft.DrawingView drawingView in sheet.DrawingViews) 66 | { 67 | yield return drawingView; 68 | } 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/SheetExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | 8 | namespace SolidEdgeCommunity.Extensions 9 | { 10 | public static class SheetExtensions 11 | { 12 | [DllImport("user32.dll")] 13 | static extern bool CloseClipboard(); 14 | 15 | [DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 16 | static extern IntPtr GetClipboardData(uint format); 17 | 18 | [DllImport("user32.dll")] 19 | static extern IntPtr GetClipboardOwner(); 20 | 21 | [DllImport("user32.dll")] 22 | static extern bool IsClipboardFormatAvailable(uint format); 23 | 24 | [DllImport("user32.dll")] 25 | static extern bool OpenClipboard(IntPtr hWndNewOwner); 26 | 27 | [DllImport("gdi32.dll")] 28 | static extern bool DeleteEnhMetaFile(IntPtr hemf); 29 | 30 | [DllImport("gdi32.dll")] 31 | static extern uint GetEnhMetaFileBits(IntPtr hemf, uint cbBuffer, [Out] byte[] lpbBuffer); 32 | 33 | const uint CF_ENHMETAFILE = 14; 34 | 35 | public static System.Drawing.Imaging.Metafile GetEnhancedMetafile(this SolidEdgeDraft.Sheet sheet) 36 | { 37 | try 38 | { 39 | // Copy the sheet as an EMF to the windows clipboard. 40 | sheet.CopyEMFToClipboard(); 41 | 42 | if (OpenClipboard(IntPtr.Zero)) 43 | { 44 | if (IsClipboardFormatAvailable(CF_ENHMETAFILE)) 45 | { 46 | // Get the handle to the EMF. 47 | IntPtr henhmetafile = GetClipboardData(CF_ENHMETAFILE); 48 | 49 | return new System.Drawing.Imaging.Metafile(henhmetafile, true); 50 | } 51 | else 52 | { 53 | throw new System.Exception("CF_ENHMETAFILE is not available in clipboard."); 54 | } 55 | } 56 | else 57 | { 58 | throw new System.Exception("Error opening clipboard."); 59 | } 60 | } 61 | catch (System.Exception e) 62 | { 63 | throw e; 64 | } 65 | finally 66 | { 67 | CloseClipboard(); 68 | } 69 | } 70 | 71 | public static void SaveAsEnhancedMetafile(this SolidEdgeDraft.Sheet sheet, string filename) 72 | { 73 | try 74 | { 75 | // Copy the sheet as an EMF to the windows clipboard. 76 | sheet.CopyEMFToClipboard(); 77 | 78 | if (OpenClipboard(IntPtr.Zero)) 79 | { 80 | if (IsClipboardFormatAvailable(CF_ENHMETAFILE)) 81 | { 82 | // Get the handle to the EMF. 83 | IntPtr hEMF = GetClipboardData(CF_ENHMETAFILE); 84 | 85 | // Query the size of the EMF. 86 | uint len = GetEnhMetaFileBits(hEMF, 0, null); 87 | byte[] rawBytes = new byte[len]; 88 | 89 | // Get all of the bytes of the EMF. 90 | GetEnhMetaFileBits(hEMF, len, rawBytes); 91 | 92 | // Write all of the bytes to a file. 93 | File.WriteAllBytes(filename, rawBytes); 94 | 95 | // Delete the EMF handle. 96 | DeleteEnhMetaFile(hEMF); 97 | } 98 | else 99 | { 100 | throw new System.Exception("CF_ENHMETAFILE is not available in clipboard."); 101 | } 102 | } 103 | else 104 | { 105 | throw new System.Exception("Error opening clipboard."); 106 | } 107 | } 108 | catch (System.Exception e) 109 | { 110 | throw e; 111 | } 112 | finally 113 | { 114 | CloseClipboard(); 115 | } 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/SheetMetalDocumentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgePart.SheetMetalDocument extension methods. 10 | /// 11 | public static class SheetMetalDocumentExtensions 12 | { 13 | /// 14 | /// Returns the version of Solid Edge that was used to create the referenced document. 15 | /// 16 | /// 17 | /// 18 | public static Version GetCreatedVersion(this SolidEdgePart.SheetMetalDocument document) 19 | { 20 | return new Version(document.CreatedVersion); 21 | } 22 | 23 | /// 24 | /// Returns the version of Solid Edge that was used the last time the referenced document was saved. 25 | /// 26 | /// 27 | /// 28 | public static Version GetLastSavedVersion(this SolidEdgePart.SheetMetalDocument document) 29 | { 30 | return new Version(document.LastSavedVersion); 31 | } 32 | 33 | /// 34 | /// Returns the properties for the referenced document. 35 | /// 36 | /// 37 | /// 38 | public static SolidEdgeFramework.PropertySets GetProperties(this SolidEdgePart.SheetMetalDocument document) 39 | { 40 | return document.Properties as SolidEdgeFramework.PropertySets; 41 | } 42 | 43 | /// 44 | /// Returns the summary information property set for the referenced document. 45 | /// 46 | /// 47 | /// 48 | public static SolidEdgeFramework.SummaryInfo GetSummaryInfo(this SolidEdgePart.SheetMetalDocument document) 49 | { 50 | return document.SummaryInfo as SolidEdgeFramework.SummaryInfo; 51 | } 52 | 53 | /// 54 | /// Returns a collection of variables for the referenced document. 55 | /// 56 | /// 57 | /// 58 | public static SolidEdgeFramework.Variables GetVariables(this SolidEdgePart.SheetMetalDocument document) 59 | { 60 | return document.Variables as SolidEdgeFramework.Variables; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/SolidEdgeDocumentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | 7 | namespace SolidEdgeCommunity.Extensions 8 | { 9 | /// 10 | /// SolidEdgeFramework.SolidEdgeDocument extension methods. 11 | /// 12 | public static class SolidEdgeDocumentExtensions 13 | { 14 | /// 15 | /// Returns the version of Solid Edge that was used to create the referenced document. 16 | /// 17 | /// 18 | /// 19 | public static Version GetCreatedVersion(this SolidEdgeFramework.SolidEdgeDocument document) 20 | { 21 | return new Version(document.CreatedVersion); 22 | } 23 | 24 | /// 25 | /// Returns the version of Solid Edge that was used the last time the referenced document was saved. 26 | /// 27 | /// 28 | /// 29 | public static Version GetLastSavedVersion(this SolidEdgeFramework.SolidEdgeDocument document) 30 | { 31 | return new Version(document.LastSavedVersion); 32 | } 33 | 34 | /// 35 | /// Returns the properties for the referenced document. 36 | /// 37 | /// 38 | /// 39 | public static SolidEdgeFramework.PropertySets GetProperties(this SolidEdgeFramework.SolidEdgeDocument document) 40 | { 41 | return document.Properties as SolidEdgeFramework.PropertySets; 42 | } 43 | 44 | /// 45 | /// Returns the summary information property set for the referenced document. 46 | /// 47 | /// 48 | /// 49 | public static SolidEdgeFramework.SummaryInfo GetSummaryInfo(this SolidEdgeFramework.SolidEdgeDocument document) 50 | { 51 | return document.SummaryInfo as SolidEdgeFramework.SummaryInfo; 52 | } 53 | 54 | /// 55 | /// Returns a collection of variables for the referenced document. 56 | /// 57 | /// 58 | /// 59 | public static SolidEdgeFramework.Variables GetVariables(this SolidEdgeFramework.SolidEdgeDocument document) 60 | { 61 | return document.Variables as SolidEdgeFramework.Variables; 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/WeldmentDocumentExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgePart.WeldmentDocument extension methods. 10 | /// 11 | public static class WeldmentDocumentExtensions 12 | { 13 | /// 14 | /// Returns the version of Solid Edge that was used to create the referenced document. 15 | /// 16 | /// 17 | /// 18 | public static Version GetCreatedVersion(this SolidEdgePart.WeldmentDocument document) 19 | { 20 | return new Version(document.CreatedVersion); 21 | } 22 | 23 | /// 24 | /// Returns the version of Solid Edge that was used the last time the referenced document was saved. 25 | /// 26 | /// 27 | /// 28 | public static Version GetLastSavedVersion(this SolidEdgePart.WeldmentDocument document) 29 | { 30 | return new Version(document.LastSavedVersion); 31 | } 32 | 33 | /// 34 | /// Returns the properties for the referenced document. 35 | /// 36 | /// 37 | /// 38 | public static SolidEdgeFramework.PropertySets GetProperties(this SolidEdgePart.WeldmentDocument document) 39 | { 40 | return document.Properties as SolidEdgeFramework.PropertySets; 41 | } 42 | 43 | /// 44 | /// Returns the summary information property set for the referenced document. 45 | /// 46 | /// 47 | /// 48 | public static SolidEdgeFramework.SummaryInfo GetSummaryInfo(this SolidEdgePart.WeldmentDocument document) 49 | { 50 | return document.SummaryInfo as SolidEdgeFramework.SummaryInfo; 51 | } 52 | 53 | /// 54 | /// Returns a collection of variables for the referenced document. 55 | /// 56 | /// 57 | /// 58 | public static SolidEdgeFramework.Variables GetVariables(this SolidEdgePart.WeldmentDocument document) 59 | { 60 | return document.Variables as SolidEdgeFramework.Variables; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Extensions/WindowExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SolidEdgeCommunity.Extensions 7 | { 8 | /// 9 | /// SolidEdgeFramework.Window extension methods. 10 | /// 11 | public static class WindowExtensions 12 | { 13 | /// 14 | /// Returns an IntPtr representing the window handle. 15 | /// 16 | public static IntPtr GetDrawHandle(this SolidEdgeFramework.Window window) 17 | { 18 | return new IntPtr(window.DrawHwnd); 19 | } 20 | 21 | /// 22 | /// Returns an IntPtr representing the window handle. 23 | /// 24 | public static IntPtr GetHandle(this SolidEdgeFramework.Window window) 25 | { 26 | return new IntPtr(window.hWnd); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/IsolatedTask.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | 7 | namespace SolidEdgeCommunity 8 | { 9 | /// 10 | /// Generic class used to execute an IsolatedTaskProxy implementation. 11 | /// 12 | /// 13 | public sealed class IsolatedTask : IDisposable where T : IsolatedTaskProxy 14 | { 15 | private Type _proxyType = null; 16 | private AppDomain _appDomain = null; 17 | private T _proxy = null; 18 | 19 | /// 20 | /// 21 | /// 22 | public IsolatedTask() 23 | { 24 | // Get the proxy type. 25 | _proxyType = typeof(T); 26 | 27 | // Create a custom AppDomain to do COM Interop. 28 | _appDomain = AppDomain.CreateDomain(String.Format("{0} AppDomain", _proxyType.Name), null, AppDomain.CurrentDomain.SetupInformation); 29 | 30 | // Create a new instance of InteropProxy in the isolated application domain. 31 | _proxy = (T)_appDomain.CreateInstanceAndUnwrap(_proxyType.Assembly.FullName, _proxyType.FullName); 32 | } 33 | 34 | void IDisposable.Dispose() 35 | { 36 | if (_appDomain != null) 37 | { 38 | // Unload the Interop AppDomain. This will automatically free up any COM references. 39 | AppDomain.Unload(_appDomain); 40 | } 41 | 42 | _proxy = null; 43 | _appDomain = null; 44 | _proxyType = null; 45 | } 46 | 47 | public T Proxy { get { return _proxy; } } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/IsolatedTaskProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Runtime.Remoting; 6 | using System.Text; 7 | 8 | namespace SolidEdgeCommunity 9 | { 10 | /// 11 | /// Abstract base class to be used with IsolatedTask<T>. 12 | /// 13 | public abstract class IsolatedTaskProxy : MarshalByRefObject 14 | { 15 | private SolidEdgeFramework.Application _application; 16 | private SolidEdgeFramework.SolidEdgeDocument _document; 17 | 18 | /// 19 | /// Lifetime services as disabled by default. 20 | /// 21 | public sealed override object InitializeLifetimeService() 22 | { 23 | return null; 24 | } 25 | 26 | /// 27 | /// Invokes a method in a STA thread. 28 | /// 29 | /// 30 | protected void InvokeSTAThread(Action target) 31 | { 32 | if (target == null) throw new ArgumentNullException("target"); 33 | 34 | Exception exception = null; 35 | 36 | // Define thread. 37 | var thread = new System.Threading.Thread(() => 38 | { 39 | // Thread specific try\catch. 40 | try 41 | { 42 | target(); 43 | } 44 | catch (System.Exception ex) 45 | { 46 | exception = ex; 47 | } 48 | }); 49 | 50 | // Important! Set thread apartment state to STA. 51 | thread.SetApartmentState(System.Threading.ApartmentState.STA); 52 | 53 | // Start the thread. 54 | thread.Start(); 55 | 56 | // Wait for the thead to finish. 57 | thread.Join(); 58 | 59 | if (exception != null) 60 | { 61 | throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception); 62 | } 63 | } 64 | 65 | /// 66 | /// Invokes a method in a STA thread. 67 | /// 68 | /// The type of arg1. 69 | /// 70 | /// 71 | protected void InvokeSTAThread(Action target, TArg1 arg1) 72 | { 73 | if (target == null) throw new ArgumentNullException("target"); 74 | 75 | Exception exception = null; 76 | 77 | // Define thread. 78 | var thread = new System.Threading.Thread(() => 79 | { 80 | // Thread specific try\catch. 81 | try 82 | { 83 | target(arg1); 84 | } 85 | catch (System.Exception ex) 86 | { 87 | exception = ex; 88 | } 89 | }); 90 | 91 | // Important! Set thread apartment state to STA. 92 | thread.SetApartmentState(System.Threading.ApartmentState.STA); 93 | 94 | // Start the thread. 95 | thread.Start(); 96 | 97 | // Wait for the thead to finish. 98 | thread.Join(); 99 | 100 | if (exception != null) 101 | { 102 | throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception); 103 | } 104 | } 105 | 106 | /// 107 | /// Invokes a method in a STA thread. 108 | /// 109 | /// The type of arg1. 110 | /// The type of arg2. 111 | /// 112 | /// 113 | /// 114 | protected void InvokeSTAThread(Action target, TArg1 arg1, TArg2 arg2) 115 | { 116 | if (target == null) throw new ArgumentNullException("target"); 117 | 118 | Exception exception = null; 119 | 120 | // Define thread. 121 | var thread = new System.Threading.Thread(() => 122 | { 123 | // Thread specific try\catch. 124 | try 125 | { 126 | target(arg1, arg2); 127 | } 128 | catch (System.Exception ex) 129 | { 130 | exception = ex; 131 | } 132 | }); 133 | 134 | // Important! Set thread apartment state to STA. 135 | thread.SetApartmentState(System.Threading.ApartmentState.STA); 136 | 137 | // Start the thread. 138 | thread.Start(); 139 | 140 | // Wait for the thead to finish. 141 | thread.Join(); 142 | 143 | if (exception != null) 144 | { 145 | throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception); 146 | } 147 | } 148 | 149 | /// 150 | /// Invokes a method in a STA thread. 151 | /// 152 | /// The type of arg1. 153 | /// The type of arg2. 154 | /// The type of arg3. 155 | /// 156 | /// 157 | /// 158 | /// 159 | protected void InvokeSTAThread(Action target, TArg1 arg1, TArg2 arg2, TArg3 arg3) 160 | { 161 | if (target == null) throw new ArgumentNullException("target"); 162 | 163 | Exception exception = null; 164 | 165 | // Define thread. 166 | var thread = new System.Threading.Thread(() => 167 | { 168 | // Thread specific try\catch. 169 | try 170 | { 171 | target(arg1, arg2, arg3); 172 | } 173 | catch (System.Exception ex) 174 | { 175 | exception = ex; 176 | } 177 | }); 178 | 179 | // Important! Set thread apartment state to STA. 180 | thread.SetApartmentState(System.Threading.ApartmentState.STA); 181 | 182 | // Start the thread. 183 | thread.Start(); 184 | 185 | // Wait for the thead to finish. 186 | thread.Join(); 187 | 188 | if (exception != null) 189 | { 190 | throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception); 191 | } 192 | } 193 | 194 | /// 195 | /// Invokes a method in a STA thread. 196 | /// 197 | /// The type of arg1. 198 | /// The type of arg2. 199 | /// The type of arg3. 200 | /// The type of arg4. 201 | /// 202 | /// 203 | /// 204 | /// 205 | /// 206 | protected void InvokeSTAThread(Action target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4) 207 | { 208 | if (target == null) throw new ArgumentNullException("target"); 209 | 210 | Exception exception = null; 211 | 212 | // Define thread. 213 | var thread = new System.Threading.Thread(() => 214 | { 215 | // Thread specific try\catch. 216 | try 217 | { 218 | target(arg1, arg2, arg3, arg4); 219 | } 220 | catch (System.Exception ex) 221 | { 222 | exception = ex; 223 | } 224 | }); 225 | 226 | // Important! Set thread apartment state to STA. 227 | thread.SetApartmentState(System.Threading.ApartmentState.STA); 228 | 229 | // Start the thread. 230 | thread.Start(); 231 | 232 | // Wait for the thead to finish. 233 | thread.Join(); 234 | 235 | if (exception != null) 236 | { 237 | throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception); 238 | } 239 | } 240 | 241 | /// 242 | /// Invokes a method in a STA thread. 243 | /// 244 | /// The type of the return value. 245 | /// 246 | /// An instance of TResult. 247 | protected TResult InvokeSTAThread(Func target) 248 | { 249 | if (target == null) throw new ArgumentNullException("target"); 250 | 251 | TResult returnValue = default(TResult); 252 | Exception exception = null; 253 | 254 | // Define thread. 255 | var thread = new System.Threading.Thread(() => 256 | { 257 | // Thread specific try\catch. 258 | try 259 | { 260 | returnValue = target(); 261 | } 262 | catch (System.Exception ex) 263 | { 264 | exception = ex; 265 | } 266 | }); 267 | 268 | // Important! Set thread apartment state to STA. 269 | thread.SetApartmentState(System.Threading.ApartmentState.STA); 270 | 271 | // Start the thread. 272 | thread.Start(); 273 | 274 | // Wait for the thead to finish. 275 | thread.Join(); 276 | 277 | if (exception != null) 278 | { 279 | throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception); 280 | } 281 | 282 | return returnValue; 283 | } 284 | 285 | /// 286 | /// Invokes a method in a STA thread. 287 | /// 288 | /// The type of arg1. 289 | /// The type of the return value. 290 | /// 291 | /// 292 | /// An instance of TResult. 293 | protected TResult InvokeSTAThread(Func target, TArg1 arg1) 294 | { 295 | if (target == null) throw new ArgumentNullException("target"); 296 | 297 | TResult returnValue = default(TResult); 298 | Exception exception = null; 299 | 300 | // Define thread. 301 | var thread = new System.Threading.Thread(() => 302 | { 303 | // Thread specific try\catch. 304 | try 305 | { 306 | returnValue = target(arg1); 307 | } 308 | catch (System.Exception ex) 309 | { 310 | exception = ex; 311 | } 312 | }); 313 | 314 | // Important! Set thread apartment state to STA. 315 | thread.SetApartmentState(System.Threading.ApartmentState.STA); 316 | 317 | // Start the thread. 318 | thread.Start(); 319 | 320 | // Wait for the thead to finish. 321 | thread.Join(); 322 | 323 | if (exception != null) 324 | { 325 | throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception); 326 | } 327 | 328 | return returnValue; 329 | } 330 | 331 | /// 332 | /// Invokes a method in a STA thread. 333 | /// 334 | /// The type of arg1. 335 | /// The type of arg2. 336 | /// The type of the return value. 337 | /// 338 | /// 339 | /// 340 | /// An instance of TResult. 341 | protected TResult InvokeSTAThread(Func target, TArg1 arg1, TArg2 arg2) 342 | { 343 | if (target == null) throw new ArgumentNullException("target"); 344 | 345 | TResult returnValue = default(TResult); 346 | Exception exception = null; 347 | 348 | // Define thread. 349 | var thread = new System.Threading.Thread(() => 350 | { 351 | // Thread specific try\catch. 352 | try 353 | { 354 | returnValue = target(arg1, arg2); 355 | } 356 | catch (System.Exception ex) 357 | { 358 | exception = ex; 359 | } 360 | }); 361 | 362 | // Important! Set thread apartment state to STA. 363 | thread.SetApartmentState(System.Threading.ApartmentState.STA); 364 | 365 | // Start the thread. 366 | thread.Start(); 367 | 368 | // Wait for the thead to finish. 369 | thread.Join(); 370 | 371 | if (exception != null) 372 | { 373 | throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception); 374 | } 375 | 376 | return returnValue; 377 | } 378 | 379 | /// 380 | /// Invokes a method in a STA thread. 381 | /// 382 | /// The type of arg1. 383 | /// The type of arg2. 384 | /// The type of arg3. 385 | /// The type of the return value. 386 | /// 387 | /// 388 | /// 389 | /// 390 | /// An instance of TResult. 391 | protected TResult InvokeSTAThread(Func target, TArg1 arg1, TArg2 arg2, TArg3 arg3) 392 | { 393 | if (target == null) throw new ArgumentNullException("target"); 394 | 395 | TResult returnValue = default(TResult); 396 | Exception exception = null; 397 | 398 | // Define thread. 399 | var thread = new System.Threading.Thread(() => 400 | { 401 | // Thread specific try\catch. 402 | try 403 | { 404 | returnValue = target(arg1, arg2, arg3); 405 | } 406 | catch (System.Exception ex) 407 | { 408 | exception = ex; 409 | } 410 | }); 411 | 412 | // Important! Set thread apartment state to STA. 413 | thread.SetApartmentState(System.Threading.ApartmentState.STA); 414 | 415 | // Start the thread. 416 | thread.Start(); 417 | 418 | // Wait for the thead to finish. 419 | thread.Join(); 420 | 421 | if (exception != null) 422 | { 423 | throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception); 424 | } 425 | 426 | return returnValue; 427 | } 428 | 429 | /// 430 | /// Invokes a method in a STA thread. 431 | /// 432 | /// The type of arg1. 433 | /// The type of arg2. 434 | /// The type of arg3. 435 | /// The type of arg4. 436 | /// The type of the return value. 437 | /// 438 | /// 439 | /// 440 | /// 441 | /// 442 | /// An instance of TResult. 443 | protected TResult InvokeSTAThread(Func target, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4) 444 | { 445 | if (target == null) throw new ArgumentNullException("target"); 446 | 447 | TResult returnValue = default(TResult); 448 | Exception exception = null; 449 | 450 | // Define thread. 451 | var thread = new System.Threading.Thread(() => 452 | { 453 | // Thread specific try\catch. 454 | try 455 | { 456 | returnValue = target(arg1, arg2, arg3, arg4); 457 | } 458 | catch (System.Exception ex) 459 | { 460 | exception = ex; 461 | } 462 | }); 463 | 464 | // Important! Set thread apartment state to STA. 465 | thread.SetApartmentState(System.Threading.ApartmentState.STA); 466 | 467 | // Start the thread. 468 | thread.Start(); 469 | 470 | // Wait for the thead to finish. 471 | thread.Join(); 472 | 473 | if (exception != null) 474 | { 475 | throw new System.Exception("An unhandled exception has occurred. See inner exception for details.", exception); 476 | } 477 | 478 | return returnValue; 479 | } 480 | 481 | /// 482 | /// Solid Edge Application property. 483 | /// 484 | public SolidEdgeFramework.Application Application 485 | { 486 | get { return _application; } 487 | set 488 | { 489 | _application = UnwrapRuntimeCallableWrapper(value); 490 | } 491 | } 492 | 493 | /// 494 | /// Solid Edge Application property. 495 | /// 496 | public SolidEdgeFramework.SolidEdgeDocument Document 497 | { 498 | get { return _document; } 499 | set 500 | { 501 | _document = UnwrapRuntimeCallableWrapper(value); 502 | } 503 | } 504 | 505 | /// 506 | /// Unwraps a runtime callable wrapper (RCW) that is passed across AppDomains. 507 | /// 508 | /// 509 | /// 510 | /// 511 | protected TInterface UnwrapRuntimeCallableWrapper(object rcw) where TInterface : class 512 | { 513 | if (RemotingServices.IsTransparentProxy(rcw)) 514 | { 515 | if (Marshal.IsComObject(rcw)) 516 | { 517 | IntPtr punk = Marshal.GetIUnknownForObject(rcw); 518 | 519 | try 520 | { 521 | return (TInterface)Marshal.GetObjectForIUnknown(punk); 522 | } 523 | finally 524 | { 525 | Marshal.Release(punk); 526 | } 527 | } 528 | else 529 | { 530 | throw new InvalidComObjectException(); 531 | } 532 | } 533 | 534 | return rcw as TInterface; 535 | } 536 | } 537 | } 538 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/OleMessageFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Threading; 4 | 5 | namespace SolidEdgeCommunity 6 | { 7 | enum SERVERCALL 8 | { 9 | SERVERCALL_ISHANDLED = 0, 10 | SERVERCALL_REJECTED = 1, 11 | SERVERCALL_RETRYLATER = 2 12 | } 13 | 14 | enum PENDINGMSG 15 | { 16 | PENDINGMSG_CANCELCALL = 0, 17 | PENDINGMSG_WAITNOPROCESS = 1, 18 | PENDINGMSG_WAITDEFPROCESS = 2 19 | } 20 | 21 | [ComImport] 22 | [Guid("00000016-0000-0000-C000-000000000046")] 23 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 24 | interface IMessageFilter 25 | { 26 | [PreserveSig] 27 | int HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo); 28 | 29 | [PreserveSig] 30 | int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType); 31 | 32 | [PreserveSig] 33 | int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType); 34 | } 35 | 36 | /// 37 | /// Class that implements the OLE IMessageFilter interface. 38 | /// 39 | public class OleMessageFilter : IMessageFilter 40 | { 41 | [DllImport("Ole32.dll")] 42 | static extern int CoRegisterMessageFilter(IMessageFilter newFilter, out IMessageFilter oldFilter); 43 | 44 | /// 45 | /// Private constructor. 46 | /// 47 | /// 48 | /// Instance of this class is only created by Register(). 49 | /// 50 | private OleMessageFilter() 51 | { 52 | } 53 | 54 | /// 55 | /// Destructor. 56 | /// 57 | ~OleMessageFilter() 58 | { 59 | // Call Unregister() for good measure. It's fine if this gets called twice. 60 | Unregister(); 61 | } 62 | 63 | /// 64 | /// Registers this instance of IMessageFilter with OLE to handle concurrency issues on the current thread. 65 | /// 66 | /// 67 | /// Only one message filter can be registered for each thread. 68 | /// Threads in multithreaded apartments cannot have message filters. 69 | /// Thread.CurrentThread.GetApartmentState() must equal ApartmentState.STA. In console applications, this can 70 | /// be achieved by applying the STAThreadAttribute to the Main() method. In WinForm applications, it is default. 71 | /// 72 | public static void Register() 73 | { 74 | IMessageFilter newFilter = new OleMessageFilter(); 75 | IMessageFilter oldFilter = null; 76 | 77 | // 1st check the current thread's apartment state. It must be STA! 78 | if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) 79 | { 80 | // Call CoRegisterMessageFilter(). 81 | Marshal.ThrowExceptionForHR(CoRegisterMessageFilter(newFilter: newFilter, oldFilter: out oldFilter)); 82 | } 83 | else 84 | { 85 | throw new System.Exception("The current thread's apartment state must be STA."); 86 | } 87 | } 88 | 89 | /// 90 | /// Unregisters a previous instance of IMessageFilter with OLE on the current thread. 91 | /// 92 | /// 93 | /// It is not necessary to call Unregister() unless you need to explicitly do so as it is handled 94 | /// in the destructor. 95 | /// 96 | public static void Unregister() 97 | { 98 | IMessageFilter oldFilter = null; 99 | 100 | // Call CoRegisterMessageFilter(). 101 | CoRegisterMessageFilter(newFilter: null, oldFilter: out oldFilter); 102 | } 103 | 104 | #region IMessageFilter 105 | 106 | public int HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo) 107 | { 108 | return (int)SERVERCALL.SERVERCALL_ISHANDLED; 109 | } 110 | 111 | public int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType) 112 | { 113 | // Cancel the outgoing call. This should be returned only under extreme conditions. Canceling a call that 114 | // has not replied or been rejected can create orphan transactions and lose resources. COM fails the original 115 | // call and returns RPC_E_CALL_CANCELLED. 116 | //return (int)NativeMethods.PENDINGMSG.PENDINGMSG_CANCELCALL; 117 | 118 | // Continue waiting for the reply, and do not dispatch the message unless it is a task-switching or 119 | // window-activation message. A subsequent message will trigger another call to MessagePending. 120 | //return (int)NativeMethods.PENDINGMSG.PENDINGMSG_WAITNOPROCESS; 121 | 122 | // Keyboard and mouse messages are no longer dispatched. However there are some cases where mouse and 123 | // keyboard messages could cause the system to deadlock, and in these cases, mouse and keyboard messages 124 | // are discarded. WM_PAINT messages are dispatched. Task-switching and activation messages are handled as before. 125 | return (int)PENDINGMSG.PENDINGMSG_WAITDEFPROCESS; 126 | } 127 | 128 | public int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType) 129 | { 130 | if (dwRejectType == (int)SERVERCALL.SERVERCALL_RETRYLATER) 131 | { 132 | // 0 ≤ value < 100 133 | // The call is to be retried immediately. 134 | return 99; 135 | 136 | // 100 ≤ value 137 | // COM will wait for this many milliseconds and then retry the call. 138 | // return 1000; // Wait 1 second before retrying the call. 139 | } 140 | 141 | // The call should be canceled. COM then returns RPC_E_CALL_REJECTED from the original method call. 142 | return -1; 143 | } 144 | 145 | #endregion 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | // Setting ComVisible to false makes the types in this assembly not visible 4 | // to COM components. If you need to access a type in this assembly from 5 | // COM, set the ComVisible attribute to true on that type. 6 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /src/SolidEdge.Community/Runtime/InteropServices/ComObject.cs: -------------------------------------------------------------------------------- 1 | using SolidEdgeCommunity.Runtime.InteropServices.ComTypes; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Runtime.InteropServices.ComTypes; 7 | using System.Text; 8 | 9 | namespace SolidEdgeCommunity.Runtime.InteropServices 10 | { 11 | /// 12 | /// COM object wrapper class. 13 | /// 14 | public class ComObject 15 | { 16 | const int LOCALE_SYSTEM_DEFAULT = 2048; 17 | 18 | /// 19 | /// Using IDispatch, returns the ITypeInfo of the specified object. 20 | /// 21 | /// 22 | /// 23 | public static ITypeInfo GetITypeInfo(object comObject) 24 | { 25 | if (Marshal.IsComObject(comObject) == false) throw new InvalidComObjectException(); 26 | 27 | var dispatch = comObject as IDispatch; 28 | 29 | if (dispatch != null) 30 | { 31 | return dispatch.GetTypeInfo(0, LOCALE_SYSTEM_DEFAULT); 32 | } 33 | 34 | return null; 35 | } 36 | 37 | /// 38 | /// Returns a strongly typed property by name using the specified COM object. 39 | /// 40 | /// The type of the property to return. 41 | /// 42 | /// The name of the property to retrieve. 43 | /// 44 | public static T GetPropertyValue(object comObject, string name) 45 | { 46 | if (Marshal.IsComObject(comObject) == false) throw new InvalidComObjectException(); 47 | 48 | var type = comObject.GetType(); 49 | var value = type.InvokeMember(name, System.Reflection.BindingFlags.GetProperty, null, comObject, null); 50 | 51 | return (T)value; 52 | } 53 | 54 | /// 55 | /// Returns a strongly typed property by name using the specified COM object. 56 | /// 57 | /// The type of the property to return. 58 | /// 59 | /// The name of the property to retrieve. 60 | /// The value to return if the property does not exist. 61 | /// 62 | public static T GetPropertyValue(object comObject, string name, T defaultValue) 63 | { 64 | if (Marshal.IsComObject(comObject) == false) throw new InvalidComObjectException(); 65 | 66 | var type = comObject.GetType(); 67 | 68 | try 69 | { 70 | var value = type.InvokeMember(name, System.Reflection.BindingFlags.GetProperty, null, comObject, null); 71 | return (T)value; 72 | } 73 | catch 74 | { 75 | return defaultValue; 76 | } 77 | } 78 | 79 | /// 80 | /// Using IDispatch, determine the managed type of the specified object. 81 | /// 82 | /// 83 | /// 84 | public static Type GetType(object comObject) 85 | { 86 | if (Marshal.IsComObject(comObject) == false) throw new InvalidComObjectException(); 87 | 88 | Type type = null; 89 | var dispatch = comObject as IDispatch; 90 | ITypeInfo typeInfo = null; 91 | var pTypeAttr = IntPtr.Zero; 92 | var typeAttr = default(System.Runtime.InteropServices.ComTypes.TYPEATTR); 93 | 94 | try 95 | { 96 | if (dispatch != null) 97 | { 98 | typeInfo = dispatch.GetTypeInfo(0, LOCALE_SYSTEM_DEFAULT); 99 | typeInfo.GetTypeAttr(out pTypeAttr); 100 | typeAttr = (System.Runtime.InteropServices.ComTypes.TYPEATTR)Marshal.PtrToStructure(pTypeAttr, typeof(System.Runtime.InteropServices.ComTypes.TYPEATTR)); 101 | 102 | // Type can technically be defined in any loaded assembly. 103 | var assemblies = AppDomain.CurrentDomain.GetAssemblies(); 104 | 105 | // Scan each assembly for a type with a matching GUID. 106 | foreach (var assembly in assemblies) 107 | { 108 | type = assembly.GetTypes() 109 | .Where(x => x.IsInterface) 110 | .Where(x => x.GUID.Equals(typeAttr.guid)) 111 | .FirstOrDefault(); 112 | 113 | if (type != null) 114 | { 115 | // Found what we're looking for so break out of the loop. 116 | break; 117 | } 118 | } 119 | } 120 | } 121 | finally 122 | { 123 | if (typeInfo != null) 124 | { 125 | typeInfo.ReleaseTypeAttr(pTypeAttr); 126 | Marshal.ReleaseComObject(typeInfo); 127 | } 128 | } 129 | 130 | return type; 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/Runtime/InteropServices/ComTypes/IDispatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Runtime.InteropServices.ComTypes; 6 | using System.Text; 7 | 8 | namespace SolidEdgeCommunity.Runtime.InteropServices.ComTypes 9 | { 10 | [ComImport] 11 | [Guid("00020400-0000-0000-C000-000000000046")] 12 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 13 | interface IDispatch 14 | { 15 | int GetTypeInfoCount(); 16 | ITypeInfo GetTypeInfo(int iTInfo, int lcid); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/SolidEdge.Community.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | NET40;NET45 5 | 219.0.0.0 6 | 219.0.0.0 7 | 219.0.0 8 | Jason Newell 9 | Jason Newell 10 | Community provided package for automating Solid Edge. 11 | https://github.com/SolidEdgeCommunity/SolidEdge.Community/blob/master/LICENSE.md 12 | https://github.com/SolidEdgeCommunity/SolidEdge.Community 13 | https://raw.githubusercontent.com/SolidEdgeCommunity/SolidEdge.Community/master/media/icon.png 14 | https://github.com/SolidEdgeCommunity/SolidEdge.Community.git 15 | git 16 | interop solidedge community contrib 17 | true 18 | 19 | 20 | 21 | bin\Release\net40\SolidEdge.Community.xml 22 | 23 | 24 | 25 | bin\Release\net45\SolidEdge.Community.xml 26 | 27 | 28 | 29 | 30 | None 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/SolidEdge.Community/SolidEdgeUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | 8 | namespace SolidEdgeCommunity 9 | { 10 | /// 11 | /// Helper class for interaction with Solid Edge. 12 | /// 13 | public static class SolidEdgeUtils 14 | { 15 | //[DllImport("ole32.dll")] 16 | //static extern int CreateBindCtx(uint reserved, out IBindCtx ppbc); 17 | 18 | //[DllImport("ole32.dll")] 19 | //static extern void GetRunningObjectTable(int reserved, out IRunningObjectTable prot); 20 | 21 | //const int MK_E_UNAVAILABLE = (int)(0x800401E3 - 0x100000000); 22 | const int MK_E_UNAVAILABLE = unchecked((int)0x800401E3); 23 | 24 | /// 25 | /// Connects to a running instance of Solid Edge. 26 | /// 27 | /// 28 | /// An object of type SolidEdgeFramework.Application. 29 | /// 30 | public static SolidEdgeFramework.Application Connect() 31 | { 32 | return Connect(startIfNotRunning: false); 33 | } 34 | 35 | /// 36 | /// Connects to or starts a new instance of Solid Edge. 37 | /// 38 | /// 39 | /// 40 | /// An object of type SolidEdgeFramework.Application. 41 | /// 42 | public static SolidEdgeFramework.Application Connect(bool startIfNotRunning) 43 | { 44 | try 45 | { 46 | // Attempt to connect to a running instance of Solid Edge. 47 | return (SolidEdgeFramework.Application)Marshal.GetActiveObject(progID: SolidEdgeSDK.PROGID.SolidEdge_Application); 48 | } 49 | catch (System.Runtime.InteropServices.COMException ex) 50 | { 51 | switch (ex.ErrorCode) 52 | { 53 | // Solid Edge is not running. 54 | case MK_E_UNAVAILABLE: 55 | if (startIfNotRunning) 56 | { 57 | // Start Solid Edge. 58 | return Start(); 59 | } 60 | else 61 | { 62 | // Rethrow exception. 63 | throw; 64 | } 65 | default: 66 | // Rethrow exception. 67 | throw; 68 | } 69 | } 70 | catch 71 | { 72 | // Rethrow exception. 73 | throw; 74 | } 75 | } 76 | 77 | /// 78 | /// Connects to or starts a new instance of Solid Edge. 79 | /// 80 | /// 81 | /// 82 | /// 83 | /// An object of type SolidEdgeFramework.Application. 84 | /// 85 | public static SolidEdgeFramework.Application Connect(bool startIfNotRunning, bool ensureVisible) 86 | { 87 | SolidEdgeFramework.Application application = null; 88 | 89 | try 90 | { 91 | // Attempt to connect to a running instance of Solid Edge. 92 | application = (SolidEdgeFramework.Application)Marshal.GetActiveObject(progID: SolidEdgeSDK.PROGID.SolidEdge_Application); 93 | } 94 | catch (System.Runtime.InteropServices.COMException ex) 95 | { 96 | switch (ex.ErrorCode) 97 | { 98 | // Solid Edge is not running. 99 | case MK_E_UNAVAILABLE: 100 | if (startIfNotRunning) 101 | { 102 | // Start Solid Edge. 103 | application = Start(); 104 | break; 105 | } 106 | else 107 | { 108 | // Rethrow exception. 109 | throw; 110 | } 111 | default: 112 | // Rethrow exception. 113 | throw; 114 | } 115 | } 116 | catch 117 | { 118 | // Rethrow exception. 119 | throw; 120 | } 121 | 122 | if ((application != null) && (ensureVisible)) 123 | { 124 | application.Visible = true; 125 | } 126 | 127 | return application; 128 | } 129 | 130 | /// 131 | /// Returns the path to the Solid Edge installation folder. 132 | /// 133 | /// 134 | /// Typically 'C:\Program Files\Solid Edge XXX'. 135 | /// 136 | public static string GetInstalledPath() 137 | { 138 | /* Get path to Solid Edge program directory. */ 139 | var programDirectory = new DirectoryInfo(GetProgramFolderPath()); 140 | 141 | /* Get path to Solid Edge installation directory. */ 142 | var installationDirectory = programDirectory.Parent; 143 | 144 | return installationDirectory.FullName; 145 | } 146 | 147 | public static System.Globalization.CultureInfo GetInstalledLanguage() 148 | { 149 | var installData = new SEInstallDataLib.SEInstallData(); 150 | 151 | try 152 | { 153 | return System.Globalization.CultureInfo.GetCultureInfo(installData.GetLanguageID()); 154 | } 155 | finally 156 | { 157 | if (installData != null) 158 | { 159 | Marshal.ReleaseComObject(installData); 160 | } 161 | } 162 | } 163 | 164 | /// 165 | /// Returns the path to the Solid Edge program folder. 166 | /// 167 | /// 168 | /// Typically 'C:\Program Files\Solid Edge XXX\Program'. 169 | /// 170 | public static string GetProgramFolderPath() 171 | { 172 | var installData = new SEInstallDataLib.SEInstallData(); 173 | 174 | try 175 | { 176 | /* Get path to Solid Edge program directory. */ 177 | return installData.GetInstalledPath(); 178 | } 179 | finally 180 | { 181 | if (installData != null) 182 | { 183 | Marshal.ReleaseComObject(installData); 184 | } 185 | } 186 | } 187 | 188 | //public static SolidEdgeFramework.Application[] GetRunningInstances() 189 | //{ 190 | // List instances = new List(); 191 | // Type type = Type.GetTypeFromProgID(SolidEdge.PROGID.Application); 192 | // var clsid = type.GUID.ToString(); 193 | 194 | // // get Running Object Table ... 195 | // IRunningObjectTable rot = null; 196 | // GetRunningObjectTable(0, out rot); 197 | 198 | // if (rot != null) 199 | // { 200 | // // get enumerator for ROT entries 201 | // IEnumMoniker monikerEnumerator = null; 202 | // rot.EnumRunning(out monikerEnumerator); 203 | 204 | // if (monikerEnumerator != null) 205 | // { 206 | // monikerEnumerator.Reset(); 207 | 208 | // IntPtr pNumFetched = new IntPtr(); 209 | // IMoniker[] monikers = new IMoniker[1]; 210 | 211 | // while (monikerEnumerator.Next(1, monikers, pNumFetched) == 0) 212 | // { 213 | // IBindCtx bindCtx; 214 | // CreateBindCtx(0, out bindCtx); 215 | 216 | // if (bindCtx == null) 217 | // continue; 218 | 219 | // string displayName; 220 | // monikers[0].GetDisplayName(bindCtx, null, out displayName); 221 | 222 | // Guid pClassID = Guid.Empty; 223 | // monikers[0].GetClassID(out pClassID); 224 | 225 | // if (displayName.IndexOf(clsid, StringComparison.OrdinalIgnoreCase) > 0) 226 | // { 227 | // object comObject; 228 | // rot.GetObject(monikers[0], out comObject); 229 | 230 | // if (comObject != null) 231 | // { 232 | // var applicationInstance = comObject as SolidEdgeFramework.Application; 233 | // if (applicationInstance != null) 234 | // { 235 | // instances.Add(applicationInstance); 236 | // } 237 | // } 238 | // } 239 | 240 | // } 241 | // } 242 | // } 243 | 244 | // return instances.ToArray(); 245 | //} 246 | 247 | /// 248 | /// Returns the path to the Solid Edge training folder. 249 | /// 250 | /// 251 | /// Typically 'C:\Program Files\Solid Edge XXX\Training'. 252 | /// 253 | public static string GetTrainingFolderPath() 254 | { 255 | /* Get path to Solid Edge training directory. */ 256 | var trainingDirectory = new DirectoryInfo(Path.Combine(GetInstalledPath(), "Training")); 257 | 258 | return trainingDirectory.FullName; 259 | } 260 | 261 | /// 262 | /// Returns a Version object representing the installed version of Solid Edge. 263 | /// 264 | /// 265 | public static Version GetVersion() 266 | { 267 | var installData = new SEInstallDataLib.SEInstallData(); 268 | 269 | return new Version(installData.GetMajorVersion(), installData.GetMinorVersion(), installData.GetServicePackVersion(), installData.GetBuildNumber()); 270 | } 271 | 272 | /// 273 | /// Creates and returns a new instance of Solid Edge. 274 | /// 275 | /// 276 | /// An object of type SolidEdgeFramework.Application. 277 | /// 278 | public static SolidEdgeFramework.Application Start() 279 | { 280 | // On a system where Solid Edge is installed, the COM ProgID will be 281 | // defined in registry: HKEY_CLASSES_ROOT\SolidEdge.Application 282 | Type t = Type.GetTypeFromProgID(progID: SolidEdgeSDK.PROGID.SolidEdge_Application, throwOnError: true); 283 | 284 | // Using the discovered Type, create and return a new instance of Solid Edge. 285 | return (SolidEdgeFramework.Application)Activator.CreateInstance(type: t); 286 | } 287 | } 288 | } 289 | --------------------------------------------------------------------------------