Inventor Customization

Reply
Active Contributor
Passi
Posts: 48
Registered: ‎03-24-2011
Message 1 of 6 (440 Views)
Accepted Solution

Want to get component name by selecting it in graphic window (vb.net)

440 Views, 5 Replies
07-03-2012 07:42 AM

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 :smileyhappy:)

 

I need the name to go on wth it in .net. 

 

Best Regards 

 

Passi 

*Expert Elite*
Curtis_Waguespack
Posts: 2,566
Registered: ‎03-08-2006
Message 2 of 6 (432 Views)

Re: Want to get component name by selecting it in graphic window (vb.net)

07-03-2012 11:56 AM in reply to: Passi

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



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Active Contributor
Passi
Posts: 48
Registered: ‎03-24-2011
Message 3 of 6 (413 Views)

Re: Want to get component name by selecting it in graphic window (vb.net)

07-04-2012 08:59 AM in reply to: Passi

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 :smileyhappy:

 

Best Regards

 

Passi 

Contributor
Posts: 23
Registered: ‎09-16-2008
Message 4 of 6 (408 Views)

Re: Want to get component name by selecting it in graphic window (vb.net)

07-04-2012 01:22 PM in reply to: 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.

Active Contributor
Passi
Posts: 48
Registered: ‎03-24-2011
Message 5 of 6 (399 Views)

Re: Want to get component name by selecting it in graphic window (vb.net)

07-04-2012 11:08 PM in reply to: Passi

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 :smileyhappy:

 

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 :smileyvery-happy:)  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 

Active Contributor
Passi
Posts: 48
Registered: ‎03-24-2011
Message 6 of 6 (397 Views)

Re: Want to get component name by selecting it in graphic window (vb.net)

07-05-2012 12:28 AM in reply to: 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 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube