SolidWorks机械工程师网——最大的SolidWorks学习平台

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1888|回复: 4
打印 上一主题 下一主题

宏代码——获取特征状态

[复制链接]

84

主题

286

帖子

168

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
474
QQ
跳转到指定楼层
楼主
发表于 2009-10-31 00:40:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

   经典图书
  
Get Editing Status of Features Example (VBA)
This example shows how to get the editing status of one or more features.

'-------------------------------------
'
' Preconditions:
' (1) Open samplestutorialintrotoswpressure_plate.sldprt.
' (2) Insert a breakpoint in your macro at this line:
' retVal = swModelDocExt.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
' (3) Run the macro (F5) and then step into the code using
' the debugger (F8) after execution stops at the breakpoint.
' (4) Examine the results displayed in the Immediate window and
' FeatureManager design tree while stepping through the
' remaining code.
'
' Postconditions: None
'
' NOTE: Because this document is used by a SolidWorks
' online tutorial, do not save any changes when
' closing the document.
'
'-------------------------------------
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeatMgr As SldWorks.FeatureManager
Dim swSelMgr As SldWorks.SelectionMgr
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim varFeat As Variant
Dim editStatus As Long
Dim retVal As Boolean
Dim i As Long
Dim featName As String

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeatMgr = swModel.FeatureManager
Set swSelMgr = swModel.SelectionManager
Set swModelDocExt = swModel.Extension

' Traverse through the FeatureManager design tree
' to get the editing status of all features
' Change the editing status of a sketch and feature
' during feature traversal
varFeat = swFeatMgr.GetFeatures(True)
editStatus = swFeature_NonEditable
For i = LBound(varFeat) To UBound(varFeat)
Dim swFeat As SldWorks.Feature
Set swFeat = varFeat(i)
featName = swFeat.Name
Select Case (featName)
Case "Sketch2"
' Select and edit a sketch
retVal = swModelDocExt.SelectByID2("Sketch2", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
swModel.EditSketch
Case "Extrude3"
' Close the open sketch
swModel.InsertSketch2 True
Case "Cut-Extrude2"
' Select and edit a feature
retVal = swModelDocExt.SelectByID2("Cut-Extrude2", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
swModel.FeatEdit
End Select
' Get the editing status of the current feature
editStatus = swFeat.GetEditStatus
Select Case (editStatus)
Case 0
Debug.Print (swFeat.Name & " can be edited.")
Case 1
Debug.Print (swFeat.Name & " cannot currently be edited.")
Case 2
Debug.Print (swFeat.Name & " is already being edited.")
End Select
Set swFeat = Nothing
Next i

' End feature editing
swModel.InsertSketch2 True

End Sub
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 转播转播 分享教程|习题|模型|技巧 点赞点赞16610 拍砖拍砖1100
SolidWorks机械工程师网
提示:建议使用谷歌浏览器浏览本网站!如单击这里下载!否则,可能无法下载附件文件!(支持大多数版本的谷歌浏览器,支持360和QQ浏览器的极速模式,即谷歌内核模式,使用IE和Edge浏览器,浏览个别网页以及下载文件时,会误报“***不安全”,此时需要单击“继续访问此不安全站点(不推荐)”才可以继续下载,另外,本网站不含任何不安全的文件,已联系微软公司解决,纯属IE和Edge浏览器误报)
回复

使用道具 举报

9

主题

201

帖子

22

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
246
QQ
沙发
发表于 2009-10-31 01:00:55 | 只看该作者
E文有难度!
学习!!谢了!
SolidWorks机械工程师网
提示:建议使用谷歌浏览器浏览本网站!如单击这里下载!否则,可能无法下载附件文件!(支持大多数版本的谷歌浏览器,支持360和QQ浏览器的极速模式,即谷歌内核模式,使用IE和Edge浏览器,浏览个别网页以及下载文件时,会误报“***不安全”,此时需要单击“继续访问此不安全站点(不推荐)”才可以继续下载,另外,本网站不含任何不安全的文件,已联系微软公司解决,纯属IE和Edge浏览器误报)
回复 支持 反对

使用道具 举报

19

主题

235

帖子

39

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
287
QQ
板凳
发表于 2009-10-31 01:01:48 | 只看该作者

   经典图书
进来学习。。。
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

9

主题

222

帖子

17

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
253
QQ
地板
发表于 2009-10-31 01:02:07 | 只看该作者
学习了
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

0

主题

35

帖子

17

金币

天使

Rank: 2Rank: 2

积分
114

最佳新人活跃会员宣传达人

5#
发表于 2022-3-24 14:59:44 | 只看该作者

   经典案例图书
好深奥的样子
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭 卷起
关闭 卷起

SOLIDWORKS 2023 机械设计从入门到精通

手机版|小黑屋| GMT+8, 2024-9-28 12:23 , Processed in 0.185677 second(s), 24 queries , Memcache On.

SolidWorks机械工程师网 ( 鲁ICP备14025122号-2 ) 鲁公网安备 37028502190335号

声明:本网言论纯属发表者个人意见,与本网立场无关。
如涉版权,可发邮件: admin@swbbsc.com

快速回复 返回顶部 返回列表