My guess is that this fails because you are using a macro to create a draw page in a Draw document, but you are running the macro in a Write document. A write document contains only one draw page, not multiple draw pages. In other words, you can not create a new draw page in a Write document (I should verify this, but I believe it to be true).

Senthilkumar Mehalingam wrote:

Hi All,

Thanks Andrew for your reply.

I am trying to create a macro which like MS Word's draw table for the Draw application allows the user to specify the number of shapes and then creates them. Just as Word's draw wizard asks for number of rows and columns I want to ask for number of shapes and their hierarchy(say 1 root and two children) and creating them accordingly. I looked at DannysDrawPowerTools-2003-08-09.01 and Andrew's book on OO macros and got a lot of help and this is what I managed to do using both of them but am still having problems I cannot comprehend and would appreciate any assistance. After I click the Create button in the dialog I get an error in createDrawPages function

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Private oDialog As Object


Sub StarPolyDialog()
Copyright (c) 2003 Danny Brewer
' Make sure this library, with its dialog is loaded which I checked
DialogLibraries.LoadLibrary( "Standard" )
REM I loaded the libraries and created a Dialog box of name ShapeDlg 'having a REMnumeric 'field Count in it. I assgned the macro Sub btnCreateStarOrPoly_Clicked to REMbe assigned to the create button when it is clicked but inspite of the fact the REM rectangels are not created. I traced the running step by step by the Single Step but REM am not able to trace the error
' Create the dialog object.
oDialog = createUnoDialog( DialogLibraries.GetByName( "Standard" ).GetByName( "ShapeDlg" ) )

' Display the dialog.
' This routine call does not return until the dialog is dismissed.
oDialog.Execute()

' Execution does not reach this point until the dialog is dismissed.
End Sub





' This is called when the user clicks the Create button on the dialog box.
Sub btnCreateStarOrPoly_Clicked

' Get the values of the controls in the dialog box.
'
nNumSides = oDialog.getControl( "Count" ).getValue()


' and pass it to the Builder function

Builder( nNumSides)
End Sub


Sub Builder( num )
' Make sure the TurtleGraphics library of modules is loaded. which I did.
BasicLibraries.LoadLibrary( "TurtleGraphics" )

drawFirstGraphic(num)
End Sub

Sub drawFirstGraphic(num)
Dim oPage 'Page on which to draw
Dim oShape 'Shape to insert
Dim oPoint 'Initial start point of the line
Dim oSize 'Width and height of the line
Dim i% 'Index variable
Dim n% 'Number of iterations to perform
oPage = createDrawPage(ThisComponent, "new Test Draw", True) ' create a new Drawing pag
n = num
' and try to create Rectangles in it
For i = 0 To n
oShape = ThisComponent.createInstance("com.sun.star.drawing.RectangleShape")
oPage.add(oShape)
oShape.setPosition(createPoint(1000,1000))
oShape.setSize(createSize(4000, 1000))
oShape.setString("box 1")
oShape.Shadow = True
oShape = ThisComponent.createInstance("com.sun.star.drawing.RectangleShape")
oPage.add(oShape)
oShape.setPosition(createPoint(6000, 1000))
oShape.setSize(createSize(4000, 1000))
oShape.setString("box 2")
oShape.Shadow = True
oShape.ShadowXDistance = -150
oShape.CornerRadius = 100
Next i
End Sub





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



Function createDrawPage(oDoc, sName$, bForceNew As boolean) As Variant
Dim oPages 'All of the draw pages
Dim oPage 'A single draw page
Dim i% 'General index variable
oPages = oDoc.getDrawPages()
If oPages.hasByName(sName) Then
REM If we require a new page then delete
REM the page and get out of the for loop.
If bForceNew Then
oPages.remove(oPages.getByName(sName))
Else
REM Did not request a new page so return the found page
REM and then get out of the function.
createDrawPage = oPages.getByName(sName)
Exit Function
End If
End If
REM Did not find the page, or found the page and removed it.
REM Create a new page, set the name, and return the page.
oPages.insertNewByIndex(oPages.getCount())
oPage = oPages.getByIndex(oPages.getCount()-1)
oPage.setName(sName)
createDrawPage = oPage
End Function




///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Thanks a lot.

From: Andrew Douglas Pitonyak <[EMAIL PROTECTED]>
Reply-To: dev@api.openoffice.org
To: dev@api.openoffice.org
CC: Senthilkumar Mehalingam <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
Subject: Re: [api-dev] Re: newbie drawing question
Date: Wed, 11 May 2005 22:34:25 -0400

Yes, if you want to draw a line, you create a line object and then add it to the document. The Draw and Impress chapters of my book are available as a free download, and it contains numerous examples of shapes and lines and such.

Jürgen Schmidt wrote:

Hi Senthil,

no your understanding is wrong, when using the OOo API you work more or less directly on documents of the different application areas. If you want to draw lines, circles and other stuff directly in a canvas you have to use Java APIs directly.

Juergen

Senthilkumar Mehalingam wrote:

Hi Juergen,

Thanks for the reply. I have now subscribed to the mailing list [EMAIL PROTECTED]

I took a look at the SDK examples(http://api.openoffice.org/docs/DevelopersGuide/Drawing/Drawing.htm and in that 9.3.2 Shapes) but they I presume are for drawing/adding shapes on a document, not for drawing lines, circles and stuff directly on a canvas(and I am trying to find how to draw lines, ovals, rectangles, arrows and text boxes using a Java API for the drawing(or presentation) tool so I think I will be doing on a canvas if I am using the drawing tool).

Can you please let me know if my understanding is correct or not?

Thanks a lot.

Sincerely
Senthil

P.S. My apologies if this is a very elementary question for this group.


From: Jürgen Schmidt <[EMAIL PROTECTED]>
To: Senthilkumar Mehalingam <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED], [EMAIL PROTECTED]
Subject: Re: newbie drawing question
Date: Mon, 09 May 2005 09:41:58 +0200

Hi,

do you have subscribed to the mailing list? If no, please subscibe to the mailing list and ask your question on the mailing list. This has the advantage that you will get faster an answer when for example people you have contacted directly are not available.
To your question:
Please take a look to the SDK examples (<sdk>/examples/DevelopersGuide/Drawing), they show the use of the API to draw shapes and other graphic objects.

I hope this helps

Juergen

Senthilkumar Mehalingam wrote:

Hi All,

I am a beginner to OpenOffice.org.

I am trying to make it possible by the user to insert structures
like MS Office's  organisation chart  in the Drawing and
Presentation documents so as to make drawing such structures in OO a
command rather than the user manually trying to do it

I am trying to implement functionality by which a user can choose
the number and
shapes(say 3 rectangles) and their hierarchy. One on top as parent
having two children.  Just as MS Office has an organisation chart I
want to know how the wizard(I presume there is a wizard in Office to
create an Organisation Chart.  I want to see how the steps work in
creaing the chart to get ideas for how to build a graphic of a graph
or tree).

Can anybody please suggest me the correct direction and the correct
method to do this.

Thanks a lot



Sincerely
Senthil

P.S. My apologies for posting again but I sent this on May 4 and did not see it in the mailing list till today May 7.




--
Juergen Schmidt, Technical Lead Software Engineering
                 OpenOffice.org/StarOffice SDK
_______________________________________________________
Sun Microsystems GmbH         [EMAIL PROTECTED]
Sachsenfeld 4, 20097 Hamburg  http://sun.com/staroffice
Germany +49/40 23646-984      http://api.openoffice.org







--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.sxw
My Macro Book: http://www.hentzenwerke.com/catalog/oome.htm
Free Info:  http://www.pitonyak.org/oo.php


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.sxw
My Macro Book: http://www.hentzenwerke.com/catalog/oome.htm
Free Info:  http://www.pitonyak.org/oo.php


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to