|
加入QQ群
参与讨论和学习
或扫描二维码加入
我先把钻孔成功的范例放上来好了
SolidWorks 钻孔测试(确认可执行).zip
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim swApp As SldWorks
Dim swModel As ModelDoc2
Dim swFeatureMgr As FeatureManager
Dim swFeature As Feature
Dim swModelDocExt As ModelDocExtension
Dim fileName As String
Dim errors As Long
Dim warnings As Long
Dim status As Boolean
Dim SlotType As Long
Dim HoleType As Long
Dim StandardIndex As Long
Dim FastenerTypeIndex As Long
Dim SSize As String
Dim EndType As Long
Dim ConvFactorLength As Double
Dim ConvFactorAngle As Double
Dim Diameter As Double
Dim Depth As Double
Dim Length As Double
Dim ScrewFit As Double
Dim DrillAngle As Double
Dim NearCsinkDiameter As Double
Dim NearCsinkAngle As Double
Dim FarCsinkDiameter As Double
Dim FarCsinkAngle As Double
Dim Offset As Double
Dim ThreadClass As String
Dim CounterBoreDiameter As Double
Dim CounterBoreDepth As Double
Dim HeadClearance As Double
Dim BotCsinkDiameter As Double
Dim BotCsinkAngle As Double
Dim swWizardHoleFeatData As WizardHoleFeatureData2
swApp = New SldWorks
swApp.Visible = True
fileName = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\api\block20.sldprt"
swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
swFeatureMgr = swModel.FeatureManager
swModelDocExt = swModel.Extension
'Use IFeatureManager::HoleWizard5
'to create a slot
'Select the face where to create the slot
status = swModelDocExt.SelectByID2("", "FACE", -0.000609805077203873, 0.0396239999998897, -0.00830387834611201, False, 0, Nothing, 0)
SlotType = swWzdGeneralHoleTypes_e.swWzdHoleSlot
StandardIndex = swWzdHoleStandards_e.swStandardAnsiInch
FastenerTypeIndex = swWzdHoleStandardFastenerTypes_e.swStandardAnsiInchAllDrillSizes
SSize = "#97"
EndType = swEndConditions_e.swEndCondBlind
ConvFactorLength = 25.4 / 1000 'Convert inches to meters
ConvFactorAngle = (22 / 7) / 180 'Convert degrees to radians
Diameter = 0.5 * ConvFactorLength
Depth = 2 * ConvFactorLength
Length = 3 * ConvFactorLength
'Value1 to Value7 arguments; SolidWorks
'ignores parameters set to -1
ScrewFit = -1 'Value1
DrillAngle = 100 * ConvFactorAngle'Value2
NearCsinkDiameter = -1 'Value3
NearCsinkAngle = -1 'Value4
FarCsinkDiameter = -1 'Value5
FarCsinkAngle = -1 'Value6
Offset = -1 'Value7
ThreadClass = ""
swFeature = swFeatureMgr.HoleWizard5(SlotType, StandardIndex, FastenerTypeIndex,
SSize, EndType, Diameter, Depth, Length, ScrewFit, DrillAngle,
NearCsinkDiameter, NearCsinkAngle, FarCsinkDiameter, FarCsinkAngle, Offset, -1, -1, -1,
-1, -1, ThreadClass, False, False, False, False, False, False)
'_______________________________________________________________________________
status = swModelDocExt.SelectByID2("", "FACE", -0.00134479865672033, 0.0396240000000034, -0.0399210049380327, False, 0, Nothing, 0)
SlotType = swWzdGeneralHoleTypes_e.swWzdHoleSlot
StandardIndex = swWzdHoleStandards_e.swStandardAnsiInch
FastenerTypeIndex = swWzdHoleStandardFastenerTypes_e.swStandardAnsiInchAllDrillSizes
SSize = "#1"
EndType = swEndConditions_e.swEndCondBlind
ConvFactorLength = 25.4 / 1000 'Convert inches to meters
ConvFactorAngle = (22 / 7) / 180 'Convert degrees to radians
Diameter = 0.5 * ConvFactorLength
Depth = 2 * ConvFactorLength
Length = 3 * ConvFactorLength
'Value1 to Value7 arguments; SolidWorks
'ignores parameters set to -1
ScrewFit = -1 'Value1
DrillAngle = 100 * ConvFactorAngle'Value2
NearCsinkDiameter = -1 'Value3
NearCsinkAngle = -1 'Value4
FarCsinkDiameter = -1 'Value5
FarCsinkAngle = -1 'Value6
Offset = -1 'Value7
ThreadClass = ""
swFeature = swFeatureMgr.HoleWizard5(SlotType, StandardIndex, FastenerTypeIndex,
SSize, EndType, Diameter, Depth, Length, ScrewFit, DrillAngle,
NearCsinkDiameter, NearCsinkAngle, FarCsinkDiameter, FarCsinkAngle, Offset, -1, -1, -1,
-1, -1, ThreadClass, False, False, False, False, False, False)
'_______________________________________________________________________________
'Print length of slot to Immediate window
swWizardHoleFeatData = swFeature.GetDefinition
Debug.Print("Length of slot: " & swWizardHoleFeatData.Length & " inches")
'Use IFeatureManager::HoleWizard5
'to create a counterbore hole
'Select the face where to create the hole
status = swModelDocExt.SelectByID2("", "FACE", -0.0060197480091233, 0.0396239999998329, 0.0270812377555103, False, 0, Nothing, 0)
HoleType = swWzdGeneralHoleTypes_e.swWzdCounterBore
StandardIndex = swWzdHoleStandards_e.swStandardAnsiInch
FastenerTypeIndex = swWzdHoleStandardFastenerTypes_e.swStandardAnsiInchBinding
SSize = "#12"
EndType = swEndConditions_e.swEndCondThroughAll
ConvFactorLength = 25.4 / 1000 'Convert inches to meters
ConvFactorAngle = (22 / 7) / 180 'Convert degrees to radians
Diameter = 0.5 * ConvFactorLength
Depth = -1
Length = -1
'Value1 to Value12 arguments; SolidWorks
'ignores parameters set to -1
CounterBoreDiameter = 0.6 * ConvFactorLength 'Value1
CounterBoreDepth = 0.2 * ConvFactorLength 'Value2
HeadClearance = -1 'Value3
ScrewFit = -1 'Value4
DrillAngle = -1 'Value5
NearCsinkDiameter = -1 'Value6
NearCsinkAngle = -1 'Value7
BotCsinkDiameter = -1 'Value8
BotCsinkAngle = -1 'Value9
FarCsinkDiameter = -1 'Value10
FarCsinkAngle = -1 'Value11
Offset = -1 'Value12
ThreadClass = ""
swFeature = swFeatureMgr.HoleWizard5(HoleType, StandardIndex, FastenerTypeIndex, SSize, EndType,
Diameter, Depth, Length, CounterBoreDiameter, CounterBoreDepth, HeadClearance, ScrewFit, DrillAngle,
NearCsinkDiameter, NearCsinkAngle, BotCsinkDiameter, BotCsinkAngle, FarCsinkDiameter, FarCsinkAngle,
Offset, ThreadClass, False, False, False, False, False, False)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim swApp As SldWorks
Dim Part As ModelDoc2
Dim swFeatureMgr As FeatureManager
Dim swFeature As Feature
Dim swModelDocExt As ModelDocExtension
Dim swWizardHoleFeatData As WizardHoleFeatureData2
swApp = New SldWorks
swApp.Visible = True
'fileName = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\api\block20.sldprt"
'swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
Part = swApp.NewPart
swFeatureMgr = Part.FeatureManager
swModelDocExt = Part.Extension
'-----------------------------
Part.Extension.SelectByID2("前基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch(True)
Part.ClearSelection2(True)
Part.SketchManager.CreateCenterRectangle(-0, 0, 0, 0.1, 0.1, 0)
Part.SetPickMode
Part.ClearSelection2(True)
Part.SketchManager.InsertSketch(True)
Part.ShowNamedView2("*不等角视图", 8)
Part.ClearSelection2(True)
Part.Extension.SelectByID2("草图1", "SKETCH", 0, 0, 0, False, 4, Nothing, 0)
Part.FeatureManager.FeatureExtrusion2(True, False, True, 0, 0, 0.01, 0.01, False, False, False, False, 0.0174532925199433, 0.0174532925199433, False, False, False, False, True, True, True, 0, 0, False)
Part.SelectionManager.EnableContourSelection = False
Part.ClearSelection2(True)
'-----------------------------
'ByVal GenericHoleType As System.Integer 钻孔类型列举
'柱孔 swWzdGeneralHoleTypes_e.swWzdCounterBore
'锥孔 swWzdGeneralHoleTypes_e.swWzdCounterSink
'钻孔 swWzdGeneralHoleTypes_e.swWzdHole
'直螺丝孔 swWzdGeneralHoleTypes_e.swWzdTap
'斜螺丝孔 swWzdGeneralHoleTypes_e.swWzdPipeTap
'旧制孔 swWzdGeneralHoleTypes_e.swWzdLegacy
'柱孔狭槽 swWzdGeneralHoleTypes_e.swWzdCounterBoreSlot
'锥孔狭槽 swWzdGeneralHoleTypes_e.swWzdCounterSinkSlot
'狭槽 swWzdGeneralHoleTypes_e.swWzdHoleSlot
'ByVal StandardIndex As System.Integer 尺寸单位定义
'ISO(公制) swWzdHoleStandards_e.swStandardISO
'ByVal FastenerTypeIndex As System.Integer 孔类型与单位配对(需与钻孔类型配对)
'公制沉头孔swWzdHoleStandardFastenerTypes_e.swStandardISOSocketHeadCap
'ByVal SSize As System.String 特徵树显示的孔类型
'Ex:SSize = "M4" -> M4 六角承窝头盖螺钉的柱孔
'ByVal EndType As System.Short 特徵终止型态定义
'指定深度 swEndConditions_e.swEndCondBlind
'ByVal Diameter As System.Double 钻孔直径
'ByVal Depth As System.Double 钻孔深度
'ByVal Length As System.Double 长度(仅对狭槽类型孔有效)
'ByVal Value1 As System.Double Value值依据孔类型有所不同(-1代表忽略该项目)
'ByVal Value2 As System.Double
'ByVal Value3 As System.Double
'ByVal Value4 As System.Double
'ByVal Value5 As System.Double
'ByVal Value6 As System.Double
'ByVal Value7 As System.Double
'ByVal Value8 As System.Double
'ByVal Value9 As System.Double
'ByVal Value10 As System.Double
'ByVal Value11 As System.Double
'ByVal Value12 As System.Double
'ByVal ThreadClass As System.String 线程数(仅适用于 ANSI Inch标准)
'ByVal RevDir As System.Boolean 钻孔方向
'True-> 参考面法向量
'False -> 反向法向量
'ByVal FeatureScope As System.Boolean 多实体成型
'True-> 特徵建立于"所有"实体
'False -> 特徵建立于"所选"实体
'尚未使用下列功能
'ByVal AutoSelect As System.Boolean
'ByVal AssemblyFeatureScope As System.Boolean
'ByVal AutoSelectComponents As System.Boolean
'ByVal PropagateFeatureToParts As System.Booleam
'钻孔参数定义
Dim Counterbores As New Hole(swWzdGeneralHoleTypes_e.swWzdCounterBore, swWzdHoleStandards_e.swStandardISO,
swWzdHoleStandardFastenerTypes_e.swStandardISOSocketHeadCap, "M4",
swEndConditions_e.swEndCondThroughAll, 0.0045, -1, -1, 0.008, 0.0045,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "", False, False, False, False, False, False)
Part.Extension.SelectByID2("", "FACE", 0, 0, 0, False, 0, Nothing, 0)
Part.FeatureManager.HoleWizard5(Counterbores.GenericHoleType, Counterbores.StandardIndex, Counterbores.FastenerTypeIndex,
Counterbores.SSize, Counterbores.EndType, Counterbores.Diameter, Counterbores.Depth, Counterbores.Length,
Counterbores.Value1, Counterbores.Value2, Counterbores.Value3, Counterbores.Value4, Counterbores.Value5,
Counterbores.Value6, Counterbores.Value7, Counterbores.Value8, Counterbores.Value9, Counterbores.Value10,
Counterbores.Value11, Counterbores.Value12, Counterbores.ThreadClass, Counterbores.RevDir, Counterbores.FeatureScope,
Counterbores.AutoSelect, Counterbores.AssemblyFeatureScope, Counterbores.AutoSelectComponents, Counterbores.PropagateFeatureToParts)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim swApp As SldWorks
Dim Part As ModelDoc2
Dim swFeatureMgr As FeatureManager
Dim swModelDocExt As ModelDocExtension
swApp = New SldWorks
swApp.Visible = True
Part = swApp.NewPart
swFeatureMgr = Part.FeatureManager
swModelDocExt = Part.Extension
'-----------------------------
Part.Extension.SelectByID2("前基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch(True)
Part.ClearSelection2(True)
Part.SketchManager.CreateCenterRectangle(-0, 0, 0, 0.1, 0.1, 0)
Part.SetPickMode()
Part.ClearSelection2(True)
Part.SketchManager.InsertSketch(True)
Part.ShowNamedView2("*不等角视图", 8)
Part.ClearSelection2(True)
Part.Extension.SelectByID2("草图1", "SKETCH", 0, 0, 0, False, 4, Nothing, 0)
Part.FeatureManager.FeatureExtrusion2(True, False, True, 0, 0, 0.01, 0.01, False, False, False, False, 0.0174532925199433, 0.0174532925199433, False, False, False, False, True, True, True, 0, 0, False)
Part.SelectionManager.EnableContourSelection = False
Part.ClearSelection2(True)
'-----------------------------
Part.Extension.SelectByID2("", "FACE", 0, 0, 0, False, 0, Nothing, 0)
Dim PinHole As New Hole(swWzdGeneralHoleTypes_e.swWzdHole, swWzdHoleStandards_e.swStandardISO,
swWzdHoleStandardFastenerTypes_e.swStandardISODowelHole, "?6.0",
swEndConditions_e.swEndCondThroughAll, 0.006, 0.01, 1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, "", False, True, True, True, True, False)
Part.FeatureManager.HoleWizard5(PinHole.GenericHoleType, PinHole.StandardIndex, PinHole.FastenerTypeIndex,
PinHole.SSize, PinHole.EndType, PinHole.Diameter, PinHole.Depth, PinHole.Length,
PinHole.Value1, PinHole.Value2, PinHole.Value3, PinHole.Value4, PinHole.Value5,
PinHole.Value6, PinHole.Value7, PinHole.Value8, PinHole.Value9, PinHole.Value10,
PinHole.Value11, PinHole.Value12, PinHole.ThreadClass, PinHole.RevDir, PinHole.FeatureScope,
PinHole.AutoSelect, PinHole.AssemblyFeatureScope, PinHole.AutoSelectComponents, PinHole.PropagateFeatureToParts)
End Sub
End Class
复制代码
Public Class Hole
Public Sub New(ByVal GenericHoleType As Integer, ByVal StandardIndex As Integer, ByVal FastenerTypeIndex As Integer, ByVal SSize As String,
ByVal EndType As Integer, ByVal Diameter As Double, ByVal Depth As Double, ByVal Length As Double,
ByVal Value1 As Double, ByVal Value2 As Double, ByVal Value3 As Double, ByVal Value4 As Double,
ByVal Value5 As Double, ByVal Value6 As Double, ByVal Value7 As Double, ByVal Value8 As Double,
ByVal Value9 As Double, ByVal Value10 As Double, ByVal Value11 As Double, ByVal Value12 As Double,
ByVal ThreadClass As String, ByVal RevDir As Boolean, ByVal FeatureScope As Boolean, ByVal AutoSelect As Boolean,
ByVal AssemblyFeatureScope As Boolean, ByVal AutoSelectComponents As Boolean, ByVal PropagateFeatureToParts As Boolean)
Me.GenericHoleType = GenericHoleType
Me.StandardIndex = StandardIndex
Me.FastenerTypeIndex = FastenerTypeIndex
Me.SSize = SSize
Me.EndType = EndType
Me.Diameter = Diameter
Me.Depth = Depth
Me.Length = Length
Me.Value1 = Value1
Me.Value2 = Value2
Me.Value3 = Value3
Me.Value4 = Value4
Me.Value5 = Value5
Me.Value6 = Value6
Me.Value7 = Value7
Me.Value8 = Value8
Me.Value9 = Value9
Me.Value10 = Value10
Me.Value11 = Value11
Me.Value12 = Value12
Me.ThreadClass = ThreadClass
Me.RevDir = RevDir
Me.FeatureScope = FeatureScope
Me.AutoSelect = AutoSelect
Me.AssemblyFeatureScope = AssemblyFeatureScope
Me.AutoSelectComponents = AutoSelectComponents
Me.PropagateFeatureToParts = PropagateFeatureToParts
End Sub
Public GenericHoleType As Integer
'柱孔 swWzdGeneralHoleTypes_e.swWzdCounterBore
'锥孔 swWzdGeneralHoleTypes_e.swWzdCounterSink
'钻孔 swWzdGeneralHoleTypes_e.swWzdHole
'直螺丝孔 swWzdGeneralHoleTypes_e.swWzdTap
'斜螺丝孔 swWzdGeneralHoleTypes_e.swWzdPipeTap
'旧制孔 swWzdGeneralHoleTypes_e.swWzdLegacy
'柱孔狭槽 swWzdGeneralHoleTypes_e.swWzdCounterBoreSlot
'锥孔狭槽 swWzdGeneralHoleTypes_e.swWzdCounterSinkSlot
'狭槽 swWzdGeneralHoleTypes_e.swWzdHoleSlot
Public StandardIndex As Integer
'ISO(公制) swWzdHoleStandards_e.swStandardISO
Public FastenerTypeIndex As Integer
'公制沉头孔swWzdHoleStandardFastenerTypes_e.swStandardISOSocketHeadCap
'公制定位孔swWzdHoleStandardFastenerTypes_e.swStandardISODowelHole
Public SSize As String
'特徵描述
Public EndType As Integer
'特徵终止型态
Public Diameter As Double
'钻孔直径
Public Depth As Double
'钻孔深度
Public Length As Double
'狭槽长度
Public Value1 As Double
Public Value2 As Double
Public Value3 As Double
Public Value4 As Double
Public Value5 As Double
Public Value6 As Double
Public Value7 As Double
Public Value8 As Double
Public Value9 As Double
Public Value10 As Double
Public Value11 As Double
Public Value12 As Double
Public ThreadClass As String
Public RevDir As Boolean
Public FeatureScope As Boolean
Public AutoSelect As Boolean
Public AssemblyFeatureScope As Boolean
Public AutoSelectComponents As Boolean
Public PropagateFeatureToParts As Boolean
End Class
SolidWorks 鑽孔測試(確認可執行).zip
(652.54 KB, 下载次数: 208)
|
|