Imports System.Runtime.InteropServices
Imports System.IO
Public Class Form1
Private Sub SectionView_Click(sender As Object, e As EventArgs) Handles SectionView.Click
Dim objApplication As SolidEdgeFramework.Application = Nothing
Dim objDocument As SolidEdgeAssembly.AssemblyDocument = Nothing
Dim objBalloon As SolidEdgeFrameworkSupport.Balloon = Nothing
Dim objDim As SolidEdgeFrameworkSupport.Dimension = Nothing
Dim objPMI As SolidEdgeFrameworkSupport.PMI = Nothing
Dim objPMIMVs As SolidEdgeFrameworkSupport.PMIModelViews = Nothing
Dim objPMIMV As SolidEdgeFrameworkSupport.PMIModelView = Nothing
Dim objSection As SolidEdgeFramework.SectionView = Nothing
Dim SectionDisplayMode As SolidEdgeFramework.PMISectionDisplayModeConstants = SolidEdgeFramework.PMISectionDisplayModeConstants.sePMISectionDisplayShowCutFacesAndCutBodies
Dim nSectionCount As Integer = 0
Dim strCaption As String
Dim strName As String
Dim strStyle As String
Dim planeColor As Long
Dim edgeColor As Long
Dim dOpacity As Double
Dim dExtent As Double
Dim bCutHardware As Boolean = False
Dim bShowCuttingPlane As Boolean = False
Dim SEInstallDir As DirectoryInfo
Dim layout As SolidEdgeAssembly.Layout = Nothing
Dim profileArray(0 To 1) As SolidEdgePart.Profile
Dim sectionViews As SolidEdgeFramework.SectionViews = Nothing
Dim sectionView As SolidEdgeFramework.SectionView = Nothing
Try
objApplication = Marshal.GetActiveObject("SolidEdge.Application")
'Get Solid Edge Installation directory
SEInstallDir = GetTrainingFolder()
'Open carrier.asm
objDocument = objApplication.Documents.Open(SEInstallDir.FullName + "\carrier.asm")
layout = objDocument.Layouts.Add(objDocument.AsmRefPlanes.Item(3))
profileArray(0) = Layout.Profile
Call profileArray(0).Lines2d.AddBy2Points(0, -1, 0, 1)
sectionViews = objDocument.SectionViews
sectionView = sectionViews.Add(1, profileArray, "test", 0.02, SolidEdgeFramework.SectionViewExtentSide.igLeftExtent, SolidEdgeFramework.SectionViewProfileSide.igRightProfileSide, False)
'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)
objPMIMV.AddDimAnnotOrSectionToView(sectionView)
'Get count of Dimensions/Annotations/Sections in MV
nSectionCount = objPMIMV.SectionCount
'Get the section object
objSection = objPMIMV.SectionItem(1)
'Get the section name and caption
strCaption = objSection.Caption
strName = objSection.Name
'Set the section name and caption
objSection.Caption = "AB"
objSection.Name = "MV Section"
'Set and get the annotation style
strStyle = objSection.Style
objSection.Style = "DIN"
'Get the cutting plane and cutting edges color
planeColor = objSection.CuttingPlaneColor
edgeColor = objSection.CuttingPlaneEdgeColor
'Setting yellow color to cutting plane faces
objSection.CuttingPlaneColor = 65535
'Setting red color to cutting planes edges
objSection.CuttingPlaneEdgeColor = 255
'Get the cutting plane's opacity
dOpacity = objSection.Opacity
'Set the new opacity
objSection.Opacity = 0.0
objSection.Opacity = 1.0
'Get the extent distance of cutting plane
dExtent = objSection.ThroughAllExtent
'Set the extent distance of cutting plane
objSection.ThroughAllExtent = 0.2
'Get the cut hardware
bCutHardware = objSection.CutHardware
'Set the cut hardware
objSection.CutHardware = True
'Get and set the cutting Plane
bShowCuttingPlane = objSection.ShowCuttingPlane
objSection.ShowCuttingPlane = True
'Get and set the section display mode
SectionDisplayMode = objSection.SectionDisplayMode
objSection.SectionDisplayMode = SolidEdgeFramework.PMISectionDisplayModeConstants.sePMISectionDisplayShowOnlyOriginalBodies
'Remove the section view from model view
objSection.RemoveFromModelView(objPMIMV)
'Add the section view to model view
objSection.AddToModelView(objPMIMV)
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 SectionView_Click(object sender, EventArgs e)
{
SolidEdgeFramework.Application objApplication = null;
SolidEdgeAssembly.AssemblyDocument objDocument = null;
SolidEdgeFrameworkSupport.Balloon objBalloon = null;
SolidEdgeFrameworkSupport.Dimension objDim = null;
SolidEdgeFrameworkSupport.PMI objPMI = null;
SolidEdgeFrameworkSupport.PMIModelViews objPMIMVs = null;
SolidEdgeFrameworkSupport.PMIModelView objPMIMV = null;
SolidEdgeFramework.SectionView objSection = null;
SolidEdgeFramework.PMISectionDisplayModeConstants SectionDisplayMode = SolidEdgeFramework.PMISectionDisplayModeConstants.sePMISectionDisplayShowCutFacesAndCutBodies;
int nSectionCount = 0;
string strCaption = null;
string strName = null;
string strStyle = null;
long planeColor = 0;
long edgeColor = 0;
double dOpacity = 0;
double dExtent = 0;
bool bCutHardware = false;
bool bShowCuttingPlane = false;
DirectoryInfo SEInstallDir = null;
SolidEdgeAssembly.Layout layout = null;
SolidEdgePart.Profile[] profileArray = new SolidEdgePart.Profile[2];
SolidEdgeFramework.SectionViews sectionViews = null;
SolidEdgeFramework.SectionView sectionView = null;
try
{
objApplication = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
//Get Solid Edge Installation directory
SEInstallDir = GetTrainingFolder();
//Open carrier.asm
objDocument = objApplication.Documents.Open(SEInstallDir.FullName + "\\carrier.asm");
layout = objDocument.Layouts.Add(objDocument.AsmRefPlanes.Item(3));
profileArray[0] = layout.Profile;
profileArray[0].Lines2d.AddBy2Points(0, -1, 0, 1);
sectionViews = objDocument.SectionViews;
sectionView = sectionViews.Add(1, profileArray, "test", 0.02, SolidEdgeFramework.SectionViewExtentSide.igLeftExtent, SolidEdgeFramework.SectionViewProfileSide.igRightProfileSide, false);
//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);
objPMIMV.AddDimAnnotOrSectionToView(sectionView);
//Get count of Dimensions/Annotations/Sections in MV
nSectionCount = objPMIMV.SectionCount;
//Get the section object
objSection = objPMIMV.SectionItem(1);
//Get the section name and caption
strCaption = objSection.Caption;
strName = objSection.Name;
//Set the section name and caption
objSection.Caption = "AB";
objSection.Name = "MV Section";
//Set and get the annotation style
strStyle = objSection.Style;
objSection.Style = "DIN";
//Get the cutting plane and cutting edges color
planeColor = objSection.CuttingPlaneColor;
edgeColor = objSection.CuttingPlaneEdgeColor;
//Setting yellow color to cutting plane faces
objSection.CuttingPlaneColor = 65535;
//Setting red color to cutting planes edges
objSection.CuttingPlaneEdgeColor = 255;
//Get the cutting plane's opacity
dOpacity = objSection.Opacity;
//Set the new opacity
objSection.Opacity = 0.0;
objSection.Opacity = 1.0;
//Get the extent distance of cutting plane
dExtent = objSection.ThroughAllExtent;
//Set the extent distance of cutting plane
objSection.ThroughAllExtent = 0.2;
//Get the cut hardware
bCutHardware = objSection.CutHardware;
//Set the cut hardware
objSection.CutHardware = true;
//Get and set the cutting Plane
bShowCuttingPlane = objSection.ShowCuttingPlane;
objSection.ShowCuttingPlane = true;
//Get and set the section display mode
SectionDisplayMode = objSection.SectionDisplayMode;
objSection.SectionDisplayMode = SolidEdgeFramework.PMISectionDisplayModeConstants.sePMISectionDisplayShowOnlyOriginalBodies;
//Remove the section view from model view
objSection.RemoveFromModelView(objPMIMV);
//Add the section view to model view
objSection.AddToModelView(objPMIMV);
}
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;
SectionView.Click += SectionView_Click;
}
}