Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get File path of selected item

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
pball
3588 Views, 9 Replies

Get File path of selected item

I'm looking to get the file path of a selected part/assembly while inside of an assembly. I think I found something that can get it but the example is just different enough I can't figure it out and I don't have time to play with it. There also might be an easier way I couldn't find while searching.

 

This is the example code that seems to be able to do loads of things including get the full path, if you know what you're doing.

http://modthemachine.typepad.com/my_weblog/2008/10/program-prototyping.html

9 REPLIES 9
Message 2 of 10
FarrenYoung
in reply to: pball

I'm not sure if you meant that you need to get the path in your own program or if you were trying to create a utility that would do this for you. If you just want a utility that will do this for you and if you are running Inventor 2013 or later there is a nice app in the Inventor App Exchange that does this.
http://apps.exchange.autodesk.com/INVNTOR/Detail/Index?id=appstore.exchange.autodesk.com%3ainventorf...
--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Message 3 of 10
pball
in reply to: FarrenYoung

That isn't really what I'm looking for. I want the full path of a select part/assembly inside of an assembly using VBA code.

Message 4 of 10
nagwani
in reply to: pball

Hi There,

 

The sample VBA code below gets the path of selected occurrence in an assembly document.

 

Hope this helps!

 

-Ishwar N

 

Sub TestOccPath()
    Dim odoc As AssemblyDocument
    Set odoc = ThisApplication.ActiveDocument
    
    Dim obj As Object
    Set obj = odoc.SelectSet.Item(1)
    
    Dim occ As ComponentOccurrence
    Set occ = obj
    Dim spath As String
    spath = getOccPath(occ)
End Sub

Public Function getOccPath(ByVal m_occ As Inventor.ComponentOccurrence) As String
    Dim m_name As String
    If m_occ.OccurrencePath.Count = 1 Then
        ' The occurenace path is name of parent assembly + current componnet
        getOccPath = m_occ.Name
        Exit Function
    Else
        'build up occurrent path in case of nested component
        Dim m_occtemp As Inventor.ComponentOccurrence
        For Each m_occtemp In m_occ.OccurrencePath
            m_name = m_name + m_occtemp.Name + "\"
        Next
        Mid(m_name, Len(m_name)) = " " 'replace last "\" with space
        getOccPath = Trim(m_name)
        Exit Function
    End If
End Function

 

 

Message 5 of 10
GeorgK
in reply to: pball

Sub get_Path()
    Dim FullFileName As String
    Dim FilePath As String
    FullFileName = ThisApplication.ActiveDocument.FullFileName
    FilePath = Left(FullFileName, InStrRev(FullFileName, "\"))
    ThisApplication.Caption = FullFileName  'FilePath
    MsgBox "File Path: " & FilePath, vbOKOnly, FilePath
    MsgBox "Full File Name: " & FullFileName, vbOKOnly, FullFileName
    Variable = InputBox("Path", "Input", FullFileName, 1, 1)
   
    Shell "explorer.exe /e, """ & FilePath & """", vbNormalFocus
    
   Shell "Explorer.exe /e,/select, """ & FullFileName & """", vbNormalFocus
End Sub

Message 6 of 10
pball
in reply to: nagwani

nagwani

 

Your code is returning the name in the browser tree which I don't trust since it can wrong and that doesn't help with the path. Also it doesn't appear to work if you are editing a subassembly.

 

GeorgK

 

I'm not quite sure what your code does.

Message 7 of 10
nagwani
in reply to: pball

HI,

 

It seems tha you want full path of selected occurrence. The sample code shown below demonstrates same.

 

Regards,

-Ishwar N

 

Sub geSelectedPath()
Dim obj As Object
Set obj = ThisApplication.ActiveDocument.SelectSet.Item(1)
If (TypeOf obj Is ComponentOccurrence) Then
   Dim occ As ComponentOccurrence
   Set occ = obj
   Debug.Print occ.Definition.Document.FullFileName
End If
End Sub

Message 8 of 10
pball
in reply to: nagwani

Thanks, that's exactly what I'm looking for.

Message 9 of 10
akosi
in reply to: nagwani

how to use the path that is printed using debug.print

 

and open that file?

 

 

Message 10 of 10
pball
in reply to: akosi

Sub openselected()
  Dim obj As Object
  Set obj = ThisApplication.ActiveDocument.SelectSet.Item(1)
  If (TypeOf obj Is ComponentOccurrence) Then
     Dim occ As ComponentOccurrence
     Set occ = obj
     Set odrawdoc = ThisApplication.Documents.Open(occ.Definition.Document.FullFileName, True)
     odrawdoc.Activate
  End If
End Sub

 I replaced the debug.print with the commands to open the drawing. The first new line opens the drawing and the second line activates it.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report