Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

macro to list path names of components 1

Status
Not open for further replies.

Yogibear

Mechanical
Sep 5, 2002
107
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

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


 
Replies continue below

Recommended for you

Unless you are wanting this as part of a larger macro, you can simply go to the File pull-down, then select Find References...
 
It didn't seem to pick up on the parts that were referenced from the network only parts from my c: drive.
 
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.
 
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.
 
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.
 
Yogibear, if you found MElam's suggestion helpful then give him a star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor