Access Data Example (VBA)
View Code
All features have a feature data object that contains specific information
about each instance of the feature. For
example, an extrude feature contains an IExtrudeFeatureData2 object that
contains the parameters for the extrude’s depth. The IExtrudeFeatureData2::AccessSelections
method is called to allow a program to modify a feature data object. After
making the changes, call IFeature::ModifyDefinition to implement the changes
to the feature and release control of the feature data object. A call
to IExtrudeFeatureData2::ReleaseSelectionAccess also releases control
of the feature data object.
This example shows how to access and modify the data specific to a certain
feature in a SOLIDWORKS part or assembly. To use this example, open a
part with a base extrusion and select the base extrusion.
-
Attach the program to SOLIDWORKS, get the active model,
and access the ISelectionManager.
Set swApp = CreateObject("sldWorks.application")
Set Model = swApp.ActiveDoc
Set SelMgr = Model.SelectionManager
-
Obtain the selected feature, and extract the feature
data Object from the feature.
Set CurFeature = SelMgr.GetSelectedObject5(1)
Set FeatData = CurFeature.GetDefinition
-
Get the permissions to access the parameters of the
feature.
isGood = FeatData.AccessSelections(Model,
Component)
-
Modify the feature data, in this case double the depth
of the extrude.
Depth = FeatData.GetDepth(True)
FeatData.SetDepth
True, Depth * 2
-
Implement the changes in the model.
isGood = CurFeature.ModifyDefinition(FeatData,
Model, Component)
-
If the Feature::ModifyDefinition call fails for any
reason, release the access permissions for the feature data.
FeatData.ReleaseSelectionAccess