Hi @m_andrzejuk3FA7M. Your request sound pretty different from the earlier requests in this forum topic, so I am posting a pretty different code example for accomplishing it. You also did not provide much information or details about this task, so I can only assume that what names are used and how those names are formatted does not matter. You also did not mention any patterns, so this code example does not even attempt to target those separately.
The example code below can be ran from either a part or assembly, and will not only work directly on that main document, but also on all documents being referenced by that main document, at all levels of depth. This code does avoid errors pretty well, but while doing so, does not provide any feedback about when it encounters any of those issues, or any explanation about why there was an issue. It could be expanded and developed further to add more checks, more feedback, and/or more functionality. Some referenced documents it encounters along the way may be seen as ReadOnly, and when that is the case, it will not be able to make any changes to those. Some of the ones that may be seen that way are content center members, files located in library directories, iPart/iAssembly members, and ModelState members. The 'base name' for the new name of each WorkPlane can be changed on Line 21 & Line 26.
Sub Main
Dim oDoc As Inventor.Document = ThisDoc.Document
RenameAllWorkPlanes(oDoc)
For Each oRefDoc As Inventor.Document In oDoc.AllReferencedDocuments
RenameAllWorkPlanes(oRefDoc)
Next oRefDoc
oDoc.Update2(True)
'oDoc.Save2(True)
End Sub
Sub RenameAllWorkPlanes(oDoc As Inventor.Document)
If (oDoc Is Nothing) OrElse (Not oDoc.IsModifiable) OrElse
((Not TypeOf oDoc Is PartDocument) AndAlso
(Not TypeOf oDoc Is PartDocument)) Then
Return
End If
If oDoc.RequiresUpdate Then oDoc.Update2(True)
Dim oWPs As WorkPlanes = Nothing
Try : oWPs = oDoc.ComponentDefinition.WorkPlanes : Catch : End Try
If oWPs Is Nothing Then Return
Dim sBaseName As String = "WP"
Dim iNum1 As Integer = 0 : Dim iNum2 As Integer = 0
For Each oWP As WorkPlane In oWPs
If oWP.IsCoordinateSystemElement Then
iNum1 += 1
Try : oWP.Name = "Origin" & sBaseName & iNum1.ToString : Catch : End Try
Else
iNum2 += 1
Try : oWP.Name = sBaseName & iNum2.ToString : Catch : End Try
End If
Next oWP
If oDoc.RequiresUpdate Then oDoc.Update2(True)
End Sub
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)