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

Macro to colorize each letter

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Maythe
Newbie
Newbie


Joined: 13 Dec 2010
Posts: 1

PostPosted: Mon Dec 13, 2010 7:12 pm    Post subject: Macro to colorize each letter Reply with quote

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
View user's profile Send private message
therabi
Super User
Super User


Joined: 01 Sep 2010
Posts: 562

PostPosted: Mon Dec 13, 2010 8:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
Robert Tucker
Moderator
Moderator


Joined: 16 Aug 2004
Posts: 3367
Location: Manchester UK

PostPosted: Mon Dec 13, 2010 11:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
Gpoly
General User
General User


Joined: 30 Jun 2010
Posts: 6

PostPosted: Fri Dec 24, 2010 10:25 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API 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