Hide Table of Contents

Get Faces Affected by Scale Feature Example (VBA)

This example shows how to get the faces affected by a scale feature.

 

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

'

' Problem:

'       In SolidWorks, a feature is a collection of faces.

'       The faces created by a feature can be retrieved through

'       IFeature::GetFaces.

'

'       However, certain types of features only affect existing

'       faces and do not create any new faces. Examples of

'       these types of features are a draft or a scale feature.

'       For these features, IFeature::GetFaces returns an

'       empty array (no faces).

'

'       To get the faces affected by a scale feature,

'       first get the solid bodies to which the

'       scale feature is applied. Each body is composed of

'       a number of faces, which you can use to determine where

'       these faces are located after the scale feature has

'       been applied to the body.

'

'       The interesting issue is how to locate a face after

'       a rebuild because, after a rebuild, a face may no longer

'       exist. To address this, SolidWorks has safe entities,

'       which are entities that survive rebuilds; thus, are  

'       valid across rebuilds.

'

'       This sample code shows how to use IScaleFeatureData::Bodies

'       and IEntity::GetSafeEntity to get the faces affected

'       by a scale feature.

'

' Preconditions:

'       (1) Part or assembly is open.

'       (2) Assembly is fully resolved.

'       (3) Scale feature is selected.

'

' Postconditions:

'       (1) Scale feature is deselected.

'       (2) Faces affected by scale feature are selected.

'

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

Option Explicit

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim swSelData               As SldWorks.SelectData

    Dim swFeat                  As SldWorks.feature

    Dim swScaleFeat             As SldWorks.ScaleFeatureData

    Dim vBody                   As Variant

    Dim vBodyArr                As Variant

    Dim swBody                  As SldWorks.body2

    Dim swFace                  As SldWorks.face2

    Dim swEnt                   As SldWorks.Entity

    Dim swSafeEnt               As SldWorks.Entity

    Dim vSafeEnt                As Variant

    Dim swSafeEntColl           As New Collection

    Dim i                       As Long

    Dim bRet                    As Boolean

    

    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    Set swFeat = swSelMgr.GetSelectedObject5(1)

    Set swScaleFeat = swFeat.GetDefinition

    

    Debug.Assert 0 = swFeat.GetFaceCount

    

    bRet = swScaleFeat.AccessSelections(swModel, Nothing)

    

    vBodyArr = swScaleFeat.Bodies

    For Each vBody In vBodyArr

        Set swBody = vBody

        Set swFace = swBody.GetFirstFace

        

        Do While Not swFace Is Nothing

            ' Face reference is only valid in rolled back

            ' state, so get a more persistent face reference

            Set swEnt = swFace

            Set swSafeEnt = swEnt.GetSafeEntity

            

            swSafeEntColl.Add swSafeEnt

        

            Set swFace = swFace.GetNextFace

        Loop

    Next

    

     swScaleFeat.ReleaseSelectionAccess

    

     For Each vSafeEnt In swSafeEntColl

        Set swSafeEnt = vSafeEnt

        

        bRet = swSafeEnt.Select4(True, swSelData)

        Debug.Assert bRet

    Next

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:   Get Faces Affected by Scale 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) 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.