Set revision table text to document font

Hi all,

I'm trying to create 1 drawing template that formats itself depending on the process of manufacture, client (logos and unique identifier fields) and sheet size (A3, A2, A1)

I have this working by replacing sheet formats and drafting standards depending on requirements. The template has a rev table, which is set to use document font settings. However, when the sheet size changes, the text size does something interesting which I can fix manually by selecting the table, unselecting use document font, then reselecting it. However I can't VBA code to do this.

Mainly I've been trying 2017 SOLIDWORKS API Help - SetTextFormat Method (ITableAnnotation)

But my novice level of VBA just can't get it to work.

Ideally I'd have this as a sub which I can call when the sheet size has changed.

Your help is greatly appreciated.

SolidworksApi macros
Answers 7
BH
BH 2017-09-18 Best Answer

Ok, so I asked on a Friday afternoon (UK Time) probably not the most productive time in anyones week no matter where in the world you are. But now it's a shiny new week!

Anyone have any thoughts on how I can get my rev table to adjust to the correct settings?

AB
AB 2017-09-18

Can you post your code and how you're trying to do this? I have used the same method with success in updating IAnnotation objects.

<p>TextFormat tf = (TextFormat)swAnno.GetTextFormat(formatIndex);</p><p>(IAnnotation)swAnno.SetTextFormat(formatIndex, true, tf);</p>

The "true" in the SetTextFormat statement checks the "Use Document Font" box for the particular feature.

Perhaps it's in how you're getting your revision table object? You'll have to get the IAnnotation variable associated with it. I feel like the below method may be what you need.

(This is c# syntax but the idea is the same)

RevisionTable revTable = swSheet.RevisionTable;

TableAnnotation table = (TableAnnotation)revTable;

IAnnotation swAnno = table.GetAnnotation();

Then use swAnno to set the document font.

If that doesn't work, show us your code and we may be able to help further.

BH
BH 2017-09-18

thanks for the reply Alex.

My code is in absolute disarray as I've chopped and changed it so often now one line is unlikely to make sense from the next, my mind is in an infinitely worse state.

As I said, I'm a complete novice and have really got this working from other macros I've found on here and stitched it together.

I'm at a loss at converting C# to VBA.

I think I'm going to have to park this for a while. The macro does everything intended and I'm really pleased with it, I'd just really like to polish this dirty little artifact it leaves behind on the rear occasion the sheet size would be changed. All the other settings apply correctly when the drafting standard is applied and I'd have expected the rev table to follow suit.

Thanks for your help.

JC
JC 2017-09-18

Code Converter

use this. convert from vb to c#  and vice versa

BH
BH 2017-09-18

Thanks Jacob,

Looks very helpful. I'll have another crack it this when my frazzled nerves calm down, and I've done enough design work to make up for the time I've spent on this.

AB
AB 2017-09-18

You got my curiosity going on this one so I gave it a go. It looks like you can set the global "Use Document Font" for the table and the value reflects that it changed in the code. However, the toggle on the table doesn't change and neither does any of the fonts within it.

The next check I did was to apply the text format to each cell individually and that worked. I'm not sure if it helps but here's the code.

<p>Dim swDraw As DrawingDoc</p><p>Dim swSheet As Sheet</p><p>Dim revTable As RevisionTableAnnotation</p><p>Dim table As TableAnnotation</p><p>Dim swAnno As Annotation</p><p>Dim tf As TextFormat</p><p></p><p></p><p>Dim boolstatus As Boolean</p><p>Dim boolUseDocTextFormat</p><p>Dim longstatus As Long, longwarnings As Long</p><p></p><p></p><p>Sub main()</p><p></p><p></p><p>Set swApp = Application.SldWorks</p><p>Set swModel = swApp.ActiveDoc</p><p></p><p></p><p>If swModel.GetType = swDocDRAWING Then</p><p>    Set swDraw = swModel</p><p>    Set swSheet = swDraw.GetCurrentSheet</p><p>    Set revTable = swSheet.RevisionTable</p><p>    Set table = revTable</p><p>    </p><p>    'boolUseDocTextFormat = table.GetUseDocTextFormat()</p><p>    'Debug.Print "Before: " & boolUseDocTextFormat</p><p>    </p><p>    Dim Row, Col As Integer</p><p>    For Row = 0 To table.RowCount - 1</p><p>        For Col = 0 To table.ColumnCount - 1</p><p>            Set tf = table.GetCellTextFormat(Row, Col)</p><p>            table.SetCellTextFormat Row, Col, True, tf</p><p>        Next Col</p><p>    Next Row</p><p>    </p><p>    Set tf = table.GetTextFormat()</p><p>    table.SetTextFormat True, tf</p><p>    </p><p>    'boolUseDocTextFormat = table.GetUseDocTextFormat()</p><p>    'Debug.Print "After: " & boolUseDocTextFormat</p><p>    </p><p>End If</p>
BH
BH 2017-09-19

Thanks Alex,

I that works a treat! Very much appreciated!