Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table properties

Status
Not open for further replies.

Alan Lowbands

Aerospace
May 17, 2017
274
GB
Hi,
Does anyone know of a way to alter the text size and text position of a table using a script.
I'm doing some BOMS from csv files and wanted to get them all the same size etc'
I have found a way to size the column width but can't change the text size and text position in each cell.
Looked online but nothing I have found seems to work.
Any pointers would be appreciated
the code I have up to now is below..

thanks
Alan

--------------------------------------------------------------
Sub CATMain()

Set Document = CATIA.ActiveDocument

Dim selection1
Set selection1 = Document.Selection

Set Info = selection1.Item(1)

Dim MyTable
Set MyTable = Info.Value

'---------------------------------------------
Dim selection2
Dim oText1
Set selection2 = Document.Selection
Set Info2 = selection2.Item(1)
Set oText = Info2.Value
oText.SetFontSize 0, 0,3.5

'--BOM A0 sheet-
iCol = 1
iColSize = 45.5
MyTable.SetColumnSize iCol, iColSize
iCol = 2
iColSize = 45.5
MyTable.SetColumnSize iCol, iColSize
iCol = 3
iColSize = 45.5
MyTable.SetColumnSize iCol, iColSize
iCol = 4
iColSize = 45.5
MyTable.SetColumnSize iCol, iColSize
iCol = 5
iColSize = 265
MyTable.SetColumnSize iCol, iColSize
iCol = 6
iColSize = 86
MyTable.SetColumnSize iCol, iColSize
iCol = 7
iColSize = 156
MyTable.SetColumnSize iCol, iColSize
iCol = 8
iColSize = 200
MyTable.SetColumnSize iCol, iColSize
iCol = 9
iColSize = 80
MyTable.SetColumnSize iCol, iColSize
iCol = 10
iColSize = 190
MyTable.SetColumnSize iCol, iColSize


End Sub

 
Replies continue below

Recommended for you

Here are some code snips that should help.

In this section we go through the table cells one by one, setting the value from the Excel file. (there are 7 columns in my application, 3 shown here for enough clarity...I think you already have that part working enough?).
Code:
For n = 1 To (oDrawingTable.NumberOfRows - 1)
        
        ItemNo = n 'Set the Item Number for ballooning
        Call oDrawingTable.SetCellString(n, 1, ItemNo) 'Item Number for Balloon
            Call Dressup_Table(oDrawingTable, n, 1, 1, 0)
        Call oDrawingTable.SetCellString(n, 2, CStr(XLSheet.Cells(n + 4, 2))) 'Quantity
            Call Dressup_Table(oDrawingTable, n, 2, 1, 0)
        Call oDrawingTable.SetCellString(n, 3, CStr(XLSheet.Cells(n + 4, 3))) 'Part Number
            Call Dressup_Table(oDrawingTable, n, 3, 2, 0)

........

Then this is the subroutine to set the font size, justification, and text properties. I think this is mainly what you need at the moment, so I'll copy it in full.

Code:
Sub Dressup_Table(current_table As DrawingTable, ByVal line_number As Integer, ByVal column_number As Integer, ByVal type_justification As Integer, ByVal Bold As Integer)

'-------------------------------
' sort out the justification
'-------------------------------
'
    If type_justification = 1 Then
        current_table.SetCellAlignment line_number, column_number, CatTableMiddleCenter
    ElseIf type_justification = 2 Then
        current_table.SetCellAlignment line_number, column_number, CatTableMiddleLeft
    ElseIf type_justification = 3 Then
        current_table.SetCellAlignment line_number, column_number, CatTableMiddleRight
    End If
'
'--------------------------------------
' get the current text
'--------------------------------------
'
    Dim current_text As DrawingText
    Set current_text = current_table.GetCellObject(line_number, column_number)
'
'------------------------------------
' set up the current text
'------------------------------------
'
    Dim oText As Integer
    oText = Len(current_text.Text)
'
' Font Arial
'
    current_text.SetFontName 1, oText, "Arial (TrueType)"
'
' font height
'
    current_text.SetFontSize 1, oText, 1.5
'
' graphical attributes
'
    current_text.SetParameterOnSubString catBold, 1, oText, Bold
    current_text.SetParameterOnSubString catUnderline, 1, oText, 0
    current_text.SetParameterOnSubString catItalic, 1, oText, 0
    current_text.SetParameterOnSubString catItalic, 1, oText, 0
    current_text.SetParameterOnSubString catOverline, 1, oText, 0
'
End Sub

Unfortunately, this was all so long ago, I don't remember every detail of how it works (!), but I think it should help you on your way.

Mark
 
Thanks for the reply.
I have had a play with it but couldn't get it to work.
Could it be that i'm running it as a script and not a macro ?
It's weird how what you think would be a simple thing to do can be a nightmere

cheers
Alan
 
There are syntax differences between CATScript / VBScript languages, and CATVBA language (which is what my example is using), such that the code does not directly copy over. What is not in the code snips is all the declarations and the rest of the context of the code; the intent is only that this should give some clues and direction. It certainly won't run anywhere as-is.
In reviewing this, one thing I noted here is that the position and justification of the text in the table cell is controlled via the table, and I'm setting it cell by cell.
The other thing I noted is that the commands to set font type and size etc. need a position (number) input for starting and ending the property application. That's where to apply (eg. font size) to the whole text, it is applied from (1) to (length) of the text.
 
Thanks for the help.
I'm going to have to spend some time on this as i've only just got back to try and learn macro programming.
Spent some time last year but only had chance to play with macros again the last couple of weeks.
every bit of help is always appreciated :)

Alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top