Hi @Anonymous,
me again, it would be a useful feature and already requested more than once: 1, 2, ...
I workarounded it making methods to copy styles between two documents, not all the styles yet and the tableStyle is one of those missing to me.
Anyway, if you work with Local style, the methods you need should be something like this:
''' <summary>
''' Copy TextStyle. i.e. set all object's properties with setter.
''' </summary>
''' <remarks>Useful to copy style between different documents</remarks>
Public Sub CopyTextStyles(ByRef replaceStyle As TextStyle, withStyle As TextStyle)
If replaceStyle Is Nothing OrElse withStyle Is Nothing Then
Return
End If
replaceStyle.Bold = withStyle.Bold
replaceStyle.Color = withStyle.Color
replaceStyle.Comments = withStyle.Comments
replaceStyle.Font = withStyle.Font
replaceStyle.FontSize = withStyle.FontSize
replaceStyle.HorizontalJustification = withStyle.HorizontalJustification
replaceStyle.Italic = withStyle.Italic
replaceStyle.LineSpacing = withStyle.LineSpacing
replaceStyle.LineSpacingType = withStyle.LineSpacingType
replaceStyle.Name = withStyle.Name
replaceStyle.Rotation = withStyle.Rotation
replaceStyle.Underline = withStyle.Underline
replaceStyle.VerticalJustification = withStyle.VerticalJustification
replaceStyle.WidthScale = withStyle.WidthScale
End Sub
Public Sub CopyCustomTableStyles(ByRef replaceStyle As TableStyle, withStyle As TableStyle)
Dim replaceStyleManager As DrawingStylesManager = replaceStyle._Parent
' TODO: Copy all CustomTable properties with setter like HeadingPlacement, ...
' For the properties that are theirself a style like DataTextStyle, HeaderTextStyle, ...
' you have to make sure that requested style is defined in this document, if not you have to had it
' Check the existence in this document of the textStyle referenced by withStyle
Dim tsDefined As Boolean = False
For Each textStyle As TextStyle In replaceStyleManager.TextStyles
If textStyle.Name = withStyle.DataTextStyle.Name Then
tsDefined = True
Exit For
End If
Next
If Not tsDefined Then
For Each textStyle As TextStyle In replaceStyleManager.TextStyles
If textStyle.StyleLocation <> StyleLocationEnum.kLibraryStyleLocation Then
' Create textStyle starting from the first non library located textStyle
Dim newts As TextStyle = textStyle.Copy(withStyle.DataTextStyle.Name)
CopyTextStyles(newts, withStyle.DataTextStyle)
Exit For
End If
Next
End If
replaceStyle.DataTextStyle = withStyle.DataTextStyle
end Sub
And call the last one like this:
Dim newTemplateIdw As DrawingDocument = ActiveInventorApplication.Documents.Open(newTemplateIdwPath, False)
Dim curDrwDoc As DrawingDocument = ActiveInventorApplication.ActiveDocument
Dim withSts As TableStyle = newTemplateIdw.StylesManager.TableStyles.Item("tableStyleName")
For Each tableStyle As TableStyle In curDrwDoc.StylesManager.TableStyles
If tableStyle .StyleLocation <> StyleLocationEnum.kLibraryStyleLocation Then
If tableStyle .Name = "tableStyleName"Then
CopyCustomTableStyles(tableStyle , withSts)
Exit For
End If
End If
Next