MACRO LIBRARY

Get named entities in a component

Free public access. No account or subscription required.

Files

Get named entities in a component

Code

'Demonstrates how to get all named entities in a component using IPartDoc::GetNamedEntities and _
    IComponent2::GetCorresponding
    
'Preconditions: 1) Assembly is open with a component that contains entites (e.g., faces, edges, _
    vertices) that were named at the part level. 2) That component's name is specified in the _
    first constant.
'Results: named entities are selected in the assembly context
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Const COMP_NAME As String = "testing_block-1"
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swPart As SldWorks.PartDoc
Dim swComp As SldWorks.Component2
Dim swEnt As SldWorks.Entity
Dim swModel2 As SldWorks.ModelDoc2
Dim i As Integer
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swAssy = swModel
    Set swComp = swAssy.GetComponentByName(COMP_NAME)
    
    Set swModel2 = swComp.GetModelDoc2
    Set swPart = swModel2
    vNamedEntities = swPart.GetNamedEntities
    
    For i = 0 To UBound(vNamedEntities)
        Set swEnt = vNamedEntities(i)
        Set swEnt = swComp.GetCorresponding(swEnt)
        swEnt.Select4 True, Nothing
    Next i
End Sub