SelectSet, Part Priority, DrawingView

SelectSet, Part Priority, DrawingView

CadUser46
Collaborator Collaborator
1,325 Views
5 Replies
Message 1 of 6

SelectSet, Part Priority, DrawingView

CadUser46
Collaborator
Collaborator

Can someone show me how to get the part file selected in a drawing assembly view?

 

I want the user to select part priorty, select a part in a view then run macro but im having trouble grabbing the associated part.  If i try to use;

 

If TypeOf oSelectSet.Item(1) Is PartDocument Then

 

or

 

If TypeOf oSelectSet.Item(1) Is PartComponentDefinition Then

 

I get an error.  In these cases is this like a pointer to the part/assembly file?  Should i be looking for a different type?


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Accepted solutions (1)
1,326 Views
5 Replies
Replies (5)
Message 2 of 6

CadUser46
Collaborator
Collaborator

Could anyone demonstrate hwo to interact with a selectset in a drawing view please?

 

I just need to know how to get the part that has been selected and i think i can figure out how to find the associated parent assembly from there.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 3 of 6

rjay75
Collaborator
Collaborator
0 Likes
Message 4 of 6

CadUser46
Collaborator
Collaborator

2012.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 5 of 6

rjay75
Collaborator
Collaborator

Was looking at a different method but found another way.

 

This will give you an occurrence it is one.

 

Dim doc As DrawingDocument = ThisDoc.Document
selSet = ThisDoc.Document.SelectSet
If selSet.Count > 0 Then
	selObj = selSet(1)
	Dim obj As Object
	Dim oView As DrawingView
	If TypeOf(selObj) Is GenericObject Then
		Dim genObj As GenericObject = selObj
		doc.ProcessViewSelection(genObj, oView, obj)
		If Not obj Is Nothing Then
			'Try to see if it's a component occurrence
			occ = TryCast(obj, ComponentOccurrence)
			If Not occ Is Nothing Then
				MessageBox.Show("Occurance Name: " & occ.Name)
			End If
		End If
	End If
End If

 Also see: here and here for more information.

Message 6 of 6

CadUser46
Collaborator
Collaborator
Accepted solution

rjay.  I managed to take your suggestion and with the help of google turn it into what i needed.  I havent included what im doing with the objects now i have them but this will get anyone access to the containing view & the component occurence that is selected within that view.

 

From there you can access the referenced assembly of that view.

 

    'Varibales needed for process the selected component and view.
    Dim oView           As DrawingView
    Dim oSelectedObj    As Object
    Dim oGenObj         As GenericObject
    'Varibles needed for the referenced assembly document
    Dim oRefAssy        As AssemblyDocument
    Dim oRefAssyOcc     As ComponentOccurrence
    Dim i               As Integer
    Dim Response        As VbMsgBoxResult

    'Get a hook to the document.
    Dim oDoc As Inventor.DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    'Test to see if its a drawing.
    If oDoc.DocumentType <> kDrawingDocumentObject Then
        Exit Sub
    End If
    
    'Test to see the user has activated part priority.
    If oDoc.SelectionPriority <> kPartSelectionPriority Then
        MsgBox "You must select PartPriority.", vbInformation
        Exit Sub
    End If
    
    'Test to see if the user has selected a component occurrence.  This is a weak test as it cant be known if its a componentoccurrence
    'until after the view is processed.  If they select anything other than a assembly's child part it will error.
    If oDoc.SelectSet.Count <> 0 Then
            On Error GoTo NotAComponentOcc:
            Set oGenObj = oDoc.SelectSet(1)
            Call oDoc.ProcessViewSelection(oGenObj, oView, oSelectedObj)
            'Reset error trapping
            On Error GoTo 0
    End If
    
    'Find reference assembly file.
    On Error GoTo NothingSelected:
    Set oRefAssy = oView.ReferencedDocumentDescriptor.ReferencedDocument
    'Reset error trapping
    On Error GoTo 0

 


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes