使用SOLIDWORKS API获取钣金弯曲的草图线
使用SOLIDWORKS API,宏可以查找钣金Sketched Bend特征的所有直线(弯曲线)并选择所有线段。
{ width=400 }
没有直接的SOLIDWORKS API方法可以获取弯曲线,但是弯曲线在由钣金特征拥有的草图中表示为草图线段。因此,为了找到弯曲线,需要找到该草图并解析其内容。
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Set swSelMgr = swModel.SelectionManager
Dim swFeat As SldWorks.Feature
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
If swFeat.GetTypeName2 = "SM3dBend" Then
Dim swBendSketch As SldWorks.Sketch
Set swBendSketch = FindBendSketch(swFeat)
Dim vSegs As Variant
vSegs = swBendSketch.GetSketchSegments()
swModel.ClearSelection2 True
Dim i As Integer
For i = 0 To UBound(vSegs)
Dim swSkSeg As SldWorks.SketchSegment
Set swSkSeg = vSegs(i)
If swSkSeg.GetType() = swSketchSegments_e.swSketchLINE Then
swSkSeg.Select4 True, Nothing
End If
Next
Else
MsgBox "请选择弯曲特征"
End If
Else
MsgBox "请打开模型"
End If
End Sub
Function FindBendSketch(swFeat As SldWorks.Feature) As SldWorks.Sketch
Dim swSubFeat As SldWorks.Feature
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not swSubFeat Is Nothing And swSubFeat.GetTypeName2() <> "ProfileFeature"
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
If Not swSubFeat Is Nothing Then
Set FindBendSketch = swSubFeat.GetSpecificFeature2
Else
MsgBox "未找到带有弯曲的草图"
End
End If
End Function