Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
YuhanZhang
in reply to: Maxim-CADman77

You can also update the code a bit to handle the broken link scenario:

 

Sub Main()
	
	oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "")
Dim PrFtrNm As String="" 
Dim oNBND As NativeBrowserNodeDefinition=ThisDoc.Document.BrowserPanes.GetNativeBrowserNodeDefinition(oFace.SurfaceBody.CreatedByFeature)
If oNBND.NativeObject.Type=ObjectTypeEnum.kReferenceFeatureObject Then
	If oNBND.NativeObject.ReferenceComponent Is Nothing Then
		Dim oRefComp As ReferenceComponent
		Dim oRefFeature As ReferenceFeature
		
		Dim oDoc As PartDocument
		oDoc = ThisDoc.Document
		
		For Each oRefComp In oDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents
			PrFtrNm = getLabel(oNBND.NativeObject,oRefComp)
			If PrFtrNm <> "" Then
				GoTo findLabel
			End If
		Next
'		For Each oRefComp In oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents 
'			PrFtrNm = getLabel(oNBND.NativeObject,oRefComp)
'			If PrFtrNm <> "" Then
'				GoTo findLabel
'			End If
'		Next
			
	Else
		PrFtrNm = oNBND.NativeObject.ReferenceComponent.ReferencedDocumentDescriptor.DisplayName ' "With" exception failure if link to derived (reference) component is suppressed or broken.
	End If
	
findLabel :

Else
	PrFtrNm=oNBND.Label
End If
MsgBox(PrFtrNm, , "PrFtrNm")
End Sub

Function getLabel(oParentRefFeature As ReferenceFeature, oRefComp As ReferenceComponent) As String
For Each oRefFeature In oRefComp.ReferenceFeatures
        If oParentRefFeature Is oRefFeature Then
            If oRefComp.ReferencedDocumentDescriptor Is Nothing Then
                getLabel = oRefComp.Name
                Exit For
            Else
                getLabel = oRefComp.ReferencedDocumentDescriptor.DisplayName
                Exit For
            End If
        End If
Next
End Function


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.