Private Sub Form_Load()
Dim objApp As SolidEdgeFramework.Application
Dim objDoc As SolidEdgePart.PartDocument
Dim objModel As SolidEdgePart.Model
Dim objProfArr(1 To 2) As SolidEdgePart.Profile
Dim objHoleProf As SolidEdgePart.Profile
Dim objProf1 As SolidEdgePart.Profile
Dim objProf2 As SolidEdgePart.Profile
Dim objHol As SolidEdgePart.Hole
Dim objHolData As SolidEdgePart.HoleData
Dim objRefPln As SolidEdgePart.RefPlane
Dim objLines As SolidEdgeFrameworkSupport.Lines2d
Dim objExtProt1 As SolidEdgePart.ExtrudedProtrusion
Dim objExtProt2 As SolidEdgePart.ExtrudedProtrusion
Dim objRelns As SolidEdgeFrameworkSupport.Relations2d
Dim lngStatus As Long
' Report errors
Const PI = 3.14159265358979
' Create/get the application with specific settings
On Error Resume Next
Set objApp = GetObject(, "SolidEdge.Application")
If Err Then
Err.Clear
Set objApp = CreateObject("SolidEdge.Application")
Set objDoc = objApp.Documents.Add("SolidEdge.PartDocument")
objApp.Visible = True
Else
Set objDoc = objApp.ActiveDocument
End If
'Draw the Base Profile
Set objProfArr(1) = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:= _
objDoc.RefPlanes(3))
Set objLines = objProfArr(1).Lines2d
Call objLines.AddBy2Points(x1:=0, y1:=0, x2:=0.08, y2:=0)
Call objLines.AddBy2Points(x1:=0.08, y1:=0, x2:=0.08, y2:=0.06)
Call objLines.AddBy2Points(x1:=0.08, y1:=0.06, x2:=0.064, y2:=0.06)
Call objLines.AddBy2Points(x1:=0.064, y1:=0.06, x2:=0.064, y2:=0.02)
Call objLines.AddBy2Points(x1:=0.064, y1:=0.02, x2:=0.048, y2:=0.02)
Call objLines.AddBy2Points(x1:=0.048, y1:=0.02, x2:=0.048, y2:=0.06)
Call objLines.AddBy2Points(x1:=0.048, y1:=0.06, x2:=0.032, y2:=0.06)
Call objLines.AddBy2Points(x1:=0.032, y1:=0.06, x2:=0.032, y2:=0.02)
Call objLines.AddBy2Points(x1:=0.032, y1:=0.02, x2:=0.016, y2:=0.02)
Call objLines.AddBy2Points(x1:=0.016, y1:=0.02, x2:=0.016, y2:=0.06)
Call objLines.AddBy2Points(x1:=0.016, y1:=0.06, x2:=0, y2:=0.06)
Call objLines.AddBy2Points(x1:=0, y1:=0.06, x2:=0, y2:=0)
' Define Relations among the Line objects to make the Profile closed
Set objRelns = objProfArr(1).Relations2d
Call objRelns.AddKeypoint(Object1:=objLines(1), Index1:=igLineEnd, Object2:=objLines(2), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(2), Index1:=igLineEnd, Object2:=objLines(3), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(3), Index1:=igLineEnd, Object2:=objLines(4), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(4), Index1:=igLineEnd, Object2:=objLines(5), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(5), Index1:=igLineEnd, Object2:=objLines(6), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(6), Index1:=igLineEnd, Object2:=objLines(7), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(7), Index1:=igLineEnd, Object2:=objLines(8), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(8), Index1:=igLineEnd, Object2:=objLines(9), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(9), Index1:=igLineEnd, Object2:=objLines(10), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(10), Index1:=igLineEnd, Object2:=objLines(11), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(11), Index1:=igLineEnd, Object2:=objLines(12), Index2:=igLineStart)
Call objRelns.AddKeypoint(Object1:=objLines(12), Index1:=igLineEnd, Object2:=objLines(1), Index2:=igLineStart)
' Check for the Profile Validity
lngStatus = objProfArr(1).End(ValidationCriteria:=igProfileClosed)
If lngStatus <> 0 Then
MsgBox ("Profile not closed")
End If
'Create the Base Extruded Protrusion Feature
Set objModel = objDoc.Models.AddFiniteExtrudedProtrusion(NumberOfProfiles:=1, _
profileArray:=objProfArr, Profileplaneside:= _
igRight, ExtrusionDistance:=0.05)
objProfArr(1).Visible = False
' Check the status of Base Feature
If objModel.ExtrudedProtrusions(1).Status <> igFeatureOK Then
MsgBox ("Error in the Creation of Base Protrusion Feature object")
End If
' Create a Holes2d Profile for the Hole object
Set objRefPln = objDoc.RefPlanes.AddParallelByDistance(ParentPlane:=objDoc.RefPlanes(2), _
Distance:=0.01, NormalSide:=igRight)
Set objHoleProf = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objRefPln)
Call objHoleProf.Holes2d.Add(xCenter:=-0.025, yCenter:=0.04)
' Check for the Profile Validity
lngStatus = objHoleProf.End(ValidationCriteria:=igProfileClosed)
If lngStatus <> 0 Then
MsgBox ("Profile not closed")
End If
'Create 2nd ExtrudedProtrusion Feature object
Set objProf1 = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objDoc.RefPlanes(1))
Call objProf1.Circles2d.AddByCenterRadius(x:=0.15, y:=-0.025, Radius:=0.025)
' Check if the Profile is closed
lngStatus = objProf1.End(ValidationCriteria:=igProfileClosed)
If lngStatus <> 0 Then
MsgBox ("Profile not closed")
End If
Set objExtProt1 = objModel.ExtrudedProtrusions.AddFinite(Profile:=objProf1, _
ProfileSide:=igLeft, Profileplaneside:=igRight, Depth:=0.1)
objProf1.Visible = False
If objExtProt1.Status <> igFeatureOK Then
MsgBox ("AddFinite Method of ExtrudedProtrusions object failed")
End If
'Create 3rd ExtrudedProtrusion Feature object
Set objProf2 = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objDoc.RefPlanes(1))
Call objProf2.Circles2d.AddByCenterRadius(x:=0.25, y:=-0.025, Radius:=0.025)
' Check if the Profile is closed
lngStatus = objProf2.End(ValidationCriteria:=igProfileClosed)
If lngStatus <> 0 Then
MsgBox ("Profile not closed")
End If
Set objExtProt2 = objModel.ExtrudedProtrusions.AddFinite(Profile:=objProf2, _
ProfileSide:=igLeft, Profileplaneside:=igRight, Depth:=0.1)
objProf2.Visible = False
If objExtProt2.Status <> igFeatureOK Then
MsgBox ("AddFinite Method of ExtrudedProtrusions object failed")
End If
' Create the HoleData object
Set objHolData = objDoc.HoleDataCollection.Add(HoleType:=igCounterboreHole, _
HoleDiameter:=0.005, CounterboreDiameter:=0.007, _
CounterboreDepth:=0.0075)
' Create a Hole object
Set objHol = objModel.Holes.AddThroughAll(Profile:=objHoleProf, Profileplaneside:= _
igRight, Data:=objHolData)
objHoleProf.Visible = False
If objHol.Status <> igFeatureOK Then
MsgBox ("AddThroughAll method of Holes object failed")
End If
' Reorder the Hole object before ExtrudedProtrusion_3
Call objHol.Reorder(TargetFeature:=objExtProt1, InsertBefore:=False)
' USER DISPLAY
' Release objects
Set objApp = Nothing
Set objDoc = Nothing
Set objHoleProf = Nothing
Set objProfArr(1) = Nothing
Set objModel = Nothing
Set objHol = Nothing
Set objHolData = Nothing
Set objRefPln = Nothing
Set objExtProt1 = Nothing
Set objExtProt2 = Nothing
Set objLines = Nothing
Set objRelns = Nothing
End Sub