"Copy Full Path" of part to clipboard

"Copy Full Path" of part to clipboard

Anonymous
Not applicable
1,510 Views
2 Replies
Message 1 of 3

"Copy Full Path" of part to clipboard

Anonymous
Not applicable

I'm not sure if there's already a solution in existence or if I need to create a macro/add-in/SDK/custom-programming, so please guide me in the right direction.

 

Let's say I have an assembly. I would like the ability to right-click one of its parts and then be able to copy its full path (aka location in iProperties) to my clipboard.

 

Those of you who might have used the picture manager Picasa might be aware of this "Copy Full Path" functionality. See attached image.Fullscreen capture 1262011 50257 PM.bmp.jpg

 

0 Likes
Accepted solutions (1)
1,511 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

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)

  1. Assume the user makes a single (1) selection in the assembly.
  2. User runs my macro.
  3. Macro finds the name of the selection.
  4. Macro finds the "document" based on the name of the selection.
  5. 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
0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution

I found my own answer. Note this is just a macro, so you'll have to figure out how to put it in the context sensitive menu.

 

I didn't understand how I could extract a "FullFileName" (which is property of Inventor.Document) from a SelectSet object. Assuming the user selects only one item in the assembly, the SelectSet.Item(1) is of type ComponentOccurrence. Kudos to Teun Ham for making it so clear how to get "FullFileName" from a ComponentOccurrence. His post can be found here:

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Getting-Document-from-Occurrence/m-p/1...

 

 

Public Sub FindDocumentByComponentOccurrence()
    Dim oSelectSet As SelectSet
    Set oSelectSet = ThisApplication.ActiveDocument.SelectSet
    
    If oSelectSet.Count = 1 Then
        If TypeOf oSelectSet.Item(1) Is ComponentOccurrence Then
            Dim strPath As String
            strPath = oSelectSet.Item(1).Definition.Document.FullFileName
            
            MyData.SetText strPath
            MyData.PutInClipboard
            
            MsgBox strPath & vbCrLf & vbCrLf & "has been placed in your clipboard. Use Ctrl + V to paste."
        Else
            MsgBox "This is not a ComponentOccurrence. Build case for this type."
        End If
        Exit Sub
    Else
        MsgBox "Select 1 item."
        
        Exit Sub
    End If
End Sub

 

 

0 Likes