We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question
0

[BASIC] how to add text in a Draw document?

asked 2021-02-24 08:37:47 +0200

F. Delente gravatar image

Hello,

I have tried adding text to an existing empty Draw document, following the info I found in A. Pytoniak's book on macros, but the text doesn't appear. Here is my code:

REM  *****  BASIC  *****

Function createPoint(ByVal x As Long, ByVal y As Long) As com.sun.star.awt.Point
  dim oPoint
  oPoint = createUnoStruct( "com.sun.star.awt.Point" )
  oPoint.X = x
  oPoint.Y = y
  createPoint = oPoint
End Function

Function createSize(ByVal x As Long, ByVal y As Long) As com.sun.star.awt.Size
  dim oSize
  oSize = createUnoStruct( "com.sun.star.awt.Size" )
  oSize.Width = x : oSize.Height = y
  createSize = oSize
End Function

Sub Main
dim oDoc, page, texte, point
oDoc = ThisComponent
page = oDoc.getDrawPages().getByIndex(0)
page.width = 1485
page.height = 1050
page.borderLeft = 50
page.borderTop = 50
page.borderRight = 50
page.borderBottom = 50

page.orientation = com.sun.star.view.PaperOrientation.LANDSCAPE

texte = oDoc.createInstance("com.sun.star.drawing.TextShape")
'point = createUnoStruct( "com.sun.star.awt.Point" )
'point.X = 10
'point.Y = 5
'rect.position = point
texte.setPosition( createPoint( 50, 50 ) )
texte.setSize( createSize( 1385, 950 ) )
texte.setString("HTH")
texte.string =" 123 "

page.add(texte)


End Sub

Can anybody help or point to other info? Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2021-02-24 16:11:34 +0200

Przemo gravatar image

Move page.add(texte) to the line immediately after you create the TextShape:

texte = oDoc.createInstance("com.sun.star.drawing.TextShape")
page.add(texte)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2021-02-24 08:37:47 +0200

Seen: 45 times

Last updated: Feb 24