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
Solved! Go to Solution.
Solved by nagwani. Go to Solution.
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.
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
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
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
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.