| View previous topic :: View next topic |
| Author |
Message |
diggertoo General User

Joined: 16 Mar 2004 Posts: 12
|
Posted: Tue Mar 16, 2004 8:42 pm Post subject: Dividing rectangle into equally spaced vertical columns ?? |
|
|
| 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 |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Wed Mar 17, 2004 9:15 am Post subject: |
|
|
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 |
|
 |
diggertoo General User

Joined: 16 Mar 2004 Posts: 12
|
Posted: Wed Mar 17, 2004 7:16 pm Post subject: |
|
|
Danny,
Thanks for all the help. The macro works great. |
|
| Back to top |
|
 |
Philip Epstein Power User

Joined: 06 Sep 2003 Posts: 52
|
Posted: Thu Mar 18, 2004 12:20 am Post subject: |
|
|
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 |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
Steph33 Newbie

Joined: 05 Apr 2005 Posts: 1 Location: Vienna, Austria
|
Posted: Tue Apr 05, 2005 12:58 am Post subject: |
|
|
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 |
|
 |
|