Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim objApp As SolidEdgeFramework.Application = Nothing
Dim objType As Type = Nothing
Dim objMatTable As SolidEdgeFramework.MatTable = Nothing
Dim strLibrary As String = "Materials"
Dim objDocument As SolidEdgePart.PartDocument = Nothing
Dim strMaterial As String = ""
Dim strMessage As String
Dim varGetPropVal As Object = Nothing
Dim nUnitType As SolidEdgeFramework.UnitTypeConstants = 0
Dim strPropName As String = ""
Try
' Get SE handle
objApp = Marshal.GetActiveObject("SolidEdge.Application")
If objApp Is Nothing Then
' Get the type from the Solid Edge ProgID
objType = Type.GetTypeFromProgID("SolidEdge.Application")
' Start Solid Edge
objApp = Activator.CreateInstance(objType)
' Make Solid Edge visible
objApp.Visible = True
End If
' Get material table object handle
objMatTable = objApp.GetMaterialTable()
objDocument = objApp.Documents.Add("SolidEdge.Partdocument")
strMaterial = "Steel"
objMatTable.AddCustomProperty(strMaterial, strLibrary, "My Custom Property ", 1, 152.66)
objMatTable.AddCustomProperty(strMaterial, strLibrary, "SE Custom Property ", 13, 42.98)
objMatTable.ApplyMaterialToDoc(objDocument, strMaterial, strLibrary)
objMatTable.GetCustomMaterialPropertyFromDoc(objDocument, 1, strPropName, nUnitType, varGetPropVal)
strMessage = String.Format("Custom Property of STEEL - Name: {0}, Unit Type: {1}, Value: {2}", strPropName, nUnitType, varGetPropVal)
MsgBox(strMessage)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class Form1
{
private void Button1_Click(object sender, EventArgs e)
{
SolidEdgeFramework.Application objApp = null;
Type objType = null;
SolidEdgeFramework.MatTable objMatTable = null;
string strLibrary = "Materials";
SolidEdgePart.PartDocument objDocument = null;
string strMaterial = "";
string strMessage = null;
object varGetPropVal = null;
SolidEdgeFramework.UnitTypeConstants nUnitType = 0;
string strPropName = "";
try
{
// Get SE handle
objApp = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
if (objApp == null)
{
// Get the type from the Solid Edge ProgID
objType = Type.GetTypeFromProgID("SolidEdge.Application");
// Start Solid Edge
objApp = Activator.CreateInstance(objType);
// Make Solid Edge visible
objApp.Visible = true;
}
// Get material table object handle
objMatTable = objApp.GetMaterialTable();
objDocument = objApp.Documents.Add("SolidEdge.Partdocument");
strMaterial = "Steel";
objMatTable.AddCustomProperty(strMaterial, strLibrary, "My Custom Property ", 1, 152.66);
objMatTable.AddCustomProperty(strMaterial, strLibrary, "SE Custom Property ", 13, 42.98);
objMatTable.ApplyMaterialToDoc(objDocument, strMaterial, strLibrary);
objMatTable.GetCustomMaterialPropertyFromDoc(objDocument, 1, strPropName, nUnitType, varGetPropVal);
strMessage = string.Format("Custom Property of STEEL - Name: {0}, Unit Type: {1}, Value: {2}", strPropName, nUnitType, varGetPropVal);
MessageBox.Show(strMessage);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public Form1()
{
SubscribeToEvents();
}
private bool EventsSubscribed = false;
private void SubscribeToEvents()
{
if (EventsSubscribed)
return;
else
EventsSubscribed = true;
Button1.Click += Button1_Click;
}
}