solidworks二次开发-03-访问特征数据

王朝c#·作者佚名  2006-12-17
宽屏版  字体: |||超大  

solidworks二次开发-03-访问特征数据 'coder arden

'filename : getchoosed.swp

'date :2005-03-22

'used to get the simple hole infomation dep & dia

'finished lucky !!

'------------------------------------------------------------

Option Explicit

Dim swApp As SldWorks.SldWorks

Dim Model As ModelDoc2

Dim curfeature As feature

Dim boolstatus As Boolean

Dim featdata As SimpleHoleFeatureData2 '声明一个简单直孔对象

Dim component As Component2

Dim dep As Double

Dim dia As Double

Dim SelMgr As SelectionMgr

Dim ncount As Integer

Sub getselected()

Set swApp = Application.SldWorks

Set Model = swApp.ActiveDoc

Set SelMgr = Model.SelectionManager

Set curfeature = SelMgr.GetSelectedObject5(1) '得到当前选中的第一个特征

MsgBox curfeature.Name

Set featdata = curfeature.GetDefinition '得到特征的定义

boolstatus = featdata.AccessSelections(Model, component) ' 可以对数据进行访问了

ncount = featdata.GetFeatureScopeBodiesCount

MsgBox ncount

dep = featdata.Depth

dia = featdata.Diameter

MsgBox dia & '*' & dep

'MsgBox 'error arden' '在solidworks中可以使用swAPP.sendmsgtouser2

'featdata.ReleaseSelectionAccess

Model.Save

Model.EditRebuild

End Sub

**********************************************

上面程序运行前,假设你选择了一个简单直孔特征。然后得到这个孔德一些参数。

孔深、直径等。

solidworks的API虽然是e文的。介绍的还算详细,并且有很多的example。大家可以多看看代码。

要访问一个特征,需要经历这样的步骤:

定义一个特征对象: dim....as ...

得到这个特征 :比如使用GetSelectedObject5 还有SelectebyID等...

得到定义:GetDefinition

进行访问:AccessSelections

上面的程序没有if选择的容错机制,需要添加上。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有