马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
怎么能在孔的上面添加螺纹。很苦恼~
下面的就是不行,错在那了?请指教
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 objHol As SolidEdgePart.Hole
Dim objHolData As SolidEdgePart.HoleData
Dim objThread As SolidEdgePart.Thread
Dim objHolData1 As SolidEdgePart.HoleData
Dim objEdgs As Object
Dim objFaces As Object
Dim objLines As SolidEdgeFrameworkSupport.Lines2d
Dim objRelns As SolidEdgeFrameworkSupport.Relations2d
Dim objApplication As SolidEdgeFramework.Application
Dim objRefPln As SolidEdgePart.RefPlane
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 ("rofile 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 ("rofile not closed")
End If
' Create the HoleData object
Set objHolData = objDoc.HoleDataCollection.Add(HoleType:=igRegularHole, _
HoleDiameter:=0.0085)
'(HoleType:=igCounterboreHole, _
HoleDiameter:=0.005, CounterboreDiameter:=0.007, _
CounterboreDepth:=0.0075)
' Create a Hole object
Set objHol = objModel.Holes.AddFinite(Profile:=objHoleProf, Profileplaneside:= _
igRight, FiniteDepth:=0.05, Data:=objHolData)
objHoleProf.Visible = False
If objHol.Status <> igFeatureOK Then
MsgBox ("AddFinite method with Profileplaneside set to Right failed")
End If
' Get the Application Property of Hole
'Set objApplication = objHol.Application
Set objEdgs = objHol.Edges(EdgeType:=igQueryAll)
Set objFaces = objHol.Faces(FaceType:=igQueryRoundable)
Set objHolData1 = objDoc.HoleDataCollection.Add(HoleType:=igRegularThread, _
HoleDiameter:=0.01, ThreadDepth:=0.01)
'Set objModel = objDoc.Models(1)
'Get the Threads Object for the Model
Set objThread = objModel.Threads.Add(HoleData:=objHol, numberofcylinders:=1, _
cylinderarray:=objFaces, cylinderendarray:=objEdgs)
' 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 objRelns = Nothing
Set objLines = Nothing
Set objApplication = Nothing
Set objRefPln = Nothing
End Sub |