Hi @brianmD486F. When I quickly typed that code example up, I knew that only parts have bodies, so I assumed the code should only run when it obtains a part type document. Assemblies do not have any SurfaceBody objects in them, but instead have a collection of assembly components (ComponentOccurrence objects). However, I did do a little additional testing this morning with an assembly as my active document, and did find out that if we set the selection filter to 'Select Body Priority' mode, then that would allow us to select the individual bodies, that are within parts, within the assembly components. And that this selection set would translate OK into the code I created...with a few minor tweaks, such as getting rid of the specific document type filter in the first line, then changing the variable representing the document in a few places.

Here is the modified code example that should be usable from either a part or assembly, as long as you are using that selection filter if in an assembly.
Sub Main
Dim oDoc As Inventor.Document = ThisDoc.Document
Dim oSS As Inventor.SelectSet = oDoc.SelectSet
If oSS.Count = 0 Then Return
Dim iIndex As Integer = 0
Dim sBaseName As String = InputBox("Enter body base name.", "New Body Name", "")
If sBaseName = "" Then Return
For Each oObj In oSS
If TypeOf oObj Is Inventor.SurfaceBody Then
Dim oBody As Inventor.SurfaceBody = oObj
iIndex = iIndex + 1
Dim sIndex As String = iIndex.ToString("00")
oBody.Name = sBaseName & "_" & sIndex
End If
Next oObj
oDoc.Update2(True)
End Sub
The thought also crossed my mind that we could further develop a routine like this so that, if nothing was 'pre-selected', instead of immediately exiting the rule, it would then prompt us to manually 'Pick' a body to rename, and put that 'Pick' action within a loop, to allow the user to keep picking another one until the user exits the loop by not picking anything. The 'Pick' method has its own selection filter that can be applied.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)