×
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

macro to list path names of components

macro to list path names of components

macro to list path names of components

(OP)
I found this example code in the help file somewhere, I can't seem to find the original so this is modified a little.  The original didn't work and it still doesn't.  I want a macro that will tell me (in an assembly file) where all of the components are being pulled from ex. R:\standard parts\my parts

Thanks in advance.

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

'  Preconditions:

'       * File is open

'       * Feature is optionally selected in the FeatureManager design tree

'

' Postconditions:

'       None

'

Option Explicit

Public Enum swExternalReferenceStatus_e

    swExternalReferenceBroken = 0

    swExternalReferenceLocked = 1

    swExternalReferenceInContext = 3

    swExternalReferenceOutOfContext = 4

    swExternalReferenceDangling = 5

End Enum

Public Enum swSelectType_e

    swSelSKETCHES = 9       '  "SKETCH"

    swSelCOMPONENTS = 20    '  "COMPONENT"

    swSelBODYFEATURES = 22  '  "BODYFEATURE"

End Enum

Sub main()

    Dim swApp                   As SldWorks.SldWorks
    Dim swModel                 As SldWorks.ModelDoc2
    Dim swSelMgr                As SldWorks.SelectionMgr
    Dim swFeat                  As SldWorks.feature
    Dim swComp                  As SldWorks.Component2
    Dim vModelPathName          As Variant
    Dim vComponentPathName      As Variant
    Dim vFeature                As Variant
    Dim vDataType               As Variant
    Dim vStatus                 As Variant
    Dim vRefEntity              As Variant
    Dim vFeatComp               As Variant
    Dim nRefCount               As Long
    Dim nSelType                As Long
    Dim i                       As Long
    Dim bRet                    As Boolean

    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    nSelType = swSelMgr.GetSelectedObjectType2(1)

    Select Case nSelType

        ' Component in an assembly

        Case swSelCOMPONENTS

            Set swComp = swSelMgr.GetSelectedObjectsComponent2(1)

            nRefCount = swComp.ListExternalFileReferencesCount

            swComp.ModelDocExtension.ListExternalFileReferences _

                vModelPathName _

                vComponentPathName _

                vFeature _

                vDataType _

                vStatus _

                vRefEntity _

                vFeatComp

                

            Set swModel = swComp.GetModelDoc

        

        ' Feature in a part or assembly

        Case swSelBODYFEATURES, swSelSKETCHES

            Set swFeat = swSelMgr.GetSelectedObject5(1)

            nRefCount = swFeat.ListExternalFileReferencesCount

            

            swFeat.ListExternalFileReferences _

                vModelPathName _

                vComponentPathName _

                vFeature _

                vDataType _

                vStatus _

                vRefEntity _

                vFeatComp

            

        ' Top-level part or assembly

        Case Else

            nRefCount = swModel.ListExternalFileReferencesCount2

            

            swModel.ListExternalFileReferences2 _

                vModelPathName _

                vComponentPathName _

                vFeature _

                vDataType _

                vStatus _

                vRefEntity _

                vFeatComp

    End Select

        

    

    Debug.Print "ModelName = " + swModel.GetPathName

    Debug.Print "    RefCount           = " + Str(nRefCount)

    Debug.Print ""

    For i = 0 To nRefCount - 1

        Debug.Print "    ModelPathName      = " + vModelPathName(i)

        Debug.Print "    ComponentPathName  = " + vComponentPathName(i)

        Debug.Print "    Feature            = " + vFeature(i)

        Debug.Print "    DataType           = " + vDataType(i)

        Debug.Print "    Status             = " + Str(vStatus(i))

        Debug.Print "    RefEntity          = " + vRefEntity(i)

        Debug.Print "    FeatComp           = " + vFeatComp(i)

        Debug.Print ""

        Debug.Print ""

    Next i

End Sub

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


RE: macro to list path names of components

One of my programs catalogs parts in an assembly and provides a list.  Feel free to use any portions you need.

Download the macro version of the "Density Manager" from this page:
<http://www.esoxrepublic.com/freeware/>

Due to illness, the part of The Tick will be played by... The Tick.
http://www.EsoxRepublic.com

RE: macro to list path names of components

Unless you are wanting this as part of a larger macro, you can simply go to the File pull-down, then select Find References...

RE: macro to list path names of components

(OP)
It didn't seem to pick up on the parts that were referenced from the network only parts from my c: drive.

RE: macro to list path names of components

(OP)
Thanks MElam I guess I didn't see that command.  That is what I was looking for.
Didn't get your post before I replied to TheTick.

RE: macro to list path names of components

Yogibear:

Thanks for letting me know.  I tested the program with an assembly with local and network components, and I haven't been able to replicate the problem.

RE: macro to list path names of components

(OP)
I reran your program and was able to duplice it.  I didn't save the assembly after I inserted the network component.  Once I did save it then it picked up on the network component.  99% of the time it's operator error.
Thanks for the help.

RE: macro to list path names of components

Yogibear, if you found MElam's suggestion helpful then give him a star!

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