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
'------------------------------------------
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
'------------------------------------------