访问|数据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选择的容错机制,需要添加上。
solidworks二次开发-03-访问特征数据
80酷酷网 80kuku.com