Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

BOM API

Status
Not open for further replies.

MHendler

Mechanical
Mar 28, 2002
35
Hi,

Could you explain how to make a routine that just get the names of the level 1 components of an assembly?

Regards,

MHendler
 
Replies continue below

Recommended for you

Do you want to gather information from the drawing BOM or from the assembly? DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
From an assembly:
Code:
'<><><><><><><><><><><><><><><><><><>
' List Top Level Parts in an Assembly
'<><><><><><><><><><><><><><><><><><>
Option Explicit

Const swDocASSEMBLY = 2

Sub Main()
    Dim swApp As Object
    Dim swAssy As Object
    Dim swConfig As Object
    Dim swRoot As Object
    Dim swComp() As Object
    Dim swChild As Object
    
    Dim sAssyName As String
    Dim i As Integer
    Dim ChildCount As Integer
    Dim sMsg As String

    Set swApp = CreateObject(&quot;SldWorks.Application&quot;)
    Set swAssy = swApp.ActiveDoc
    If (swAssy.GetType <> swDocASSEMBLY) Then
        swApp.SendMsgToUser &quot;You need to open an Assembly&quot;
        Exit Sub
    End If
    'Get Assy Name - Strip Extension
    sAssyName = swAssy.GetTitle
    If InStr(1, sAssyName, &quot;.&quot;) Then
        sAssyName = Left$(sAssyName, InStr(1, sAssyName, &quot;.&quot;) - 1)
    End If
    'Find the Root Component
    Set swConfig = swAssy.GetActiveConfiguration()
    Set swRoot = swConfig.GetRootComponent()
    swComp = swRoot.GetChildren
    'Find Children
    ChildCount = UBound(swComp) + 1
    sMsg = ChildCount & &quot; Items&quot;
    For i = 0 To (ChildCount - 1)
        Set swChild = swComp(i)
        sMsg = sMsg & vbCrLf & swChild.Name
    Next i
    'Report Results
    swApp.SendMsgToUser sMsg
    'Clean Up
    Set swChild = Nothing
    Set swRoot = Nothing
    Set swConfig = Nothing
    Set swAssy = Nothing
    Set swApp = Nothing
End Sub
Hope this helps... DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor