Imports System.Runtime.InteropServices
Public Class Add
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim objApplication As SolidEdgeFramework.Application = Nothing
Dim objpartDoc As SolidEdgePart.PartDocument = Nothing
Dim objRedefineFaces As SolidEdgePart.RedefineFaces
Dim objRedefineFace As SolidEdgePart.RedefineFace
Dim objModels As SolidEdgePart.Models
Dim objModel As SolidEdgePart.Model
Dim objBody As SolidEdgeGeometry.Body
Dim objFaces As SolidEdgeGeometry.Faces
Dim objFace As SolidEdgeGeometry.Face
Dim objEdge As SolidEdgeGeometry.Edge
Dim ii As Integer = 0
Dim objType As Type = Nothing
Dim objInputFaces(0) As Object
Dim objInputEdges(0) As Object
Dim objTypes(0) As SolidEdgeConstants.FeaturePropertyConstants
Dim numBoundaryEdges As Integer
Dim objBdryEdges(1) As Object
Dim objBdryEdgeTypes(1) As SolidEdgeConstants.FeaturePropertyConstants
Dim objRefPlanes As SolidEdgePart.RefPlanes
Dim objRefPlane As SolidEdgePart.RefPlane
Dim minParams(1) As Double
Dim maxParams(1) As Double
Dim isUCurve(0) As Boolean
Dim inParams(0) As Double
Try
' Create/get the application with specific settings
objApplication = Marshal.GetActiveObject("SolidEdge.Application")
If objApplication Is Nothing Then
' Get the type from the Solid Edge ProgID
objType = Type.GetTypeFromProgID("SolidEdge.Application")
' Start Solid Edge
objApplication = Activator.CreateInstance(objType)
' Make Solid Edge visible
objApplication.Visible = True
End If
' open the document mentioned in the doc files.
objpartDoc = objApplication.Documents.Open("C:\TestFiles\RedefineFace\Cylinder.par")
' For solids
objModels = objpartDoc.Models
objModel = objModels.Item(1)
objRedefineFaces = objModel.RedefineFaces
objBody = objModel.Body
objFaces = objBody.Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryPlane)
objFace = objFaces.Item(1)
Dim FaceId As Integer = objFace.ID
objInputFaces(0) = objFace
objEdge = objFace.Edges(1)
objInputEdges(0) = objEdge
objTypes(0) = SolidEdgePart.FeaturePropertyConstants.igNatural
'*************** Create the redefine feature first **********************
objRedefineFace = objRedefineFaces.Add(1,
objInputFaces,
1,
objInputEdges,
objTypes,
SolidEdgePart.SurfaceByBoundaryPatchTopology.igSurfaceByBoundarySingle, True)
'******************Edit the feature option to full merge *********************
objRedefineFace.FaceMergeOption = SolidEdgePart.SurfaceByBoundaryPatchTopology.igSurfaceByBoundarySingle
'************ Edit the feature so that instead of replacing faces new surface is created. ***************
objRedefineFace.ReplaceFacesOnSolidBody = False
'********** Get and Set boundary edges tangency.************************
'We must roll to previous feature before we get/set tangency types for edges. This is because the tangency is set on edges which are present before creating 'redefine feature.
objModel.RollToFeature(objModel.Features.Item(1), True)
objRedefineFace.GetEdgeTangencyTypes(numBoundaryEdges,
objBdryEdges,
objBdryEdgeTypes)
For ii = 0 To numBoundaryEdges - 1
objBdryEdgeTypes(ii) = SolidEdgePart.FeaturePropertyConstants.igTangent
Next ii
'Need not send back all the edges to SetEdgeTangencyTypes. You can only send the
'edges for which tangency is to be changed.
objRedefineFace.SetEdgeTangencyTypes(numBoundaryEdges,
objBdryEdges,
objBdryEdgeTypes)
'Roll to current feature to see the changes.
objRedefineFace.RollToFeature()
'Set boundary edges tangency back to normal so that insert sketch etc. functions can be demonstrated.
objpartDoc.Undo(3)
'**************************** Insert Sketch ************************************
objRefPlanes = objpartDoc.RefPlanes
objRefPlane = objRefPlanes.Item(1)
objRedefineFace.InsertSketch(objRefPlane, True)
'******************************* Insert UV Curve *******************************
'We must roll to previous feature before we insert UV curve. This is because the
'UV curve is created on input faces to redefine feature.
objModel.RollToFeature(objModel.Features.Item(1), True)
objBody = objModel.Body
objFace = objBody.GetFaceByFaceID(FaceId)
objInputFaces(0) = objFace
objFace.GetParamRange(minParams, maxParams)
isUCurve(0) = False
inParams(0) = (minParams(0) + maxParams(0)) / 2
objRedefineFace.InsertUVCurve(1, objInputFaces, isUCurve, inParams, False)
objRedefineFace.RollToFeature()
objRedefineFace.ReplaceFacesOnSolidBody = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class