> Access Selections Example (VBA)
Welcome
Getting Started
SolidWorks API Help
FeatureWorks API Help
SolidWorks Document Manager API Help
eDrawings API Help
SolidWorks Routing API Help
SolidWorks Simulation API Help
SolidWorks Utilities API Help
SolidWorks Workgroup PDM API Help
Hide Table of Contents Show Table of Contents

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.

  1. 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

     

  2. Obtain the selected feature, and extract the feature data Object from the feature.

    Set CurFeature = SelMgr.GetSelectedObject5(1)

    Set FeatData = CurFeature.GetDefinition

     

  3. Get the permissions to access the parameters of the feature.

    isGood = FeatData.AccessSelections(Model, Component)

     

  4. Modify the feature data, in this case double the depth of the extrude.

    Depth = FeatData.GetDepth(True)

    FeatData.SetDepth True, Depth * 2

     

  5. Implement the changes in the model.

    isGood = CurFeature.ModifyDefinition(FeatData, Model, Component)

     

  6. If the Feature::ModifyDefinition call fails for any reason, release the access permissions for the feature data.

    FeatData.ReleaseSelectionAccess

     

  7.  



Related SolidWorks Forum Content

Provide feedback on this topic

SolidWorks welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Access Selections Example (VBA)
*Comment:  
x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2012 SP05

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of DS SolidWorks or its licensors. The topics within the Web-based help are not beta topics; they document API Help (English only) 2012 SP05.

To disable Web help from within SolidWorks and use local help instead, click Help > Use SolidWorks Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.