| View previous topic :: View next topic |
| Author |
Message |
JZA OOo Advocate


Joined: 01 Feb 2003 Posts: 432 Location: Mexico
|
Posted: Tue Nov 01, 2005 6:18 am Post subject: Marking your lines on a document |
|
|
How can I get a macro that will mark the number of the linea each 5th line. I want to have a document like this:
RIMA IV
No digáis que, agotado su tesoro,
de asuntos falta, enmudeció la lira;
podrá no haber poetas; pero siempre
habrá poesía.
Mientras las ondas de la luz al beso 5
palpiten encendidas,
mientras el sol las desgarradas nubes
de fuego y oro vista,
mientras el aire en su regazo lleve
perfumes y armonías, 10
mientras haya en el mundo primavera,
¡habrá poesía!
Mientras la ciencia a descubrir no alcance
las fuentes de la vida,
y en el mar o en el cielo haya un abismo 15
que al cálculo resista,
mientras la humanidad siempre avanzando
no sepa a dó camina,
mientras haya un misterio para el hombre,
¡habrá poesía! 20
Doing the macro recorder I saw that the uno:InsertPara (insert paragraph) should be counted and each 5th line it will be printed. _________________ Alexandro Colorado
PPMC Apache OpenOffice
http://es.openoffice.org |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Tue Nov 01, 2005 6:54 am Post subject: |
|
|
I can think of a few ways to do this, but what do you really want?
Do you want to setup up a numbering style and use a style. I have not used them much, but if you can, then you do not really need a macro.
Do you want to have simple text sitting there. You would then select the entire section and tell it to add the line numbers, removing existing numbers if they are already there?
Do you want to use fields?
Are you numbering paragraphs or individual lines? _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
JZA OOo Advocate


Joined: 01 Feb 2003 Posts: 432 Location: Mexico
|
Posted: Tue Nov 01, 2005 7:04 am Post subject: |
|
|
A numbering style might be a choice, however it will be difficult to replicate the way is written originally.
I think the best way is your third option which narrow the function to the selection of the text as opposed to apply it to the whole document and that can re-build the structure of the number.
I don't see a difference at this point between being a field and text but I think fields will be more flexible when printing/viewing, etc.
I notice that the BBCode eat out the spaces on the previous post so here is something more exact:
| Code: |
text text text text
text text text text
text text text text
text text text text
text text text text 5
text text text text
text text text text
text text text text
text text text text
text text text text 10 |
_________________ Alexandro Colorado
PPMC Apache OpenOffice
http://es.openoffice.org |
|
| Back to top |
|
 |
JZA OOo Advocate


Joined: 01 Feb 2003 Posts: 432 Location: Mexico
|
Posted: Tue Nov 01, 2005 7:14 am Post subject: |
|
|
| pitonyak wrote: | | Are you numbering paragraphs or individual lines? |
Individual lines but the number should only be visible every 5th line. _________________ Alexandro Colorado
PPMC Apache OpenOffice
http://es.openoffice.org |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Tue Nov 01, 2005 7:55 am Post subject: |
|
|
I see that numbering always puts the numbering on the left, and you want the numbering on the right. This rules out numbering, even if you could figure out how to move the numbers, there is the issue of labeling every fifth line.
The problem with fields is that you need to insert and remove them if you insert text.
The problem with text fields is that you need to remove the text and also, you need to identify that the text is part of the numbering.
So, how do you move the text to the right? I guess that I will leave this as an "exercise for the reader"
| Code: | Dim oSels
Dim oSel
Dim oCurs
Dim oEnum
Dim oField
Dim oNewField
Dim oMasters
Dim oDFields()
Dim sName
Dim x
Dim i%
Dim s$
Dim sExprName
Dim sNewName
Dim oText
Dim oAnchor
Dim oParenMField
Dim oNewMField
oSels = ThisComponent.getCurrentSelection()
If oSels.getCount() <> 1 Then
Print "Select a single region"
Exit Sub
End If
oSel = oSels.getByIndex(0)
oText = oSel.getText()
oCurs = oText.createTextCursorByRange(oSel)
If oCurs.isCollapsed() Then
Print "Select a single region"
Exit Sub
End If
sExprName = "com.sun.star.text.FieldMaster.SetExpression"
sName = "Paren"
sName = "Blah"
sNewName = sExprName & "." & sName
oMasters = ThisComponent.getTextFieldMasters()
If oMasters.hasByName(sNewName) Then
oNewMField = oMasters.getByName(sNewName)
Else
oNewMField = ThisComponent.createInstance(sExprName)
oNewMField.Name = sName
oNewMField.SubType = 1
End If
oDFields() = oNewMField.DependentTextFields
REM First, remove all existing fields.
For i = LBound(oDFields()) To UBound(oDFields())
oField = oDFields(i)
oAnchor = oField.getAnchor()
If oText.compareRegionStarts(oAnchor, oCurs) <= 0 AND _
oText.compareRegionEnds(oAnchor, oCurs) >= 0 Then
oField.dispose()
End If
Next
Dim nCount As Long
nCount = 0
REM Now, add new fields.
oEnum = oSel.createEnumeration()
Do While oEnum.hasMoreElements
oPar = oEnum.nextElement()
If oPar.supportsService("com.sun.star.text.Paragraph") Then
nCount = nCount + 1
If nCount MOD 5 = 0 Then
oField = ThisComponent.createInstance("com.sun.star.text.TextField.SetExpression")
If nCount = 5 Then
oField.Content = "5"
Else
oField.Content = sName & "+5"
End If
oField.NumberFormat = 4
oField.NumberingType = 4
oField.attachTextFieldMaster(oNewMField)
oCurs.gotoRange(oPar.getEnd(), False)
oText.insertTextContent(oCurs, oField, False)
End If
End If
Loop
|
_________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
JZA OOo Advocate


Joined: 01 Feb 2003 Posts: 432 Location: Mexico
|
Posted: Tue Nov 01, 2005 11:57 am Post subject: |
|
|
| pitonyak wrote: | So, how do you move the text to the right? I guess that I will leave this as an "exercise for the reader"
|
Sun engineers usually do this to their documents, even if they are not specifically to the right they are using the same technique that could be used to do the same goal.
Look at some document from the DBA project which uses frames with numbers in it.
http://dba.openoffice.org/specifications/Wizard_Table.sxw
I also put a screenshot of the properties of the frames simulating the view that we are triying to get.
 _________________ Alexandro Colorado
PPMC Apache OpenOffice
http://es.openoffice.org |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Tue Nov 01, 2005 1:25 pm Post subject: |
|
|
Excellent! I left this as an exercise because I am busy. As such, I solved what I considered the hard part so that you can have some fun playing with macros as well!  _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
JZA OOo Advocate


Joined: 01 Feb 2003 Posts: 432 Location: Mexico
|
Posted: Tue Nov 01, 2005 1:59 pm Post subject: |
|
|
Will do, thanks Andrew _________________ Alexandro Colorado
PPMC Apache OpenOffice
http://es.openoffice.org |
|
| Back to top |
|
 |
|