×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

BOM API

BOM API

BOM API

(OP)
Hi,

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

Regards,

MHendler

RE: BOM API

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.

RE: BOM API

From an assembly:

'<><><><><><><><><><><><><><><><><><>
' 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("SldWorks.Application")
    Set swAssy = swApp.ActiveDoc
    If (swAssy.GetType <> swDocASSEMBLY) Then
        swApp.SendMsgToUser "You need to open an Assembly"
        Exit Sub
    End If
    'Get Assy Name - Strip Extension
    sAssyName = swAssy.GetTitle
    If InStr(1, sAssyName, ".") Then
        sAssyName = Left$(sAssyName, InStr(1, sAssyName, ".") - 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 & " Items"
    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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources