OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Dividing rectangle into equally spaced vertical columns ??

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Draw
View previous topic :: View next topic  
Author Message
diggertoo
General User
General User


Joined: 16 Mar 2004
Posts: 12

PostPosted: Tue Mar 16, 2004 8:42 pm    Post subject: Dividing rectangle into equally spaced vertical columns ?? Reply with quote

I am trying to make up some flash cards to use in a teaching program as a slide presentation. I would like to divide a 3" x 5" rectangle into equally spaced columns and then place vertical text within each column. The number of columns would need to vary for different flash cards. Does anybody have any suggestions on how to do that?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Mar 17, 2004 9:15 am    Post subject: Reply with quote

Here is a macro that might help.

1. Tools --> Macros --> Macro.... (macro dialog box appears)
2. On the Left side, find "Macro from"
3. In the "Macro from" list, find your document name. (Your document may be Untitled1, but it is NOT "soffice".)
4. Unfold your document name to reveal a library under it named "Standard".
5. Click the "New" button on the right. (New Module dialog box appears.)
6. Click OK (accepting the name "Module1", and dismissing both dialogs)
7. The Basic IDE appears, positioned on Module1.
8. Select all of the text here and delete it.
9. Paste in the following code instead....
Code:
' Routine to vertically divide a shape into several identical
'  smaller shapes which are placed horizontally in a row,
'  occupying the same space as the original shape.
Sub Main
   ' CHANGE THIS.
   ' This is how many sub shapes a shape is split into.
   nNumSplits = 2
   
   ' Get document, its controller and frame.
   oDoc = ThisComponent
   oDocCtrl = oDoc.getCurrentController()
   oDocFrame = oDocCtrl.getFrame()
   ' Need this later.
   oDispatchHelper = createUnoService( "com.sun.star.frame.DispatchHelper" )

   ' See what is currently selected.
   oSelection = oDocCtrl.getSelection()
   If IsEmpty( oSelection ) Then
      MsgBox( "Please select a shape." )
      Exit Sub
   EndIf
   If oSelection.getCount() > 1 Then
      MsgBox( "Please select only ONE shape." )
      Exit Sub
   EndIf
   oOrigShape = oSelection.getByIndex( 0 )
   nXPosition = oOrigShape.Position.X
   nWidth = oOrigShape.Size.Width / nNumSplits
   oDispatchHelper.executeDispatch( oDocFrame, ".uno:Copy", "", 0, Array() )
   For i = 1 To nNumSplits
      oDispatchHelper.executeDispatch( oDocFrame, ".uno:Paste", "", 0, Array() )
      oSelection = oDocCtrl.getSelection()
      oNewShape = oSelection.getByIndex( 0 )
      oNewShape.Position = MakePoint( nXPosition, oOrigShape.Position.Y )
      oNewShape.Size = MakeSize( nWidth, oOrigShape.Size.Height )
      nXPosition = nXPosition + nWidth
   Next
End Sub

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

Function MakeSize( ByVal width As Long, ByVal height As Long ) As com.sun.star.awt.Size
   oSize = createUnoStruct( "com.sun.star.awt.Size" )
   oSize.Width = width
   oSize.Height = height
   MakeSize() = oSize
End Function

10. To run this code, you click the Run button. That is a little document icon with a down arrow -- second button from the left in the toolbar at the top of the BASIC window.

You can just move the BASIC window out of the way -- but don't close it.

Now create a rectangle in Draw. Select it. In the Basic window, click the Run button. You now have two shapes instead of one. (Your original shape does not go away, so you actually have two additional shapes.)

See the line that says...
nNumSplits = 2
You can change this to 3 or 4 or any number. Need a rectangle divided into five thousand smaller rectangles? Then change nNumSplits to 5000.

The macro does make use of the clipboard to copy & paste -- so you lose whatever you had in the clipboard.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
diggertoo
General User
General User


Joined: 16 Mar 2004
Posts: 12

PostPosted: Wed Mar 17, 2004 7:16 pm    Post subject: Reply with quote

Danny,

Thanks for all the help. The macro works great.
Back to top
View user's profile Send private message
Philip Epstein
Power User
Power User


Joined: 06 Sep 2003
Posts: 52

PostPosted: Thu Mar 18, 2004 12:20 am    Post subject: Reply with quote

Have you tried inserting a two column table that is 3x5 in size?

Shift+Enter can insert text within each side of the table independent of the other column?

I find tables very verastile components to display data in reports.

Phil
Back to top
View user's profile Send private message Send e-mail
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Apr 24, 2004 11:12 am    Post subject: Reply with quote

Here is a modification of the above routine that splits a shape into several rows instead of splitting it into columns.

http://www.oooforum.org/forum/viewtopic.php?p=30392#30392
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Steph33
Newbie
Newbie


Joined: 05 Apr 2005
Posts: 1
Location: Vienna, Austria

PostPosted: Tue Apr 05, 2005 12:58 am    Post subject: Reply with quote

Hi,

This macro works to split ONE cell into several column, but what if I want to split one COLUMN in several columns? But not the whole column, this is easy. Just the cells down a column from the 5th line for example. So that the first 5 lines are on 1 column and the following on 4 columns (the total width of the 4 columns being equal to the size of the 1 colum).

Stephane
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Draw All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group