Imports System.Runtime.InteropServices
Public Class Form1
Private Sub AddMaterial_Click(sender As Object, e As EventArgs) Handles AddMaterial.Click
Dim objApplication As SolidEdgeFramework.Application = Nothing
Dim objPartDocument As SolidEdgePart.PartDocument = Nothing
Dim matTable As SolidEdgeFramework.MatTable = Nothing
Dim aMaterials As Object = Nothing
Dim sMatName As String = "Test"
Dim sFaceStyle As String = "Pearl"
Dim sFillStyle As String = "Normal"
Dim sVSStyle As String = "RenderingMtrl"
Dim aMatProps(10) As Long
Dim i As Integer
Try
objApplication = Marshal.GetActiveObject("SolidEdge.Application")
objPartDocument = objApplication.ActiveDocument
matTable = objApplication.GetMaterialTable
'Get the list of all the materials in the material library file
matTable.GetMaterialList(i, aMaterials)
'Set the active document
matTable.SetActiveDocument(objPartDocument)
'Add a new material
matTable.AddMaterial(sMatName, 10, aMatProps, sFaceStyle, sFillStyle, sVSStyle)
'Apply a material
matTable.ApplyMaterial(objPartDocument, sMatName)
'Delete a material
matTable.DeleteMaterial(sMatName)
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 AddMaterial_Click(object sender, EventArgs e)
{
SolidEdgeFramework.Application objApplication = null;
SolidEdgePart.PartDocument objPartDocument = null;
SolidEdgeFramework.MatTable matTable = null;
object aMaterials = null;
string sMatName = "Test";
string sFaceStyle = "Pearl";
string sFillStyle = "Normal";
string sVSStyle = "RenderingMtrl";
long[] aMatProps = new long[11];
int i = 0;
try
{
objApplication = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
objPartDocument = objApplication.ActiveDocument;
matTable = objApplication.GetMaterialTable;
//Get the list of all the materials in the material library file
matTable.GetMaterialList(i, aMaterials);
//Set the active document
matTable.SetActiveDocument(objPartDocument);
//Add a new material
matTable.AddMaterial(sMatName, 10, aMatProps, sFaceStyle, sFillStyle, sVSStyle);
//Apply a material
matTable.ApplyMaterial(objPartDocument, sMatName);
//Delete a material
matTable.DeleteMaterial(sMatName);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public Form1()
{
SubscribeToEvents();
}
private bool EventsSubscribed = false;
private void SubscribeToEvents()
{
if (EventsSubscribed)
return;
else
EventsSubscribed = true;
AddMaterial.Click += AddMaterial_Click;
}
}