I'm getting closer. Perhaps I am not using the right terminology, but I do not understand how to reference the parent document of a single selection.
Intended Algorithm (please correct me)
- Assume the user makes a single (1) selection in the assembly.
- User runs my macro.
- Macro finds the name of the selection.
- Macro finds the "document" based on the name of the selection.
- Macro "pastes" FullDocumentName (ie file path C:\folder\subfolder\...\yourselectedpart.ipt)) of the "document" into the clipboard.
Here's what I've been able to successfully do:
1. Get all file paths of all the "documents" in the assembly and paste them in a clipboard. (most code swiped from the code sample in Brian Ekins' "Getting Started with Inventor VBA")
Public Sub ShowAllDocuments()
' Get the Documents collection object
Dim invDocs As Documents
Set invDocs = ThisApplication.Documents
' temporary output string
Dim Txt As String
Txt = ""
' Iterate through the contents of the Documents
Dim i As Integer
For i = 1 To invDocs.Count
' append document location to output string
Dim invDocument As Document
Set invDocument = invDocs.Item(i)
Txt = Txt & i & ". " & invDocument.FullDocumentName & vbCrLf
Next
' place contents of Txt into MyData
MyData.SetText Txt
MyData.PutInClipboard
End Sub
2. Output the "Name" of the selected
Public Sub DisplayName()
Dim oSelectSet As SelectSet
Set oSelectSet = ThisApplication.ActiveDocument.SelectSet
Dim strName As String
Dim strDisplayName As String
If oSelectSet.Count = 1 Then
strName = oSelectSet.Item(1).Name
MsgBox "NAME is " & strName
strDisplayName = ThisApplication.ActiveDocument.DisplayName
MsgBox "Display Name = " & strDisplayName
Exit Sub
Else
MsgBox "Select 1 item."
Exit Sub
End If
End Sub