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: 

Rename Browser nodes from an Assembly and all Parts

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
j_weber1
4145 Views, 5 Replies

Rename Browser nodes from an Assembly and all Parts

Hallo everybody,

last time i found a small iLogic-Code to rename the Display Name of an Inventor-Part

 

oDoc = ThisApplication.ActiveDocument
oDoc.DisplayName = iProperties.Value("Project", "Part Number") &  " - " & iProperties.Value("Project", "Description")
MessageBox.Show("Displayname = " & oDoc.DisplayName, "iLogic")

 

now it would be nice to do this from a top of an assembly for all instances of the assembly.

I found same codes for other ilogics, but i'm not a profi about ilogic.

 

So here is my question. Is it possible to change all display names from components of an assembly and the display name of the assembly.

 

I know there are other posts in the community, but i didn't find an answer

 

Jörg




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





5 REPLIES 5
Message 2 of 6
ekinsb
in reply to: j_weber1

Here's a small VBA macro that should do what you want.

 

Public Sub ChangeDisplayName()
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.ActiveDocument
    
    ' Change the name for the assembly.
    asmDoc.DisplayName = BuildName(asmDoc)
    
    ' Change the name in every referenced document.
    Dim doc As Document
    For Each doc In asmDoc.AllReferencedDocuments
        doc.DisplayName = BuildName(doc)
    Next
End Sub

Private Function BuildName(doc As Document) As String
    Dim name As String
    Dim designTrackProps As PropertySet
    Set designTrackProps = doc.PropertySets.Item("Design Tracking Properties")
    
    name = designTrackProps.Item("Part Number").Value & " - " & _
           designTrackProps.Item("Description").Value
           
    BuildName = name
End Function

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 6
wayne.brill
in reply to: j_weber1

Hi,

 

Yes this should be possible. I am not finding a complete example that does what you want to do however.

 

The VBA procedure QueryModelTree() in the help file iterates through the browser model tree of an open part or assembly document, printing the node labels to the VBA debug screen (the "Immediate" window in VBA, if enabled).

Your code would need to do something similar. When it finds a node that you want to rename you would have to get the native object and change the DisplayName or name property for proxies. You can't just change the label.

 

This is from from the API help:

>> >>

BrowserNodeDefinition Object
Label
Property that gets the label of the BrowserNode. This is the string that is displayed to the user. In the case of BuiltIns, this Label is really a reflection of the corresponding name held by the underlying data - for example, a Sketch or a WorkPlane object. In order to set the Label of a ClientBrowserNodeDefinition, see SetLabel on that object.
<< <<

 

 

I tried a quick example. Here is a VBA code snippet. This is just to show what objects in the API you could use to get the native object that needs to change the display. (recurse is part of the QueryModelTree() VBA example in the help) 

 

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
            oDoc.DisplayName = "WB"
        End If

       

        If TypeName(oNativeObj) = "ComponentOccurrenceProxy" Then
            Set oCompOccproxy = node.NativeObject
            oCompOccproxy.name = "WB_Test"
        End If

 

Once you have the VBA code working you can move it to .NET and then to iLogic. This is what I usually do. Prototyping in VBA is a way to quickly get things working. Pasting VBA code to a VB.NET module removes the Set statements and gets you closer to what iLogic will want the code to be. (iLogic rules can run VB.NET code).

 

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 4 of 6
j_weber1
in reply to: wayne.brill

Thanks for your answers.

I will try it out.

 

Best wishes

 

Jörg




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





Message 5 of 6

This worked for me, was looking everywhere, and managed to splice this together

 

Dim asmDoc As AssemblyDocument = ThisDoc.Document
Dim childDoc As Document

For Each childDoc In asmDoc.AllReferencedDocuments
Try
childDoc.DisplayName = childDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value

Catch
End Try
Next

Message 6 of 6
sun069099
in reply to: ekinsb

可以幫忙
為什麼無法改成
name = designTrackProps.Item("Part Number").Value & " - " & _
designTrackProps.Item("Summary", "Title").Value
是哪裡錯了呢?

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

Post to forums  

Autodesk Design & Make Report