solidworks vba PostSplitBody2 Method(分割实体命令)
提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档
一、分割特征

BodiesToMark:为PreSplitBody2的返回值,即分割后所有实体的数据数组
ConsumeCut:是否消耗实体(在零件中保存实体),true在零件中保存分割实体,false不保存
Origins:原点位置
SavePaths:分割零件保存位置
OverrideTemplateName:分割零件默认保存模板
备注:如果保存位置为空或者分割零件名称为空,此时零件只被标记不被另外单独保存。
实例:使用上视基准面分割零件:
This example shows how to create a Split feature.
'----------------------------------------------------------------------------
' Preconditions:
' 1. Open a part document that contains a body that is bisected by
' Top Plane.
' 2. Verify that c:\temp exists.
' 3. Open an Immediate window.
'
' Postconditions:
' 1. Creates Split1.
' 2. Saves a split body to c:\temp\Body1.sldprt.
' 3. Inspect the Immediate window, FeatureManager design tree, graphics area,
' and c:\temp.
'---------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeat As SldWorks.Feature
Dim swFeatMgr As SldWorks.FeatureManager
Dim swSplitBodyFeat As SldWorks.SplitBodyFeatureData
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swSelMgr = swModel.SelectionManager
Set swFeatMgr = swModel.FeatureManager
'Select the cutting tool
boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
'Get bodies resulting from the split operation
Dim vResultingBodies As Variant
vResultingBodies = swFeatMgr.PreSplitBody2
swModel.ClearSelection2 True
Dim vBodiesToMark As Variant
Dim vBodyNames As Variant
Dim vBodyOrigins As Variant
Dim bodiesToMark(1) As Object
Dim bodyNames(1) As String
Dim bodyOrigins(1) As Object
'Set up the arrays for the post-split operation
'Specify the origins of the bodies to save; specify Nothing to use the default origins
Set bodyOrigins(0) = Nothing
Set bodyOrigins(1) = Nothing
Set bodiesToMark(0) = vResultingBodies(0)
Set bodiesToMark(1) = vResultingBodies(1)
'Save the first body to a separate part document
'Substitute the name of the actual folder where to save the body
bodyNames(0) = "c:\temp\Body1.sldprt"
'Do not save the second body
bodyNames(1) = ""
vBodiesToMark = bodiesToMark
vBodyNames = bodyNames
vBodyOrigins = bodyOrigins
'Create the Split feature, consuming all split bodies
Set swFeat = swFeatMgr.PostSplitBody2((vBodiesToMark), True, (vBodyOrigins), (vBodyNames), "")
If (Not swFeat Is Nothing) Then
Debug.Print "Split feature: " & swFeat.Name
Set swSplitBodyFeat = swFeat.GetDefinition
Debug.Print "Consumed? " & swSplitBodyFeat.Consume
Debug.Print " "
End If
End Sub