Get component file name

Get component file name

Jonathanspies
Explorer Explorer
382 Views
2 Replies
Message 1 of 3

Get component file name

Jonathanspies
Explorer
Explorer

Hi,

I thought it is simple but i just dont get it going.

 

I have a known component/Display name in an assembly. Now i want to get the filename of this component based on the Display name in the Assembly to open it as a separate document, save it and close it. In the picture below you see the assembly tree... I want to open "C-RAIL" and save it, close it... then open "MOUNTING-BRACKET-out" and save it, close it... then open "MOUNTING_BRACKET-in" and save it...

 

This assembly will always get copied so i cannot use a static filename, i know how to open the document when i have a fixed filepath but i need to get the filepath and name through the assembly

 

Thanks

 

2023-02-17 13_51_51-Autodesk Inventor Professional 2022.jpg

0 Likes
Accepted solutions (1)
383 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Jonathanspies. Take a look at this example:

Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oOcc As ComponentOccurrence = oOccs.ItemByName("C-RAIL")
Dim oOccDoc As Document
oOccDoc = oOcc.Definition.Document
'or
'oOccDoc = oOcc.ReferencedDocumentDescriptor.ReferencedDocument
Dim oFFN As String = oOccDoc.FullFileName
Dim oFDN As String = oOccDoc.FullDocumentName
Dim oDName As String = oOccDoc.DisplayName

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

JelteDeJong
Mentor
Mentor

is this what you are looking for?

Dim yourOccurenceName = InputBox("Give the name", "Get name", "")

Dim doc As AssemblyDocument = ThisDoc.Document
Dim occs As ComponentOccurrences = doc.ComponentDefinition.Occurrences

Dim occ As ComponentOccurrence = occs.Cast(Of ComponentOccurrence).Where(Function(o) o._DisplayName = yourOccurenceName).FirstOrDefault

If (occ Is Nothing) Then
	MsgBox("Could not find occurencewith name: " & yourOccurenceName)
	Exit Sub
End If

Dim yourDoc As Document = ThisApplication.Documents.Open(occ.ReferencedFileDescriptor.FullFileName)
yourDoc.Save2()
yourDoc.Close(True)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes