Imports System.IO
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 objAssemblyDoc As SolidEdgeAssembly.AssemblyDocument = Nothing
Dim objDocuments As SolidEdgeFramework.Documents = Nothing
Dim objFolder As DirectoryInfo
Dim objFileInfo As FileInfo
Dim objFace1 As SolidEdgeGeometry.Face
Dim objFace2 As SolidEdgeGeometry.Face
Dim dblPoint1(0) As Double
Dim dblPoint2(0) As Double
Dim dblPoint3(0) As Double
Dim distance As Double
Dim dx As Double
Dim dy As Double
Dim dz As Double
Dim dgoem(2) As Double
Dim featedges As SolidEdgeGeometry.Edges
Dim featedge1 As SolidEdgeGeometry.Edge
Dim featedge2 As SolidEdgeGeometry.Edge
Dim featedge3 As SolidEdgeGeometry.Edge
Dim strRetStatusMsg As String
strRetStatusMsg = ""
Dim angle1 As Double
Dim angle2 As Double
Dim angle3 As Double
Dim angle4 As Double
Dim SurfArea As Double
Dim Volume As Double
Dim Length As Double
Dim coSyss As SolidEdgePart.CoordinateSystem
Dim objRef1 As Object
Dim objRef2 As Object
Dim objRef3 As Object
Dim objRef4 As Object
dgoem(0) = 0
dgoem(1) = 0
dgoem(2) = 0
Try
objApp = Marshal.GetActiveObject("SolidEdge.Application")
objFolder = GetTrainingFolder()
objFileInfo = New FileInfo(Path.Combine(objFolder.FullName, "carrier.asm"))
objDocuments = objApp.Documents
objAssemblyDoc = objDocuments.Open(objFileInfo.FullName)
objFace1 = objAssemblyDoc.Occurrences.Item(1).OccurrenceDocument.Models.Item(1).ExtrudedProtrusions.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll).Item(3)
objFace2 = objAssemblyDoc.Occurrences.Item(1).OccurrenceDocument.Models.Item(1).ExtrudedProtrusions.Item(1).Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll).Item(4)
objRef1 = objAssemblyDoc.CreateReference(objAssemblyDoc.Occurrences(0), objFace1)
objRef2 = objAssemblyDoc.CreateReference(objAssemblyDoc.Occurrences(0), objFace2)
Call objAssemblyDoc.MeasureDistance(objRef1, objRef2, SolidEdgePart.MeasureDistanceTypeConstants.MeasureDistanceTypeConstants_MaximumDistance, distance, dx, dy, dz, dblPoint1, dblPoint2)
MsgBox("Distance between the elements is " + distance.ToString)
featedges = objAssemblyDoc.Occurrences.Item(1).OccurrenceDocument.Models.Item(1).ExtrudedProtrusions.Item(1).Edges(SolidEdgeConstants.FeatureTopologyQueryTypeConstants.igQueryAll)
featedge1 = featedges.Item(1)
featedge2 = featedges.Item(2)
featedge3 = featedges.Item(3)
objRef3 = objAssemblyDoc.CreateReference(objAssemblyDoc.Occurrences(0), featedge1)
objRef4 = objAssemblyDoc.CreateReference(objAssemblyDoc.Occurrences(0), featedge2)
Call objAssemblyDoc.MeasureAngleEx(objRef3, objRef4, Nothing, angle1, angle2, angle3, angle4)
MsgBox("Angle between the edges is " + Math.Round(RadiansToDegrees(angle1)).ToString + " degrees")
Call objAssemblyDoc.InquireElement(objRef3, dgoem, Nothing, dblPoint1, SurfArea, Volume, Length)
coSyss = objAssemblyDoc.CoordinateSystems.Item(1)
Call objAssemblyDoc.InquireElement(objRef3, dblPoint2, coSyss, dblPoint3, SurfArea, Volume, Length)
MsgBox("Length of Inquired Element is " + Length.ToString)
Catch ex As Exception
MessageBox.Show(ex.ToString)
Clipboard.SetText(ex.ToString)
End Try
End Sub
Private Function RadiansToDegrees(ByVal radians As Double) As Double
Return radians * (180 / Math.PI)
End Function
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