solidworks vba 分割特征

solidworks vba PostSplitBody2 Method(分割实体命令)

提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档

一、分割特征

分割实体[外链图片转存失败,源站可能有防盗在这里插入!链机制,建描述]议将图片上https://传(imblog.csdnimg.cn/20201111092wIxN8607.png#pic_center70)(剪裁)]
在这里插入图片描述

![在这里插入图片描述](https://img-blog.csdnimg.cn/20201111092550862.png#pic_center

在这里插入图片描述

二、分割常见问题

分割自动指派名字后会提示
在这里插入图片描述
且分割特征失败
这个问题出现的原因是solidworks找不到默认模板的位置
解决办法:点击选项-默认模板
在这里插入图片描述

二、PreSplitBody2

作用:得到分割后的所有实体数据
1.选择分割工具将实体分割
2.使用PreSplitBody2获得所有实体的数据
3.使用PostSplitBody2分割实体
PreSplitBody2返回值为分割后的所有实体的数据数组,用于填入PostSplitBody2中bodiestomark的参数中。

三、PostSplitBody2

PostSplitBody2(BodiesToMark, ConsumeCut, Origins, SavePaths, OverrideTemplateName)
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

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值