Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Find Part in browser - drawing

8 REPLIES 8
Reply
Message 1 of 9
GeorgK
1267 Views, 8 Replies

Find Part in browser - drawing

Hello together,

 

how could I find a part with a given name in the browser of a drawing?

 

Thanky you very much

 

Georg

8 REPLIES 8
Message 2 of 9
wayne.brill
in reply to: GeorgK

He Georg,

 

Below is some VBA code that prints out names of parts in the browser. (most of this is from an example in the API Help). You could add an If statement to get the part you wanted. This may not do exactly what you want but it should show how to get to objects from the browser nodes.

 

Also there are other ways to get the parts and assemblies that are being used by a drawing. (The  DrawingView.ReferencedDocumentDescriptor for example)

 

 

 

Private Sub QueryModelTree()
    Dim Doc As Document
   
    If (ThisApplication.Documents.count <> 0) Then
        Set Doc = ThisApplication.ActiveDocument
    Else
        MsgBox "There are no open documents!"
        Exit Sub
    End If

    Dim oTopNode As BrowserNode
    Set oTopNode = Doc.BrowserPanes("Model").TopNode
   
  
Call recurse(oTopNode)
End Sub

Sub recurse(node As BrowserNode)
    If (node.Visible = True) Then
       ' Debug.Print node.BrowserNodeDefinition.Label
       
        Dim oNativeObj As Object
        Set oNativeObj = node.NativeObject
       
       ' Debug.Print TypeName(oNativeObj)
        Dim oDoc As Document
        Dim oAsmCompDef As AssemblyComponentDefinition
        Dim oCompOcc As ComponentOccurrence
        Dim oCompOccproxy As ComponentOccurrenceProxy
        
        If TypeName(oNativeObj) = "AssemblyComponentDefinition" Then
            Set oAsmCompDef = node.NativeObject
            Set oDoc = oAsmCompDef.Document
            Debug.Print oDoc.DisplayName
       End If
       
        If TypeName(oNativeObj) = "ComponentOccurrence" Then
            Set oCompOcc = node.NativeObject
            Set oDoc = oCompOcc.Definition.Document
       

            Debug.Print oDoc.DisplayName
       End If
       
        If TypeName(oNativeObj) = "ComponentOccurrenceProxy" Then
            Set oCompOccproxy = node.NativeObject
            Debug.Print oCompOccproxy.name
          

            Set oDoc = oCompOccproxy.NativeObject.Definition.Document
            Debug.Print oDoc.DisplayName
       End If
        
        
        
        Dim bn As BrowserNode
        For Each bn In node.BrowserNodes
            Call recurse(bn)
        Next
    End If
End Sub

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 3 of 9
GeorgK
in reply to: wayne.brill

Hello Wayne,

 

thanks for the code. But thats not what I am looking for.

 

Georg

Message 4 of 9
wayne.brill
in reply to: GeorgK

Hi Georg,

 

Please add more detail to what you are trying to do. It may help to attach a drawing and the parts it is using.

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 5 of 9
GeorgK
in reply to: wayne.brill

Hello Wayne,

 

how could I select the part in the browser and expand it? I know the name from the part already.

 

Thank you

 

Georg

Message 6 of 9
GeorgK
in reply to: GeorgK

I found a sample:

http://adndevblog.typepad.com/manufacturing/2012/09/parse-browsernodes-for-a-specified-node-and-perf...

But how could I get the full name of a selected part inluding the view etc.?
Set oBrowserNode = GetBrowserNodeByFullPath("Assembly1:Sheet:1:VIEW1:Assembly1.iam:Assembl
Message 7 of 9
wayne.brill
in reply to: GeorgK

Hi,

 

How is the Part selected? Are you asking the user to select the part? I am asking this because from what I can determine a drawing curve needs to be selected in the view to be able to get the document. (to get the parts name). If your code is prompting the user to select a part in a view you could use a filter so the user can only select a drawing curve. (kDrawingCurveSegmentFilter) See this example in the help on how to create a select event in VBA. (Sub TestSelection)

 

When a Part is selected in a drawing view the selected object in the SelectSet is a GenericObject . (you can see this in the VBA Watch window) The GenericObject does not provide any properties to get information from the API.

 

 

Here is a VBA example that is just showing what part of the API I am suggesting to get to the document. If an edge (not an edge of a face) of a part in a view is selected a MsgBox will display the document name and view name. (this example could be updated to handle ModelGeometry returning a face)

 

Public Sub SelSetTest3()
 
     Dim oDrwCrvSeg As Object
    Set oDrwCrvSeg = ThisApplication.ActiveDocument.SelectSet(1)
 
 If Not oDrwCrvSeg Is Nothing Then
 
      Dim oDrwCrv As DrawingCurve
      Set oDrwCrv = oDrwCrvSeg.Parent
     
      Dim oEdge As Edge
      Set oEdge = oDrwCrv.ModelGeometry
           
      Dim oSrfBody As SurfaceBody
      Set oSrfBody = oEdge.Parent
     
      Dim oCompDef As ComponentDefinition
      Set oCompDef = oSrfBody.ComponentDefinition
     
      Dim oDoc As Document
      Set oDoc = oCompDef.Document
     
      MsgBox oDoc.FullFileName
    
      Dim oDrwView As DrawingView
      Set oDrwView = oDrwCrv.Parent

      MsgBox oDrwView.Name

    End If

End Sub

 

 

 

Thanks,

Wayne

 

 

 

 

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 8 of 9
GeorgK
in reply to: wayne.brill

Hello Wayne,

thank you very much for your help. But how could I bring the code together? I could not get the part selected in the browser.

Georg

Message 9 of 9
wayne.brill
in reply to: GeorgK

Hi Everyone,

 

This DevBlog post has a VB.NET example

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report