How to get full filename of selected Occurence

How to get full filename of selected Occurence

SandmanINV
Advocate Advocate
3,600 Views
2 Replies
Message 1 of 3

How to get full filename of selected Occurence

SandmanINV
Advocate
Advocate

Hi, 

Like my title topic, I want get full filename (path file) of selected Occurence and display in a label or textbox. But i dont know how to do that.

Someone help me pls.

Thank you

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

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

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

Message 3 of 3

SandmanINV
Advocate
Advocate

I am using Vb.net. But your reply is so good example with me. Thank you, thank very much.

0 Likes