Hi,
I don't know, what's the correct code, for getting the name of an assembly component by selecting it in the graphic window.
The user should have the ability to slect an component and Inventor will give you the name of this component (filename, Screenname or whatever :))
I need the name to go on wth it in .net.
Best Regards
Passi
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi Passi,
This might work for you (note it's formatted for iLogic so you might need to tweek it just a bit):
'get currently selected component Dim oOccurrence as ComponentOccurrence Try oOccurrence = ThisDoc.Document.SelectSet.Item(1) Catch MessageBox.Show("Please select a component before running this rule.", "iLogic") Return End Try Dim doc As Document Dim CurFileName As String 'set the selected item oOccurrence = ThisApplication.ActiveDocument.SelectSet.Item(1) 'get the selected item document occurrence name doc = oOccurrence.Definition.Document 'get the path and file name of the selected item CurFileName = doc.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 file name (without extension) ShortName = Left(Name, Len(Name) - 4) 'get the path of the folder containing the file Folder_Location = Left(CurFileName, Len(CurFileName) - Len(Name)) MessageBox.Show("File Name: " & Name _ & vblf & "File Name without extension: " & ShortName _ & vblf & "File Path: " & Folder_Location _ & vblf & "Path and File Name: " & CurFileName, "iLogic")
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hi Curtis,
Many thanks to you.
That helps me to get it work. I will post the VB Code when it's done (Today I have to solve some other problems first).
By the way. Nice Blog. I will look into it a llittle deeper. Seems to have a lot of interesting things to discover 🙂
Best Regards
Passi
I was looking for something like this a while back, ended up making something using vb.net.
A couple small differences that improved the workflow for me (and since using vb.net, I had the capability);
Instead of a message box, I displayed the name in the statusbar (thisapplication.statusbartext or something like that).
That way you don't have to click OK.
Instead of clicking on an item, I set to trigger when hovering over something.
At the end of the day, I could just move my mouse around the graphics window, and if it hovered over a part in the assembly, the file name, location (rev level, whatever else) would flash on the statusbar.
If I decided to click on it, it would open up a relevant intranet page with a whole lot more information regarding the part number. Otherwise, I would hit escape to get out of it.
Just personal preference I guess, but thought it would be worth mentioning, as it may give you ideas about what your going to develop.
V.
Hi and thanks for the idea.
Is it ok from the speed? Can you feel the vb is working while moving around? Our assemblies could be very big.
The idea you mentioned could be useful for controlling the path of the components of the assembly. A lot of users here, do not have a full understanding of vault and copying assemblies 🙂
But in my case, I need only the name of the part to start some part specific program. And that's only possible by getting the name. So the name would not be displayed on the screen.
The user will clik on a part, start the prog via clicking on an icon (or whatever, maybe the context menu, if I get access on it :D) and then the specific program would run.
The name of the part in this case is important for choosing the correct prog to run.
Best Regards.
Passi
Here's the code, if somebody needs it:
For external VB.net Program:
Needs Autodesk.Inventor.Interop.dll and Imports Inventor for the Class
____________________
Public Function Componentname() As String
Dim Inventor As Inventor.Application
Inventor = Inventorlaeuft() 'Sub Function to get the active Inventor Session <-- Not given here.
Dim oOccurrence As ComponentOccurrence
Dim doc As Document
Try
oOccurrence = Inventor.ActiveDocument.SelectSet.Item(1)
doc = oOccurrence.Definition.Document
Dim CurFileName As String
CurFileName = doc.FullFileName
Componentname = CurFileName
MsgBox(CurFileName & vbCrLf & doc.FullDocumentName & vbCrLf & doc.DisplayName & vbCrLf & doc.InternalName & vbCrLf & oOccurrence.Name)
Catch Fehler As Exception
MsgBox("Please choose a component first.")
Componentname = "Error"
End Try
End Function
_________________________________
If you need it in VBA:
Public Sub GetName()
Dim oOccurrence As ComponentOccurrence
Dim doc As Document
On Error GoTo Ende
Set oOccurrence = ThisApplication.ActiveDocument.SelectSet.Item(1)
If Err Then Exit Sub
Set doc = oOccurrence.Definition.Document
Dim CurFileName As String
CurFileName = doc.FullFileName
MsgBox (CurFileName)
GoTo Ende2
Ende:
MsgBox ("Please choose an Element first.")
Ende2:
End Sub
__________________________
Best Regards
Pascale