Highlight Part or Assembly

Highlight Part or Assembly

GeorgK
Advisor Advisor
855 Views
7 Replies
Message 1 of 8

Highlight Part or Assembly

GeorgK
Advisor
Advisor

Hello together,

 

how could I find a part or product by a given name and highlight it in the browser? For example the filename is Test and the folder is c:\Temp

 

c:\Temp\Test.ipt.

 

Thanks Georg

0 Likes
Accepted solutions (1)
856 Views
7 Replies
Replies (7)
Message 2 of 8

GeorgK
Advisor
Advisor

Does nobody know how to search inside the browser and hihlight the part or iam?

0 Likes
Message 3 of 8

Anonymous
Not applicable
Private Sub Sample()
    Dim oAssyDoc As AssemblyDocument
    Set oAssyDoc = ThisApplication.ActiveDocument
    Dim oOcc As ComponentOccurrence
    Set oOcc = GetFirstOccMatchingName(oAssyDoc, "C:\path\filename.ipt")
    Call oAssyDoc.SelectSet.Select(oOcc)
End Sub

Private Function GetFirstOccMatchingName(oAssyDoc As AssemblyDocument, fullFileName As String) As ComponentOccurrence
    Dim oOcc As ComponentOccurrence
    Dim oDoc As Document
    For Each oOcc In oAssyDoc.ComponentDefinition.Occurrences
        Set oDoc = oOcc.Definition.Document
        If oDoc.FullDocumentName Like fullFileName Then
            Set GetFirstOccMatchingName = oOcc
            Exit Function
        End If
    Next
    MsgBox ("No occurence with that filename!")
End Function

 

0 Likes
Message 4 of 8

GeorgK
Advisor
Advisor

Hello Johan,

 

thank you very much for the code. Is it possible to higlight all matching names and center the browser to the selected part

 

Georg

0 Likes
Message 5 of 8

GeorgK
Advisor
Advisor

To center the browser to the selected part:

 

Dim oControlDef As ControlDefinition
Set oControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("Archon:FindInBrowser")   oControlDef.Execute

0 Likes
Message 6 of 8

Anonymous
Not applicable
Accepted solution
Private Sub Sample()
    Dim oAssyDoc As AssemblyDocument
    Set oAssyDoc = ThisApplication.ActiveDocument
    Dim oOcc As ComponentOccurrence
    'Set oOcc = GetFirstOccMatchingName(oAssyDoc, "C:\path\filename.ipt")
    Dim oOccs As ObjectCollection
    Set oOccs = GetAllOccurencesMatchingFileName(oAssyDoc, "C:\path\filename.ipt")
    Call oAssyDoc.SelectSet.SelectMultiple(oOccs)
End Sub

Private Function GetAllOccurencesMatchingFileName(oAssyDoc As AssemblyDocument, fullFileName As String) As ObjectCollection
    Dim oOccs As ObjectCollection
    Set oOccs = ThisApplication.TransientObjects.CreateObjectCollection()
    Dim oOcc As ComponentOccurrence
    Dim oDoc As Document
    For Each oOcc In oAssyDoc.ComponentDefinition.Occurrences
        Set oDoc = oOcc.Definition.Document
        If oDoc.FullDocumentName Like fullFileName Then
            Call oOccs.Add(oOcc)
        End If
    Next
    Set GetAllOccurencesMatchingFileName = oOccs
End Function

 

Message 7 of 8

GeorgK
Advisor
Advisor

Hello Johan,

 

thank you very much

 

Georg

0 Likes
Message 8 of 8

GeorgK
Advisor
Advisor

Hello Johan,

 

is it possible to change it that it works in a drawing?

 

Thanks again Georg

0 Likes