cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

VB API how to set the text font / text style in a table using vb api.

SteveMartel
7-Bedrock

VB API how to set the text font / text style in a table using vb api.

Hi All,

 

I have a VB program who does connect to creo and modify an existing table.

The problem is that it does not use the text font already set in the table.

My font is set to a TTF font "consolas" and height set to 0.09375"

when the program run it change the height to 0.15625" I dont get why!!!!

 

here is a breif section of the code.

Dim drwTableCell As IpfcTableCell 'ICpfcTableCell

Dim drwTable As IpfcTable = Nothing

Dim cellTxt As String

Dim lines As New Cstringseq

Dim drawing As IpfcDrawing

Dim drwTables As IpfcTables

Dim i As Integer

Dim asyncConnection As IpfcAsyncConnection = Nothing

Dim connSession As IpfcBaseSession

Dim model As IpfcModel

 

Try

'**** Connexion en cours

asyncConnection = (New CCpfcAsyncConnection).Connect(Nothing, Nothing, Nothing, Nothing)

model = asyncConnection.Session.CurrentModel

If model Is Nothing Then

Throw New Exception("Pas de modele")

End If

connSession = asyncConnection.Session

'**** recuperer l'extension

exten = Mid(model.FileName, Len(model.FileName) - 2, 3)

If exten <> "drw" Then

Throw New Exception("Modele doit être un dessin")

End If

drawing = model

drwTables = drawing.ListTables()

'**** trouver la table des révisions ID9

For i = 0 To drwTables.Count - 1

drwTable = drwTables(i)

tblName = drwTable.id.ToString

If tblName = "9" Then Exit For

Next

 

cellTxt = "some text"

drwTableCell = (New CCpfcTableCell).Create(2, 1)

lines.Insert(0, cellTxt)

drwTable.SetText(drwTableCell, lines)

Catch ex As Exception

MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)

End Try

 

Thanks for any help


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
ACCEPTED SOLUTION

Accepted Solutions

Hi To all, here is the solution.

Basically the problem was that the text properties are innherited from the drawing template.

So I have created a function to edit drawing table cell

here is the code to edit the drawing table cell:

Public Function setText(CelText As String)

'note that drwTable, drwTableCell & model are declare as public earlier

Dim noteInstructions As IpfcDetailNoteInstructions

Dim lines As New Cstringseq

Dim iText1 As New CCpfcDetailText

Dim itext As IpfcDetailText

Dim selItem1 As IpfcModelItem

Dim NoteIt As IpfcDetailNoteItem

Dim texts1 As CpfcDetailTexts

Dim textLine1 As IpfcDetailTextLine

Dim textLines1 As CpfcDetailTextLines

Dim DDraw As IpfcModel2D

'

lines.Insert(0, CelText)

drwTable.SetText(drwTableCell, lines)

selItem1 = drwTable.GetCellNote(drwTableCell)

NoteIt = DirectCast(selItem1, IpfcDetailNoteItem)

noteInstructions = NoteIt.GetInstructions(True)

textLines1 = New CpfcDetailTextLines

itext = (New CCpfcDetailText).Create(CelText)

itext.TextHeight = 5.0R

texts1 = New CpfcDetailTexts

texts1.Insert(0, itext)

textLine1 = (New CCpfcDetailTextLine).Create(texts1)

textLines1.Insert(0, textLine1)

noteInstructions.TextLines = textLines1

NoteIt.Modify(noteInstructions)

lines.Clear()

DDraw = model

DDraw.Regenerate()

Return Nothing

End Function

View solution in original post

1 REPLY 1

Hi To all, here is the solution.

Basically the problem was that the text properties are innherited from the drawing template.

So I have created a function to edit drawing table cell

here is the code to edit the drawing table cell:

Public Function setText(CelText As String)

'note that drwTable, drwTableCell & model are declare as public earlier

Dim noteInstructions As IpfcDetailNoteInstructions

Dim lines As New Cstringseq

Dim iText1 As New CCpfcDetailText

Dim itext As IpfcDetailText

Dim selItem1 As IpfcModelItem

Dim NoteIt As IpfcDetailNoteItem

Dim texts1 As CpfcDetailTexts

Dim textLine1 As IpfcDetailTextLine

Dim textLines1 As CpfcDetailTextLines

Dim DDraw As IpfcModel2D

'

lines.Insert(0, CelText)

drwTable.SetText(drwTableCell, lines)

selItem1 = drwTable.GetCellNote(drwTableCell)

NoteIt = DirectCast(selItem1, IpfcDetailNoteItem)

noteInstructions = NoteIt.GetInstructions(True)

textLines1 = New CpfcDetailTextLines

itext = (New CCpfcDetailText).Create(CelText)

itext.TextHeight = 5.0R

texts1 = New CpfcDetailTexts

texts1.Insert(0, itext)

textLine1 = (New CCpfcDetailTextLine).Create(texts1)

textLines1.Insert(0, textLine1)

noteInstructions.TextLines = textLines1

NoteIt.Modify(noteInstructions)

lines.Clear()

DDraw = model

DDraw.Regenerate()

Return Nothing

End Function

Announcements


Top Tags