Hide Table of Contents

Get Part for Corresponding Component Example (VBA)

This example shows how to get the names of the part entity and the corresponding assembly component entity.

 

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

'

' Preconditions:

'        (1) Assembly document is open.

'        (2) Select the feature whose part's and component's name you want.

'

' Postconditions: None

'

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

Option Explicit

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swModelDocComp          As SldWorks.ModelDoc2

    Dim swModelDocExt           As SldWorks.ModelDocExtension

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim swAssyFeat              As SldWorks.feature

    Dim swPartFeat              As SldWorks.feature

    Dim swComp                  As SldWorks.Component2

    Dim vFaceArr                As Variant

    Dim swAssyFace              As SldWorks.face2

    Dim swPartFace              As SldWorks.face2

    Dim swAssyEnt               As SldWorks.entity

    Dim swPartEnt               As SldWorks.entity

    Dim bRet                    As Boolean

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

 

    Set swAssyFeat = swSelMgr.GetSelectedObject5(1)

    Set swComp = swSelMgr.GetSelectedObjectsComponent2(1)

    Set swModelDocComp = swComp.GetModelDoc

    Set swModelDocExt = swModelDocComp.Extension

    

    vFaceArr = swAssyFeat.GetFaces: Debug.Assert Not IsEmpty(vFaceArr)

    

    Set swAssyFace = vFaceArr(0)

    Set swAssyEnt = swAssyFace

    Set swPartEnt = swModelDocExt.GetCorrespondingEntity(swAssyEnt): Debug.Assert Not swPartEnt Is Nothing

    Set swPartFace = swPartEnt

    Set swPartFeat = swPartFace.GetFeature: Debug.Assert Not swPartFeat Is Nothing

    

    Debug.Print "Comp       = " + swComp.Name2 + " [" + swComp.GetPathName + "]"

    Debug.Print "  AssyFeat   = " + swAssyFeat.Name

    Debug.Print "  PartFeat   = " + swPartFeat.Name

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 Part for Corresponding Component 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.