Hi @Darkforce_the_ilogic_guy. I tend to agree that there does not appear to be a 'one size fits all' type of Inventor API routine that can magically fix all possible 'style' related issues by code. It seems like we still can not do everything that we can do manually, within that Styles & Standards dialog, by code yet.
I also have a pesky style like that in one of my drawing templates that exists in both places, and seems like it will never fully update properly, so that both are in sync with each other, for some reason. I have read lots of posts about this issue over the years, and have tried lots of things in my attempts to eliminate that message about it, but it just seems like nothing I do works. All sheet formats have been deleted. All sketch symbol definitions have been deleted. All border definitions except the 'main' one have been deleted. All title block definitions have been deleted except the 'main' one. I had those only two remaining border/title block definition sketches open/active while performing the global 'update from style library' actions, and have done those update steps outside of those sketches. When using the main 'Purge' tool in the Manage tab > Styles & Standards panel, there is nothing in the list to purge. Still that one style remains in the list every time when using that main Update tool in that same panel. There are only two 'Standard' styles that are considered 'local' within the Styles & Standards editor dialog, and the one that is not 'active' will not allow me to 'purge' it, even though as far as I can determine, I can not find anything in this entire document that is 'dependent' on it or 'using' it. Even some of the 'local' styles that only exist within that 'non-active' standard style, will not allow me the option to purge them, for some reason.
However, I will still share an example code below that sounds like it is at least trying to do the process you described in your original post here. It will only run when a drawing is active. It then attempts to find an existing TextStyle named "text" (to be renamed, and replaced), and one named "Text" (to replace the other one with). If it can not find either one, it will write something to the iLogic Log window about it, then exit the rule. It will then try to rename the TextStyle named "text" to "text_", and if that fails, it will also report it, then exit the rule. It will the try to replace the TextStyle named "text_" with the TextStyle named "Text". If that works, it will then try to update the drawing. I have not tested this rule yet myself, because I do not want to mess with any of my TextStyles.
Sub Main
Dim oInvApp As Inventor.Application = ThisApplication
Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
If oDDoc Is Nothing Then Return
Dim oDSMgr As DrawingStylesManager = oDDoc.StylesManager
Dim oTSs As TextStylesEnumerator = oDSMgr.TextStyles
Dim sOrigTS_Name As String = "text"
Dim sRenameTo As String = "text_"
Dim sReplacementTS_Name As String = "Text"
Dim oOrigTS, oReplacementTS As TextStyle
Try : oOrigTS = oTSs.Item(sOrigTS_Name) : Catch : End Try
If oOrigTS Is Nothing Then
Logger.Debug("Could not find existing TextStye named " & sOrigTS_Name)
Return
End If
Try : oReplacementTS = oTSs.Item(sReplacementTS_Name) : Catch : End Try
If oReplacementTS Is Nothing Then
Logger.Debug("Could not find existing TextStye named " & sReplacementTS_Name)
Return
End If
Try
oOrigTS.Name = sRenameTo
Logger.Info("Renamed TextStyle '" & sOrigTS_Name & " to '" & sRenameTo & "'.")
Catch
Logger.Error("Error renaming TextStyle '" & sOrigTS_Name & " to '" & sRenameTo & "'!")
Return
End Try
Dim oToBeReplaced As ObjectCollection = oInvApp.TransientObjects.CreateObjectCollection
oToBeReplaced.Add(oOrigTS)
Try
oDSMgr.ReplaceStyles(oToBeReplaced, oReplacementTS, PurgeReplacedStyles = True)
Catch
Logger.Error("Error replacing TextStyle '" & sRenameTo & " with '" & sReplacementTS_Name & "'!")
Return
End Try
oDDoc.Update2(True)
'oDDoc.Save()
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)