SOLIDWORKS Secondary Development -03-Access Feature Data
'CODER ARDEN' FileName: getchoosed.swp'date: 2005-03-22'USED to get the Simple Hole Infomation Dep & Dia'Finished Lucky !! ---------------- --------------------------------------------
Option ExplicitDim swApp As SldWorks.SldWorksDim Model As ModelDoc2Dim curfeature As featureDim boolstatus As BooleanDim featdata As SimpleHoleFeatureData2 'declare a simple hole Object Dim component As Component2 Dim dep As DoubleDim dia As DoubleDim SelMgr As SelectionMgrDim ncount As Integer
Sub getselected ()
Set swapp = application.sldworks
Set model = swapp.activedoc
SET SELMGR = Model.SelectionManager
Set curfeature = sleelmgr.getSelectedObject5 (1) 'Get the first characteristic of the currently selected
Msgbox curfeature.name set featdata = curfeature.getDefinition 'Definition of Features
BoolStatus = featdata.accessSelections (MODEL, Component) can access data
ncount = featdata.getfeaturescopebodiescount
Msgbox ncount
Dep = featdata.depth dia = featdata.diameter
MSGBOX DIA & "*" & dep
'MsgBox "Error Arden"' can use swapp.sendmsgtouser2 'featdata.releaseseelectionAccessModel.Savemodel.editRebuildendeModel.editRebuildend Sub
************************************************************
Before running the program, it is assumed that you have selected a simple straight pore feature. Then get some of this Confar.
Hole depth, diameter, etc.
Although SolidWorks's API is E text. The introduction is still detailed, and there are many examples. You can look at the code more.
To access a feature, you need to experience this step:
Define a feature object: DIM .... AS ...
This feature is obtained, for example, using getSelectedObject5 and SELECTEBYID, etc ...
Get the definition: getDefinition
Visit: AccessSelections
The above program does not have the fault tolerance mechanism for IF, you need to add it.