Hello,
is there a way to perform this action (replace Style) in the part document, but by code?
Solved! Go to Solution.
Solved by JelteDeJong. Go to Solution.
i could not find a command for Replacing a text style. But i found a way to delete the style and copy the other. it works like this:
Dim originalStyleName As String = "ReplaceMe" Dim replaceBy As String = "replaceWithMe" Dim doc As PartDocument = ThisDoc.Document Dim def As PartComponentDefinition = doc.ComponentDefinition Dim textStyleOrg As TextStyle = Nothing Dim textStyleNew As TextStyle = Nothing For Each style As TextStyle In doc.TextStyles If (Style.Name = originalStyleName) Then textStyleOrg = Style End If If (Style.Name = replaceBy) Then textStyleNew = Style End If Next textStyleOrg.Delete() textStyleNew.Copy(originalStyleName)
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Hello JelteDeJong,
thanks for your response, unfortunately I can't delete styles which are in use.
This will throw an exception:
textStyleOrg.Delete()
As far as I know there's no way to create a "Standard" like for the drawing styles, and set that new standard as the active one. Then I would be able to delete the old style...
Hello Patrick1323,
I don't know what you want exatly, but could it be a solution to redefine the Style in Style library as you want and then Update the Stile from Style library?
extStyleOrg.UpdateFromGlobal()
Best Regards
Wolfgang
does this work for you:
Dim originalStyleName As String = "Note Text (ANSI) - 3DA" Dim replaceBy As String = "Sketch Text (ANSI) - 3DA" Dim doc As PartDocument = ThisDoc.Document Dim def As PartComponentDefinition = doc.ComponentDefinition Dim textStyleOrg As TextStyle = Nothing Dim textStyleNew As TextStyle = Nothing For Each style As TextStyle In doc.TextStyles If (Style.Name = originalStyleName) Then textStyleOrg = Style End If If (Style.Name = replaceBy) Then textStyleNew = Style End If Next ' in this part all properties from textStyleNew are copyed to textStyleOrg Dim type As Type = GetType(Inventor.TextStyle) For Each prop As Reflection.PropertyInfo In type.GetProperties() If (prop.CanWrite) Then If (prop.Name = "Name" Or prop.Name = "_Name") Then Continue For End If Dim obj = prop.GetValue(textStyleNew) prop.SetValue(textStyleOrg, obj) End If Next ' both styles are now the same.
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com