Private Sub Form_Load()
Dim objApp As SolidEdgeFramework.Application
Dim objDoc As SolidEdgePart.PartDocument
Dim objBaseProfile As SolidEdgePart.Profile
Dim objBaseProfArray(1 To 2) As SolidEdgePart.Profile
Dim objBase As SolidEdgePart.Model
Dim objRegHoleData As SolidEdgePart.HoleData
Dim objCBoreHoleData As SolidEdgePart.HoleData
Dim objCSinkHoleData As SolidEdgePart.HoleData
Dim objRP As SolidEdgePart.RefPlane
Dim objRegHoleProfile As SolidEdgePart.Profile
Dim objCBoreHoleProfile As SolidEdgePart.Profile
Dim objCSinkHoleProfile As SolidEdgePart.Profile
Dim objRegHole As SolidEdgePart.Hole
Dim objCBoreHole As SolidEdgePart.Hole
Dim objCSinkHole As SolidEdgePart.Hole
Dim lngCount As Long
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
' *** creating the an extruded protrusion base feature
' creating a circular profile for the base feature and validating it
Set objBaseProfile = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objDoc.RefPlanes(1))
Call objBaseProfile.Circles2d.AddByCenterRadius(x:=0, y:=0, Radius:=0.1)
lngStatus = objBaseProfile.End(ValidationCriteria:=igProfileClosed)
If (lngStatus <> 0) Then
MsgBox "Profile for the base feature is not closed"
End If
' creating the extruded protrusion and validating it
Set objBaseProfArray(1) = objBaseProfile
Set objBase = objDoc.Models.AddFiniteExtrudedProtrusion(NumberOfProfiles:=1, _
ProfileArray:=objBaseProfArray, ProfilePlaneSide:=igSymmetric, ExtrusionDistance:=0.05)
objBaseProfile.Visible = False
If (objBase.ExtrudedProtrusions(1).Status <> igFeatureOK) Then
MsgBox "AddFiniteExtrudedProtrusion method of models object fails"
End If
' *** creating a Regular Hole using the Holedatacollection object
' creating the hole data for a regular hole
Set objRegHoleData = objDoc.HoleDataCollection.Add(HoleType:=igRegularHole, _
HoleDiameter:=0.01, BottomAngle:=90)
' creating a profile for the regular hole and validating it
Set objRP = objDoc.RefPlanes.AddParallelByDistance(ParentPlane:=objDoc.RefPlanes(1), _
Distance:=0.025, NormalSide:=igRight)
Set objRegHoleProfile = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objRP)
Call objRegHoleProfile.Holes2d.Add(xcenter:=0, ycenter:=0)
lngStatus = objRegHoleProfile.End(ValidationCriteria:=igProfileClosed)
If (lngStatus <> 0) Then
MsgBox "Profile for the regular hole is not closed"
End If
' creating the regular hole on the base feature and validating it
Set objRegHole = objBase.Holes.AddFinite(Profile:=objRegHoleProfile, _
ProfilePlaneSide:=igLeft, FiniteDepth:=0.02, Data:=objRegHoleData)
If (objRegHole.Status <> igFeatureOK) Then
MsgBox "AddFinite method of the Holes object fails"
End If
objRegHoleProfile.Visible = False
' *** creating a CounterBore Hole using the HoleDataCollection object
' creating the hole data for a counter bore hole
Set objCBoreHoleData = objDoc.HoleDataCollection.Add(HoleType:=igCounterboreHole, _
HoleDiameter:=0.01, CounterboreDiameter:=0.02, CounterboreDepth:=0.01, BottomAngle:=0)
' creating a profile for the counter bore hole and validating it
Set objCBoreHoleProfile = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objRP)
Call objCBoreHoleProfile.Holes2d.Add(xcenter:=0.05, ycenter:=0)
lngStatus = objCBoreHoleProfile.End(ValidationCriteria:=igProfileClosed)
If (lngStatus <> 0) Then
MsgBox "Profile for the regular hole is not closed"
End If
' creating the counter bore hole on the base feature and validating it
Set objCBoreHole = objBase.Holes.AddFinite(Profile:=objCBoreHoleProfile, _
ProfilePlaneSide:=igLeft, FiniteDepth:=0.03, Data:=objCBoreHoleData)
If (objCBoreHole.Status <> igFeatureOK) Then
MsgBox "AddFinite method of the Holes object fails"
End If
objCBoreHoleProfile.Visible = False
' *** creating a Counter-Sunk Hole using the Holedatacollection object
' creating the hole data for a counter sunk hole
Set objCSinkHoleData = objDoc.HoleDataCollection.Add(HoleType:=igCountersinkHole, _
HoleDiameter:=0.01, CountersinkDiameter:=0.02, CountersinkAngle:=100, BottomAngle:=0)
' creating a profile for the counter sunk hole and validating it
Set objCSinkHoleProfile = objDoc.ProfileSets.Add.Profiles.Add(pRefPlaneDisp:=objRP)
Call objCSinkHoleProfile.Holes2d.Add(xcenter:=0, ycenter:=0.05)
lngStatus = objCSinkHoleProfile.End(ValidationCriteria:=igProfileClosed)
If (lngStatus <> 0) Then
MsgBox "Profile for the counter sunk hole is not closed"
End If
' creating the counter sunk hole on the base feature and validating it
Set objCSinkHole = objBase.Holes.AddThroughAll(Profile:=objCSinkHoleProfile, _
ProfilePlaneSide:=igLeft, Data:=objCSinkHoleData)
If (objCSinkHole.Status <> igFeatureOK) Then
MsgBox "AddFinite method of the Holes object fails"
End If
objCSinkHoleProfile.Visible = False
' getting the number of HoleDatas in the HoleDataCollection object
lngCount = objDoc.HoleDataCollection.Count
' USER DISPLAY
' Release objects
Set objApp = Nothing
Set objDoc = Nothing
Set objBaseProfile = Nothing
Set objBaseProfArray(1) = Nothing
Set objBase = Nothing
Set objRegHoleData = Nothing
Set objCBoreHoleData = Nothing
Set objCSinkHoleData = Nothing
Set objRP = Nothing
Set objRegHoleProfile = Nothing
Set objCBoreHoleProfile = Nothing
Set objCSinkHoleProfile = Nothing
Set objRegHole = Nothing
Set objCBoreHole = Nothing
Set objCSinkHole = Nothing
End Sub