FYI: You can set the Part Priority selection preference by code but it just doesn't work with the Pick function.
Dim oDDoc As DrawingDocument = ThisDrawing.Document
oDDoc.SelectionPriority = SelectionPriorityEnum.kPartSelectionPriority
Same for the SelectionPreferences property of the DrawingDocument.
You can set it to select specific type of object, but the Pick function has it's own filter settings, which override these settings.
Dim oDDoc As DrawingDocument = ThisDrawing.Document
oDDoc.SelectionPreferences.Add(ObjectTypeEnum.kPartComponentDefinitionObject)
There are other ways of selecting things though.
Here's a 'somewhat' simple example of the method I mentioned before. This iLogic rule will get the model document being represented within the specified view, then if it is an Assembly, it iterates through all its referenced documents, checking to see if they are Parts, then and adds their FullFileName and PartDocument object (key - value pair) to a Dictionary object for temporary storage. When the loop finishes, it presents you with an InputListBox of the FullFileName's of those Parts. You can select one, then the code gets the corresponding PartDocument. Then I just added a MsgBox at the end to show you the FullFileName of the new PartDocument variable, to show that it worked.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
Return
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = oDDoc.ActiveSheet
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter,"Select a View.")
Dim oParts As New Dictionary(Of String, PartDocument)
If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Dim oADoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPDoc As PartDocument = oRefDoc
If Not oParts.ContainsKey(oRefDoc.FullFileName) Then
oParts.Add(oPDoc.FullFileName, oPDoc)
End If
End If
Next
End If
Dim oPartName As String = InputListBox("Select the part document you want.", oParts.Keys, " ", "PARTS")
'MsgBox("You chose: " & oPartName)
Dim oPartDoc As PartDocument
oParts.TryGetValue(oPartName,oPartDoc) '<<< This line just set the value of the oPartDoc variable
MsgBox(oPartDoc.FullFileName)
Wesley Crihfield

(Not an Autodesk Employee)