Hi, I guess you're talking about ilogic. I'll give you a couple of examples.
With this example you can select a component and observe the fullfilename and the displayname
Dim oPart As ComponentOccurrence
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select component")
If oPart Is Nothing Then
Exit Sub
Else
Dim odoc As Document
odoc = oPart.Definition.Document
MessageBox.Show(odoc.DisplayName, "Document Name")
MessageBox.Show(odoc.FullFileName, "FullFileName")
End If
If you need the path of the selected file you could use something like this
Dim oPart As ComponentOccurrence
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select component")
If oPart Is Nothing Then
Exit Sub
Else
Dim odoc As Document
odoc = oPart.Definition.Document
Dim CurFileName As String
'get the path and file name of the selected item
CurFileName = odoc.FullFileName
'defines backslash as the subdirectory separator
Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
'find the postion of the last backslash in the path
FNamePos = InStrRev(CurFileName, "\", -1)
'get the file name with the file extension
Name = Right(CurFileName, Len(CurFileName) - FNamePos)
'get the path of the folder containing the file
Folder_Location = Left(CurFileName, Len(CurFileName) - Len(Name)-1)
MessageBox.Show(Folder_Location, "Folder Location")
End If
If you have previously selected the assembly occurrence, I think you could use something like this.
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.Count = 0 Then
Exit Sub
Else
Dim oCC As ComponentOccurrence = TryCast(oSSet.Item(1), ComponentOccurrence)
Dim oDoc As Document
oDoc = oCC.Definition.Document
MessageBox.Show(odoc.DisplayName, "Document Name")
MessageBox.Show(oDoc.FullFileName, "FullFileName")
End If
similarly if you have previously selected the component in the assembly and you need your path, I think you should try something like this.
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.Count = 0 Then
Exit Sub
Else
Dim oCC As ComponentOccurrence = TryCast(oSSet.Item(1), ComponentOccurrence)
Dim oDoc As Document
oDoc = oCC.Definition.Document
Dim CurFileName As String
'get the path and file name of the selected item
CurFileName = oDoc.FullFileName
'defines backslash as the subdirectory separator
Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
'find the postion of the last backslash in the path
FNamePos = InStrRev(CurFileName, "\", -1)
'get the file name with the file extension
Name = Right(CurFileName, Len(CurFileName) - FNamePos)
'get the path of the folder containing the file
Folder_Location = Left(CurFileName, Len(CurFileName) - Len(Name)-1)
MessageBox.Show(Folder_Location, "Folder Location")
End If
I hope that whatever path you try to take helps you solve your problem. regards!
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn