Imports System.Runtime.InteropServices
Imports System.IO
Public Class Form1
Private Sub PMIModelView_Click(sender As Object, e As EventArgs) Handles PMIModelView.Click
Dim objApplication As SolidEdgeFramework.Application = Nothing
Dim objDocument As SolidEdgePart.PartDocument = Nothing
Dim objPMI As SolidEdgeFrameworkSupport.PMI = Nothing
Dim objPMIMVs As SolidEdgeFrameworkSupport.PMIModelViews = Nothing
Dim objPMIMV As SolidEdgeFrameworkSupport.PMIModelView = Nothing
Dim objBalloons As SolidEdgeFrameworkSupport.Balloons = Nothing
Dim objBalloon As SolidEdgeFrameworkSupport.Balloon = Nothing
Dim objDims As SolidEdgeFrameworkSupport.Dimensions = Nothing
Dim objDim As SolidEdgeFrameworkSupport.Dimension = Nothing
Dim SEInstallDir As DirectoryInfo
Dim RenderMode As SolidEdgeFrameworkSupport.PMIRenderModeConstants = SolidEdgeFrameworkSupport.PMIRenderModeConstants.sePMIModelViewRenderModeNone
Try
objApplication = Marshal.GetActiveObject("SolidEdge.Application")
'Get Solid Edge Installation directory
SEInstallDir = GetTrainingFolder()
'Open carrier.asm
objDocument = Documents.Open(SEInstallDir.FullName + "\17_tooth_pinion.par")
'Get the PMI object
objDocument.PMI_ByModelState(objPMI)
'Get the model view collection
objPMIMVs = objPMI.PMIModelViews
''Add model view object
objPMIMV = objPMIMVs.Add("View1", SolidEdgeFrameworkSupport.PMIRenderModeConstants.sePMIModelViewRenderModeShadedWithVisibleEdges)
'Get the model view object
objPMIMV = objPMIMVs.Item(1)
'Set the name of model view
objPMIMV.Name = "Model View"
'Set the render mode
objPMIMV.RenderMode = SolidEdgeFrameworkSupport.PMIRenderModeConstants.sePMIModelViewRenderModeVisibleEdges
objPMIMV.SetShowHidePMISections(False)
'Get the render mode
RenderMode = objPMIMV.RenderMode
objBalloons = objPMI.Balloons
objBalloon = objBalloons.Item(1)
'Add and remove annotations
objPMIMV.AddDimAnnotOrSectionToView(objBalloon)
objPMIMV.RemoveDimAnnotOrSectionFromView(objBalloon)
objDims = objPMI.Dimensions
objDim = objDims.Item(1)
'Add and remove dimensions
objPMIMV.AddDimAnnotOrSectionToView(objDim)
objPMIMV.RemoveDimAnnotOrSectionFromView(objDim)
'Set the view orientation
objPMIMV.SetViewOrientationToCurrentView()
'Show/Hide referenced component in PMI model view object
objPMIMV.SetShowHideComponentsToCurrentView(objDocument.CoordinateSystems.Item(1), True)
objPMIMV.SetShowHideComponentsToCurrentView(objDocument.CoordinateSystems.Item(1), False)
'Apply the view
objPMIMV.Apply()
Catch ex As Exception
MsgBox(ex.Message)
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 PMIModelView_Click(object sender, EventArgs e)
{
SolidEdgeFramework.Application objApplication = null;
SolidEdgePart.PartDocument objDocument = null;
SolidEdgeFrameworkSupport.PMI objPMI = null;
SolidEdgeFrameworkSupport.PMIModelViews objPMIMVs = null;
SolidEdgeFrameworkSupport.PMIModelView objPMIMV = null;
SolidEdgeFrameworkSupport.Balloons objBalloons = null;
SolidEdgeFrameworkSupport.Balloon objBalloon = null;
SolidEdgeFrameworkSupport.Dimensions objDims = null;
SolidEdgeFrameworkSupport.Dimension objDim = null;
DirectoryInfo SEInstallDir = null;
SolidEdgeFrameworkSupport.PMIRenderModeConstants RenderMode = SolidEdgeFrameworkSupport.PMIRenderModeConstants.sePMIModelViewRenderModeNone;
try
{
objApplication = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
//Get Solid Edge Installation directory
SEInstallDir = GetTrainingFolder();
//Open carrier.asm
objDocument = Documents.Open(SEInstallDir.FullName + "\\17_tooth_pinion.par");
//Get the PMI object
objDocument.PMI_ByModelState(objPMI);
//Get the model view collection
objPMIMVs = objPMI.PMIModelViews;
//'Add model view object
objPMIMV = objPMIMVs.Add("View1", SolidEdgeFrameworkSupport.PMIRenderModeConstants.sePMIModelViewRenderModeShadedWithVisibleEdges);
//Get the model view object
objPMIMV = objPMIMVs.Item(1);
//Set the name of model view
objPMIMV.Name = "Model View";
//Set the render mode
objPMIMV.RenderMode = SolidEdgeFrameworkSupport.PMIRenderModeConstants.sePMIModelViewRenderModeVisibleEdges;
objPMIMV.SetShowHidePMISections(false);
//Get the render mode
RenderMode = objPMIMV.RenderMode;
objBalloons = objPMI.Balloons;
objBalloon = objBalloons.Item(1);
//Add and remove annotations
objPMIMV.AddDimAnnotOrSectionToView(objBalloon);
objPMIMV.RemoveDimAnnotOrSectionFromView(objBalloon);
objDims = objPMI.Dimensions;
objDim = objDims.Item(1);
//Add and remove dimensions
objPMIMV.AddDimAnnotOrSectionToView(objDim);
objPMIMV.RemoveDimAnnotOrSectionFromView(objDim);
//Set the view orientation
objPMIMV.SetViewOrientationToCurrentView();
//Show/Hide referenced component in PMI model view object
objPMIMV.SetShowHideComponentsToCurrentView(objDocument.CoordinateSystems.Item(1), true);
objPMIMV.SetShowHideComponentsToCurrentView(objDocument.CoordinateSystems.Item(1), false);
//Apply the view
objPMIMV.Apply();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
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;
PMIModelView.Click += PMIModelView_Click;
}
}