Access Data Example (VBA)
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
isGood = FeatData.AccessSelections(Model,
Modify the feature data, in this case double the depth
of the extrude.
Depth = FeatData.GetDepth(True)
True, Depth * 2
Implement the changes in the model.
isGood = CurFeature.ModifyDefinition(FeatData,
If the Feature::ModifyDefinition call fails for any
reason, release the access permissions for the feature data.