How to get PartDocument object from mouse selection by vba?

How to get PartDocument object from mouse selection by vba?

Anonymous
Not applicable
1,214 Views
1 Reply
Message 1 of 2

How to get PartDocument object from mouse selection by vba?

Anonymous
Not applicable

I have an active assembly, where I would like to select a part or subassembly by clicking on model (not browser). How can I get PartDocument or AssemblyDocument object from mouse selection?

0 Likes
1,215 Views
1 Reply
Reply (1)
Message 2 of 2

Sergio.D.Suárez
Mentor
Mentor

Hi, here is an example of how to access through VBA. When you select a component in the graphic window or in the navigator tree you will see the name of the file.

 

Sub Select_Component()

    Dim oCC As ComponentOccurrence
    Set oCC = ThisApplication.CommandManager.Pick(16643, "Select Component")
    'kAssemblyLeafOccurrenceFilter 16643 Assembly leaf occurrence filter.
    'kAssemblyOccurrenceFilter 16640 Assembly occurrence filter.
    
    Dim oDoc As Document
    Set oDoc = oCC.Definition.Document
    MsgBox (oDoc.DisplayName)

End Sub

Here the same action with ilogic. 

 

 

Dim oCC As ComponentOccurrence = ThisApplication.CommandManager.Pick(16643, "Select Component")
'kAssemblyLeafOccurrenceFilter 16643 Assembly leaf occurrence filter. 
'kAssemblyOccurrenceFilter 16640 Assembly occurrence filter.

Dim oDoc As Document = oCC.Definition.Document
MessageBox.Show(oDoc.DisplayName)

I hope this helps with your problem. Regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes