Hide Table of Contents

Suppress or Unsuppress Feature Example (VBA)

This example shows how to pass in two strings and either suppress or unsuppress features in a part. The first input parameter, SearchStr, allows you to pass in a feature name or a portion of a feature name. This routine cycles through all the features in the part and selects all features that contain the specified search string. For example, if you pass the string "Hole",  this routine selects any feature with a name containing the word "Hole". The second parameter passed, Action, determines whether the selected features are suppressed or unsuppressed.

This example shows how to:

  • Cycle through features in a part

  • Get a feature name

  • Suppress and unsuppress features

  • Perform a string comparison using Visual Basic

 

'---------------------------------------------

Sub FeatureSuppression(SearchStr, Action)

 

' Variable used to hold the SldWorks object

Dim swApp As Object  

' Variable used to hold the ModelDoc object

Dim Model As Object  

' Variable used to hold the current Feature object

Dim feat As Object  

Dim featureName As String

' These definitions are consistent with type names

Const swDocPART = 1   

' Constant enumerators

Const swDocASSEMBLY = 2   

Const swDocDRAWING = 3

 

Set swApp = CreateObject("SldWorks.Application")

' Attach to the active document

Set Model = swApp.ActiveDoc  

 

' Exit if no model is active

If Model Is Nothing Then  

Exit Sub

End If

 

' Do not allow drawings or assemblies

If (Model.GetType <> swDocPART) Then  

' Define message

Msg = "Only Allowed on Parts"

' OK Button only

Style = vbOKOnly

' Define title

Title = "Error"

' Display error message

Call MsgBox(Msg, Style, Title)

' Exit this program

Exit Sub

End If

 

 

' Get the 1st feature in part

Set feat = Model.FirstFeature

 

' While we have a valid feature

Do While Not feat Is Nothing

' Get the name of the feature

Let featureName = feat.Name

' See if the feature name contains our search string

If InStr(1, featureName, SearchStr, 1) Then

' Select the feature

res = Model.SelectByID(featureName, "BODYFEATURE", 0, 0, 0)

If (Action = "Suppress") Then ' User chose to suppress

res = Model.EditSuppress() ' Suppress the feature

ElseIf (Action = "Unsuppress") Then ' User chose to unsuppress

res = Model.EditUnSuppress() ' Unsuppress the feature

End If

End If

Set feat = feat.GetNextFeature() ' Get the next feature

Loop ' Continue until no more features exist

 

End Sub

 

 



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:   Suppress or Unsuppress Feature Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



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) 2015 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.