| View previous topic :: View next topic |
| Author |
Message |
Maythe Newbie

Joined: 13 Dec 2010 Posts: 1
|
Posted: Mon Dec 13, 2010 7:12 pm Post subject: Macro to colorize each letter |
|
|
To all you super smart forum dwellers,
Okay, so I've been looking into OOoBasic and the API all day, but if there's any solid documentation, I haven't exactly found it.
What I'm trying to do is create a macro/extension that will color each character a different, but constant color as I type. (i.e. all 'a's will be red and all 'b's will be blue, etc.) I know that there is an extension called cOOoder which colorizes words as if the program were a code window ("if" would be dark blue, text in quotes would be dark green, etc.) so I'm sure that it's possible to have specific characters colorized in the same way. I just don't know how.
So... any code snippets or reference links or otherwise constructive responses you might offer would be greatly appreciated.
Thanks!
-Maythe. |
|
| Back to top |
|
 |
therabi Super User


Joined: 01 Sep 2010 Posts: 562
|
Posted: Mon Dec 13, 2010 8:12 pm Post subject: |
|
|
Have you tried the Basic Programming Guide on the documentation wiki at http://wiki.services.openoffice.org/wiki/Documentation/BASIC_Guide ? Have you tried to reverse engineer the cOOoder extension? _________________ OOO v3.3.0 & LO v3.4beta on Ubuntu 10.10 and Win7
If your problem has been solved please add "[Solved]" to the beginning of your first post title (edit button). |
|
| Back to top |
|
 |
Robert Tucker Moderator


Joined: 16 Aug 2004 Posts: 3367 Location: Manchester UK
|
Posted: Mon Dec 13, 2010 11:43 pm Post subject: |
|
|
I don't know how often you want to carry out the exercise, but if it's only on one or two texts you could just use Search and Replace 26 times. (If you write a macro I'm pretty sure you will still need to write out a line or two for each letter or at least set up an array with every letter in it.) _________________ LibreOffice 3.6.6 on Fedora 18, LibreOffice 4.0.2 on Ubuntu 13.04 (Double Boot) |
|
| Back to top |
|
 |
Gpoly General User

Joined: 30 Jun 2010 Posts: 6
|
Posted: Fri Dec 24, 2010 10:25 am Post subject: |
|
|
You can test this.
| Code: |
Sub TESTReplace
Dim replaceVal(0) As New com.sun.star.beans.PropertyValue
oDoc = thisComponent
aFind = Array("a", "b", "etc") 'find this chars
aReplace = Array("a", "b", "etc") 'replace with red color
sFind = Array("c", "d", "etc") 'find this chars
sReplace = Array("c", "d", "etc") 'replace with blue color
aRayCount = 0
sRayCount = 0
FandR = oDoc.createReplaceDescriptor
FandR.SearchCaseSensitive = true
While aRayCount <= uBound(aFind)
replaceVal(0).Name = "CharColor"
replaceVal(0).Value = RGB(255,0,0) 'red color
FandR.SetReplaceAttributes(replaceVal())
FandR.setSearchString(aFind(aRayCount))
FandR.setReplaceString(aReplace(aRayCount))
aRayCount = aRayCount + 1
oDoc.ReplaceAll(FandR)
Wend
While sRayCount <= uBound(sFind)
replaceVal(0).Name = "CharColor"
replaceVal(0).Value = RGB(30,144,255) 'blue color
FandR.SetReplaceAttributes(replaceVal())
FandR.setSearchString(sFind(sRayCount))
FandR.setReplaceString(sReplace(sRayCount))
sRayCount = sRayCount + 1
oDoc.ReplaceAll(FandR)
Wend
print "Finish"
End Sub
|
ps. Sorry for erros-i'm new |
|
| Back to top |
|
 |
|