Imports System.Runtime.InteropServices
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim objSEApp As SolidEdgeFramework.Application = Nothing
Dim objAsmDoc As SolidEdgeAssembly.AssemblyDocument = Nothing
Dim objHarnesses As SolidEdgeAssembly.Harnesses = Nothing
Dim objHarness As SolidEdgeAssembly.Harness = Nothing
Dim SEInstallDir As DirectoryInfo
Dim strPath1, strPath2 As String
Dim Occ1, Occ2 As String
Dim strCompanyName As String = "Bentley - promis-e"
Try
' Get SE Application object.
Try
objSEApp = Marshal.GetActiveObject("SolidEdge.Application")
Catch ex As Exception
objSEApp = Activator.CreateInstance(Type.GetTypeFromProgID("SolidEdge.Application"))
objSEApp.DisplayAlerts = True
objSEApp.Visible = True
End Try
'Get Path of Training folder
SEInstallDir = GetTrainingFolder()
strPath1 = SEInstallDir.FullName + "\Wiring Harness\seeabwh2.cmp"
strPath2 = SEInstallDir.FullName + "\Wiring Harness\seeabwh2.con"
Occ1 = SEInstallDir.FullName + "\Wiring Harness\gauge3.par"
Occ2 = SEInstallDir.FullName + "\Wiring Harness\plug4.par"
'Add new assembly file
objAsmDoc = objSEApp.Documents.Add("SolidEdge.AssemblyDocument")
objAsmDoc.Occurrences.AddByFilename(Occ1)
objAsmDoc.Occurrences.AddByFilename(Occ2)
objHarnesses = objAsmDoc.Harnesses
objHarnesses.CreateFromNetlistImporter(strCompanyName, strPath1, strPath2)
objHarness = objHarnesses.Item(1)
objHarness.SaveAsEcad(SolidEdgeAssembly.HarnessSaveAsEcadStatusConstants.seHarnessSaveAsEcadStatus_Success, strCompanyName, strPath1, strPath2)
Catch ex As Exception
MsgBox(ex.ToString)
Finally
' USER DISPLAY
' Release objects
objSEApp = Nothing
objAsmDoc = Nothing
End Try
End Sub
Function GetTrainingFolder() As DirectoryInfo
Dim objInstallData As SEInstallDataLib.SEInstallData = Nothing
Dim objInstallFolder As DirectoryInfo = Nothing
Dim objTrainingFolder As DirectoryInfo = Nothing
Try
objInstallData = New SEInstallDataLib.SEInstallData
objInstallFolder = New DirectoryInfo(objInstallData.GetInstalledPath())
objTrainingFolder = New DirectoryInfo(Path.Combine(objInstallFolder.Parent.FullName, "Training"))
Catch
Finally
If Not (objInstallData Is Nothing) Then
Marshal.FinalReleaseComObject(objInstallData)
objInstallData = Nothing
End If
End Try
Return objTrainingFolder
End Function
End Class
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
public class Form1
{
private void Button1_Click(object sender, EventArgs e)
{
SolidEdgeFramework.Application objSEApp = null;
SolidEdgeAssembly.AssemblyDocument objAsmDoc = null;
SolidEdgeAssembly.Harnesses objHarnesses = null;
SolidEdgeAssembly.Harness objHarness = null;
DirectoryInfo SEInstallDir = null;
string strPath1 = null;
string strPath2 = null;
string Occ1 = null;
string Occ2 = null;
string strCompanyName = "Bentley - promis-e";
try
{
// Get SE Application object.
try
{
objSEApp = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
}
catch (Exception ex)
{
objSEApp = Activator.CreateInstance(Type.GetTypeFromProgID("SolidEdge.Application"));
objSEApp.DisplayAlerts = true;
objSEApp.Visible = true;
}
//Get Path of Training folder
SEInstallDir = GetTrainingFolder();
strPath1 = SEInstallDir.FullName + "\\Wiring Harness\\seeabwh2.cmp";
strPath2 = SEInstallDir.FullName + "\\Wiring Harness\\seeabwh2.con";
Occ1 = SEInstallDir.FullName + "\\Wiring Harness\\gauge3.par";
Occ2 = SEInstallDir.FullName + "\\Wiring Harness\\plug4.par";
//Add new assembly file
objAsmDoc = objSEApp.Documents.Add("SolidEdge.AssemblyDocument");
objAsmDoc.Occurrences.AddByFilename(Occ1);
objAsmDoc.Occurrences.AddByFilename(Occ2);
objHarnesses = objAsmDoc.Harnesses;
objHarnesses.CreateFromNetlistImporter(strCompanyName, strPath1, strPath2);
objHarness = objHarnesses.Item(1);
objHarness.SaveAsEcad(SolidEdgeAssembly.HarnessSaveAsEcadStatusConstants.seHarnessSaveAsEcadStatus_Success, strCompanyName, strPath1, strPath2);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
// USER DISPLAY
// Release objects
objSEApp = null;
objAsmDoc = null;
}
}
public DirectoryInfo GetTrainingFolder()
{
SEInstallDataLib.SEInstallData objInstallData = null;
DirectoryInfo objInstallFolder = null;
DirectoryInfo objTrainingFolder = null;
try
{
objInstallData = new SEInstallDataLib.SEInstallData();
objInstallFolder = new DirectoryInfo(objInstallData.GetInstalledPath());
objTrainingFolder = new DirectoryInfo(Path.Combine(objInstallFolder.Parent.FullName, "Training"));
}
catch
{
}
finally
{
if (objInstallData != null)
{
Marshal.FinalReleaseComObject(objInstallData);
objInstallData = null;
}
}
return objTrainingFolder;
}
public Form1()
{
SubscribeToEvents();
}
private bool EventsSubscribed = false;
private void SubscribeToEvents()
{
if (EventsSubscribed)
return;
else
EventsSubscribed = true;
Button1.Click += Button1_Click;
}
}