Try this iLogic code. It might be a bit hard to follow, but it works for similar situations on my end.
I'll try to explain the main points.
This is obviously using the Browser nodes instead of attempting to back-track through however many reference levels there may be to get the part. (The part may have been a sub-part of a sub-assembly of the assembly you shrink wrapped to create this part file.)
The Solid Bodies folder is always the 3rd Node under the TopNode of the Model Browser pane.
The "FullPath" property of a Node is a string that includes every node name from the TopNode, down to the current Node, with colons ":" between each name.
The Split function splits a long String into an array of sub-strings by specifying what character is the "separator".
This process is necessary to separate the levels of the path, and to separate the levels of the assembly names that this part may have been inside of, and so separate the integer at the end.
The Replace function was used to get rid of the file extension of the final part name.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Part Documents.",vbOK, "WRONG DOCUMENT TYPE")
Return
End If
Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
Dim oSBodies As BrowserNode = oPane.TopNode.BrowserNodes.Item(3)
Dim oNode As BrowserNode
Dim oBody As SurfaceBody
Dim oFullPath As String
Dim oPName As String
Dim oIndex As String
Dim oNewName As String
For Each oNode In oSBodies.BrowserNodes
oBody = oNode.NativeObject
oFullPath = oNode.BrowserNodes.Item(1).FullPath
oPName = Split(oFullPath, ":")(Split(oFullPath, ":").Length - 2)
oIndex = Split(oFullPath,":")(Split(oFullPath,":").Length-1)
oNewName = Replace(oPName,".ipt","") & "-" & oIndex
oBody.Name = oNewName
Next
I hope this helps.
If this solves your problem, or answers your questions, please click 'Accept As Solution".
Or, if this helps you reach your goal, please click 'LIKES" 👍.
Also, if you're interested, here are a few of the 'Ideas' I'd like to get implemented.
If you agree with any of them, please vote for them.
- Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
- Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
- Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
- Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
- Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
- SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
- Create DocumentSubTypeEnum Click Here
- Add kRevisionTag or kDrawingRevisionTag to ObjectTypeEnum Click Here
Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield

(Not an Autodesk Employee)