Secondary Development of SolidWorks-03-accessing feature data
'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 'declares a simple direct hole object
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) 'to obtain the first feature selected currently.
Msgbox curfeature. Name
Set featdata = curfeature. getdefinition 'to get the feature definition.
Boolstatus = featdata. accessselections (model, component) 'can access the data
Ncount = featdata. getfeaturescopebodiescount
Msgbox ncount
Dep = featdata. Depth
Dia = featdata. Diameter
Msgbox Dia & "*" & Dep
You can use swapp. sendmsgtouser2 in SolidWorks.
'Featdata. releaseselectionaccess
Model. Save
Model. editrebuild
End sub
**************************************** ******
Before running the program, assume you have selected a simple direct hole feature. Then we can get some parameters of this AMAP.
Hole depth, diameter, etc.
SolidWorks APIs are in E. The introduction is still detailed, and there are many example. You can take a look at the code.
To access a feature, follow these steps:
Define a feature object: dim......
This feature is obtained: for example, getselectedobject5 and selectebyid...
Get the definition: getdefinition
Access: accessselections
The above program does not have the fault tolerance mechanism selected by If. You need to add it.