Programmer's Guide > Solid Edge > Frequently Used Programs |
Following function will return Solid Edge Version.
Public Function oGetSolidEdgeVersion() As String Try Dim install As New SEInstallDataLib.SEInstallData Dim strSEVersion As String = String.Empty strSEVersion = install.GetVersion.ToString oReleaseObject(install) oForceGarbageCollection() Return strSEVersion Catch ex As Exception Return Nothing End Try End Function
public string oGetSolidEdgeVersion() { try { SEInstallDataLib.SEInstallData install = new SEInstallDataLib.SEInstallData(); string strSEVersion = string.Empty; strSEVersion = install.GetVersion.ToString(); oReleaseObject(install); oForceGarbageCollection(); return strSEVersion; } catch (Exception ex) { return null; } }
Following function will return Solid Edge Path.
Public Function () As String Dim strSEPath As String = String.Empty Dim install As SEInstallDataLib.SEInstallData = Nothing Try install = New SEInstallDataLib.SEInstallData strSEPath = install.GetInstalledPath Catch ex As Exception Return Nothing Finally oReleaseObject(install) oForceGarbageCollection() End Try Return strSEPath End Function
public string[] Function; private string strSEPath = string.Empty; private SEInstallDataLib.SEInstallData install = null; Try; install = new SEInstallDataLib.SEInstallData(); strSEPath = install.GetInstalledPath; } catch (Exception ex) { return null; } finally { oReleaseObject(install); oForceGarbageCollection(); } return strSEPath; }
Following function will return Solid Edge Status.
Public Function oGetSEStatus(ByVal strFName As String) As SolidEdgeFramework.DocumentStatus Dim objPropertySets As SolidEdgeFileProperties.PropertySets = Nothing Try objPropertySets = New SolidEdgeFileProperties.PropertySets Call objPropertySets.Open(strFName, True) Return objPropertySets.Item("ExtendedSummaryInformation").item("Status").value objPropertySets.Close() oReleaseObject(objPropertySets) oForceGarbageCollection() Exit Function Catch ex As Exception Return SolidEdgeFramework.DocumentStatus.igStatusUnknown oReleaseObject(objPropertySets) oForceGarbageCollection() Exit Function End Try End Function
public SolidEdgeFramework.DocumentStatus oGetSEStatus(string strFName) { SolidEdgeFileProperties.PropertySets objPropertySets = null; try { objPropertySets = new SolidEdgeFileProperties.PropertySets(); objPropertySets.Open(strFName, true); return objPropertySets.Item("ExtendedSummaryInformation").item("Status").value; objPropertySets.Close(); oReleaseObject(objPropertySets); oForceGarbageCollection(); return null; } catch (Exception ex) { return SolidEdgeFramework.DocumentStatus.igStatusUnknown; oReleaseObject(objPropertySets); oForceGarbageCollection(); return null; } }
Following function will release Solid Edge Object.
Sub (ByVal obj As Object) Try If Not (obj Is Nothing) Then 'this should only be used when programming applications that run in their own process space Marshal.FinalReleaseComObject(obj) End If Catch ex As Exception obj = Nothing End Try End Sub
(object obj) => { try { if (obj != null) { //this should only be used when programming applications that run in their own process space Marshal.FinalReleaseComObject(obj); } } catch (Exception ex) { obj = null; } };
Following function will kill Solid Edge Process.
Public Function (ByVal Name As String) As Long Dim LocalProcs As Process() Dim Proc As Process Dim i As Integer LocalProcs = System.Diagnostics.Process.GetProcesses For Each Proc In LocalProcs If UCase(Proc.ProcessName) = UCase(Name) Then Try Proc.Kill() oReleaseObject(Proc) oReleaseObject(LocalProcs) oForceGarbageCollection() Return 0 Catch ex As System.Exception oReleaseObject(Proc) oReleaseObject(LocalProcs) oForceGarbageCollection() Return 1 Exit Function End Try End If i += 1 Next oReleaseObject(Proc) oReleaseObject(LocalProcs) oForceGarbageCollection() Return 1 End Function
public long Function; private Process[] LocalProcs; private Process Proc; private int i; LocalProcs = System.Diagnostics.Process.GetProcesses(); foreach (Process Proc in LocalProcs) { if (Proc.ProcessName.ToUpper() == Convert.ToString(Name).ToUpper()) { try { Proc.Kill(); oReleaseObject(Proc); oReleaseObject(LocalProcs); oForceGarbageCollection(); return 0; } catch (System.Exception ex) { oReleaseObject(Proc); oReleaseObject(LocalProcs); oForceGarbageCollection(); return 1; return; } } i += 1; } oReleaseObject(Proc); oReleaseObject(LocalProcs); oForceGarbageCollection(); return 1; }
Following function will check file attribute.
Public Function (ByVal filename As String, ByVal attribute As IO.FileAttributes) As Boolean If IO.File.Exists(filename) Then If (IO.File.GetAttributes(filename) And attribute) > 0 Then Return True Else Return False End If Else Return False End If End Function
public bool Function; if (IO.File.Exists(filename)) { if ((IO.File.GetAttributes(filename) & attribute) > 0) { return true; } else { return false; } } else { return false; } }
Following function will help you to connect to Revision Manager..
Public Function (ByVal blnAppVisibility As Boolean, ByVal blnDisplayAlerts As Boolean) As Boolean 'to connect to a running instance of Revision Manager Try '("Word.Application") '("Excel.Application") '("RevisionManager.Application") objRevManApp = Marshal.GetActiveObject("RevisionManager.Application") objRevManApp.DisplayAlerts = blnDisplayAlerts objRevManApp.Visible = blnAppVisibility Return True Catch ex As System.Exception 'SE not running then start it Try objRevManApp = Activator.CreateInstance(objRevManType) objRevManApp.DisplayAlerts = blnDisplayAlerts objRevManApp.Visible = blnAppVisibility Return True Catch ex1 As Exception Return False End Try End Try Return False End Function
public bool Function; //to connect to a running instance of Revision Manager Try; //("Word.Application") //("Excel.Application") //("RevisionManager.Application") objRevManApp = (RevisionManager.Application)Marshal.GetActiveObject("RevisionManager.Application"); objRevManApp.DisplayAlerts = blnDisplayAlerts; objRevManApp.Visible = blnAppVisibility; return true; } catch (System.Exception ex) { //SE not running then start it try { objRevManApp = Activator.CreateInstance(objRevManType); objRevManApp.DisplayAlerts = blnDisplayAlerts; objRevManApp.Visible = blnAppVisibility; return true; } catch (Exception ex1) { return false; } } return false; }
Following function will determine whether File Name is valid or not.
Public Function (ByVal fn As String) As Boolean Try If System.IO.File.Exists(fn) Then Return True Else Return False End If Catch ex As Exception Return False End Try End Function
public bool Function; Try; if (System.IO.File.Exists(fn)) { return true; } else { return false; } } catch (Exception ex) { return false; } }
Following function will determine if file is Solid Edge file or not.
'pass in the full path including filename or just the filename Public Function (ByVal Filename As String) As Boolean Try Dim validFileTypes As String() = {"par", "psm", "asm", "dft", "pwd"} Dim strFileNameOnly As String = String.Empty strFileNameOnly = System.IO.Path.GetFileName(Filename) If strFileNameOnly = String.Empty Then Return False End If If System.IO.Path.HasExtension(strFileNameOnly) Then 'it has an extension now check to see if it is a valid SE one Dim strExtension As String = System.IO.Path.GetExtension(strFileNameOnly) For i As Integer = 0 To validFileTypes.Length - 1 If strExtension.ToLower = "." + validFileTypes(i).ToLower Then Return True End If Next Return False Else Return False End If Catch ex As Exception Return False End Try End Function
//pass in the full path including filename or just the filename public bool Function; Try; string[] validFileTypes = {"par", "psm", "asm", "dft", "pwd"}; string strFileNameOnly = string.Empty; strFileNameOnly = System.IO.Path.GetFileName(filename); if (string.IsNullOrEmpty(strFileNameOnly)) { return false; } if (System.IO.Path.HasExtension(strFileNameOnly)) { //it has an extension now check to see if it is a valid SE one string strExtension = System.IO.Path.GetExtension(strFileNameOnly); for (int i = 0; i < validFileTypes.Length; i++) { if (strExtension.ToLower() == "." + validFileTypes[i].ToLower()) { return true; } } return false; } else { return false; } } catch (Exception ex) { return false; } }
Following function will determine if File is Solid Edge Part file or not.
'pass in the full path including filename or just the filename Public Function (ByVal Filename As String) As Boolean Dim sExtension As String = Nothing Dim bPart As Boolean = False Try sExtension = System.IO.Path.GetExtension(Filename) If (sExtension.ToLower = ".par") Then Return True Else Return False End If Catch ex As Exception Return False End Try End Function
//pass in the full path including filename or just the filename public bool Function; private string sExtension = null; private bool bPart = false; Try; sExtension = System.IO.Path.GetExtension(filename); if (sExtension.ToLower() == ".par") { return true; } else { return false; } } catch (Exception ex) { return false; } }
Following function will determine if File is Solid Edge Sheet Metal file or not.
'pass in the full path including filename or just the filename Public Function oIsSolidEdgeSheetMetalFile(ByVal Filename As String) As Boolean Dim sExtension As String = Nothing Dim bPart As Boolean = False Try sExtension = System.IO.Path.GetExtension(Filename) If (sExtension.ToLower = ".psm") Then Return True Else Return False End If Catch ex As Exception Return False End Try End Function
//pass in the full path including filename or just the filename public bool oIsSolidEdgeSheetMetalFile(string Filename) { string sExtension = null; bool bPart = false; try { sExtension = System.IO.Path.GetExtension(Filename); if (sExtension.ToLower() == ".psm") { return true; } else { return false; } } catch (Exception ex) { return false; } }
Following function will determine if File is Solid Edge Draft file or not.
'pass in the full path including filename or just the filename Public Function (ByVal Filename As String) As Boolean Dim sExtension As String = Nothing Dim bPart As Boolean = False Try sExtension = System.IO.Path.GetExtension(Filename) If (sExtension.ToLower = ".dft") Then Return True Else Return False End If Catch ex As Exception Return False End Try End Function
//pass in the full path including filename or just the filename public bool Function; private string sExtension = null; private bool bPart = false; Try; sExtension = System.IO.Path.GetExtension(filename); if (sExtension.ToLower() == ".dft") { return true; } else { return false; } } catch (Exception ex) { return false; } }
Following function will determine if File is Solid Edge Assembly file or not.
'pass in the full path including filename or just the filename Public Function (ByVal Filename As String) As Boolean Dim sExtension As String = Nothing Dim bPart As Boolean = False Try sExtension = System.IO.Path.GetExtension(Filename) If (sExtension.ToLower = ".asm") Then Return True Else Return False End If Catch ex As Exception Return False End Try End Function
//pass in the full path including filename or just the filename public bool Function; private string sExtension = null; private bool bPart = false; Try; sExtension = System.IO.Path.GetExtension(filename); if (sExtension.ToLower() == ".asm") { return true; } else { return false; } } catch (Exception ex) { return false; } }
Following function will determine if File is Solid Edge Weldment file or not.
'pass in the full path including filename or just the filename Public Function (ByVal Filename As String) As Boolean Dim sExtension As String = Nothing Dim bPart As Boolean = False Try sExtension = System.IO.Path.GetExtension(Filename) If (sExtension.ToLower = ".pwd") Then Return True Else Return False End If Catch ex As Exception Return False End Try End Function
//pass in the full path including filename or just the filename public bool Function; private string sExtension = null; private bool bPart = false; Try; sExtension = System.IO.Path.GetExtension(filename); if (sExtension.ToLower() == ".pwd") { return true; } else { return false; } } catch (Exception ex) { return false; } }
DotNet has a garbage collection mechanism that runs indeterminately. When Solid Edge detects that either .NET runtime, 2.0 or 4.0, is running in the process, Solid Edge will initiate garbage collection at various points in time such as immediately after the before document event is fired. Some heavy .NET memory users have complained that this can cause delays for their .NET add-ins. So, these global parameters can be used to prevent Solid Edge from running GC automatically.
However, it is advisable to allow Solid Edge to run GC when it deems it necessary to do so. This is important because .NET will hold references to document objects that are about to be unmapped from memory. After the objects are unmapped, if .NET GC runs later and actually tries to release the objects, .NET can cause memory exceptions as it accesses the unmapped memory.
To enable or disable GC mechanism user can pass second argument as “True” or “False” respectively as shown in below sample code.
Imports System.Runtime.InteropServices Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim objApplication As SolidEdgeFramework.Application = Nothing Dim boolPref As Boolean = False Try 'Get SolidEdge object objApplication = Marshal.GetActiveObject("SolidEdge.Application") 'Set value for seApplicationGlobalEnableDotNet4GC variable objApplication.SetGlobalParameter(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalEnableDotNet4GC, "True") 'Get value from seApplicationGlobalEnableDotNet4GC variable objApplication.GetGlobalParameter(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalEnableDotNet4GC, boolPref) Catch ex As Exception Console.WriteLine(ex.Message) Finally objApplication = Nothing End Try End Sub End Class
public class Form1 { private void Button1_Click(object sender, EventArgs e) { SolidEdgeFramework.Application objApplication = null; bool boolPref = false; try { //Get SolidEdge object objApplication = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application"); //Set value for seApplicationGlobalEnableDotNet4GC variable objApplication.SetGlobalParameter(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalEnableDotNet4GC, "True"); //Get value from seApplicationGlobalEnableDotNet4GC variable objApplication.GetGlobalParameter(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalEnableDotNet4GC, boolPref); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { objApplication = null; } } public Form1() { SubscribeToEvents(); } private bool EventsSubscribed = false; private void SubscribeToEvents() { if (EventsSubscribed) return; else EventsSubscribed = true; Button1.Click += Button1_Click; } }