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


Joined: 18 Nov 2006 Posts: 257
|
Posted: Wed Feb 25, 2009 10:58 pm Post subject: [Solved]WrongWordsList macro works in italian not in english |
|
|
i have this macro that collect all wrong words (words underlined in red) of a writer document into a new writer document.
| Code: | Sub WrongWordsList
Dim oDocModel as Variant
Dim oTextCursor as Variant
Dim oLinguSvcMgr as Variant
Dim oSpellChk as Variant
Dim oListDocFrame as Variant
Dim oListDocModel as Variant
Dim sListaPalabras as String
Dim aProp() As New com.sun.star.beans.PropertyValue
oDocModel = StarDesktop.CurrentFrame.Controller.getModel()
If IsNull(oDocModel) Then
MsgBox("There's no active document." + Chr(13))
Exit Sub
End If
If Not HasUnoInterfaces (oDocModel, "com.sun.star.text.XTextDocument") Then
MsgBox("This document doesn't support the 'XTextDocument' interface." + Chr(13))
Exit Sub
End If
oTextCursor = oDocModel.Text.createTextCursor()
oTextCursor.gotoStart(False)
oLinguSvcMgr = createUnoService("com.sun.star.linguistic2.LinguServiceManager")
If Not IsNull(oLinguSvcMgr) Then
oSpellChk = oLinguSvcMgr.getSpellChecker()
End If
If IsNull (oSpellChk) Then
MsgBox("It's not possible to access to the spellcheck." + Chr(13))
Exit Sub
End If
Do
If oTextCursor.isStartOfWord() Then
oTextCursor.gotoEndOfWord(True)
' Verificar si la palabra está bien escrita
If Not isEmpty (oTextCursor.getPropertyValue("CharLocale")) Then
If Not oSpellChk.isValid(oTextCursor.getString(),oTextCursor.getPropertyValue("CharLocale").Language, aProp()) Then
sListaPalabras = sListaPalabras + oTextCursor.getString() + Chr(13)
End If
End If
oTextCursor.collapseToEnd()
End If
Loop While oTextCursor.gotoNextWord(False)
If Len(sListaPalabras) = 0 Then
MsgBox("There are no errors in the document.")
Exit Sub
End If
oListDocFrame = StarDesktop.findFrame("fListarPalabrasIncorrectas", com.sun.star.frame.FrameSearchFlag.ALL)
If IsNull(oListDocFrame) Then
oListDocModel = StarDesktop.loadComponentFromURL("private:factory/swriter", "fListarPalabrasIncorrectas", com.sun.star.frame.FrameSearchFlag.CREATE, aProp())
oListDocFrame = oListDocModel.CurrentController.getFrame()
Else
oListDocModel = oListDocFrame.Controller.getModel()
End If
oTextCursor = oListDocModel.Text.createTextCursor()
oTextCursor.gotoEnd(False)
oListDocModel.Text.insertString (oTextCursor, sListaPalabras, False)
oListDocFrame.activate()
End Sub |
the original macro had a slighly different code and worked perfectly on OOo 2.x then with the 3.x series it stopped working and i had to change some code lines.
see original code here: http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=1222#p4894
the macro does its job if a text is in italian on OOo 3.0.1. you click it and a wrong words list is generated.
if the text is in english the macro creates a list with all the words of the document... both errors and correct words are inside the list...
the macro was supposed to extract only the errors (i.e. words underlined in red...)
i have Windows Vista Home Premium 64bit SP1. I'm using OOo 3.0.1
i have both italian and english dictionary extensions installed for all users.
i'm wondering why it works in italian and doesn't work properly in english...
any idea?
Last edited by Tommy27 on Sun Mar 08, 2009 1:57 pm; edited 1 time in total |
|
| Back to top |
|
 |
bluegecko General User

Joined: 12 Jun 2007 Posts: 45 Location: Portugal
|
Posted: Fri Mar 06, 2009 5:38 pm Post subject: |
|
|
Hmm, I also noticed things no longer working. I'm not up to speed with macros these days (need to work for money instead of fiddling with OOo), but from my completely ignorant point of view, Prop() - whatever it is - seems to be causing the trouble, as the language code for oTextCursor.getPropertyValue("CharLocale").Language does, as far as I can tell, switch correctly when it gets to words in different languages.
Incidentally, the behaviour isn't related to any specific language, but I think to the GUI, so I'm guessing your copy of OOo has the interface set to Italian (my system is the reverse; the macro just works with English words, and adds everything else to the list of misspellings).
The Linguist extension (http://extensions.services.openoffice.org/project/Linguist) has similar trouble. It doesn't use the GUI language but the main document language, which is just as useless for multilingual documents.
If someone could explain what Prop() is, that would be a great help, as try as I might, I can make head or tail of the api docs.
I hope it's just syntax trouble, as there surely must be a simple way of checking the language of each word. Mind you, the entire logic of OOo's language set-up makes no sense at all: linking languages to paragraph styles is just stupid (sorry, I don't mean to offend anyone!), as it means losing language formatting when changing paragraphs. I finally found a workaround, which is to use character styles to define languages, as they won't disappear if I change the paragraph style. That means not being being able to use character styles for basic formatting like bold and italic, but I can live with that, as the result is superb handling of multilingual documents.
Anyway, fingers crossed... |
|
| Back to top |
|
 |
Tommy27 OOo Advocate


Joined: 18 Nov 2006 Posts: 257
|
Posted: Fri Mar 06, 2009 11:34 pm Post subject: |
|
|
you are right: my OOo copy has italian GUI and the macro works only in italian language, while it fails in english and german and spanish etc. etc.
i sent an email to the author of the macro but he still did not answered me
however i wonder why the same macro (with slightly different code) did its job in all language in OOo 2.x while it is suboptimal in OOo 3.x |
|
| Back to top |
|
 |
bluegecko General User

Joined: 12 Jun 2007 Posts: 45 Location: Portugal
|
Posted: Sat Mar 07, 2009 4:58 am Post subject: |
|
|
| Quote: | | i wonder why the same macro (with slightly different code) did its job in all language in OOo 2.x while it is suboptimal in OOo 3.x |
Heh, it's either a bug or a "feature"! The macro worked fine for me in 3.0 (300m7), but not in the nightly 3.0.1 I installed yesterday. Looks like I'll still be using 3.0 for the time being.
If someone more knowledgeable about language coding can explain what the problem is likely to be (as I said in my first post, I'm not an expert), I'll be happy to post a bug report.
~bluegecko |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1313
|
Posted: Sat Mar 07, 2009 8:33 am Post subject: |
|
|
Hi,
I slightly modified the macro. Please have a new test - I am on OO 2.4 and do not yet intend to go to OO 3.X.
I changed the following:
| Code: | old: oDocModel = StarDesktop.CurrentFrame.Controller.getModel()
new: oDocModel = ThisComponent | This simplifies debugging from BasicIDE
| Code: | old:
If oTextCursor.isStartOfWord() Then
oTextCursor.gotoEndOfWord(True)
' Verificar si la palabra está bien escrita
If Not isEmpty (oTextCursor.getPropertyValue("CharLocale")) Then
If Not oSpellChk.isValid(oTextCursor.getString(),oTextCursor.getPropertyValue("CharLocale").Language, aProp()) Then
sListaPalabras = sListaPalabras + oTextCursor.getString() + Chr(13)
End If
End If
oTextCursor.collapseToEnd()
End If
new:
If oTextCursor.isStartOfWord() Then
oTextCursor.gotoEndOfWord(True)
oCharLoc = oTextCursor.getPropertyValue("CharLocale")
If Not isEmpty (oCharLoc) Then
If Not oSpellChk.com_sun_star_linguistic2_XSpellChecker_isValid(oTextCursor.getString(),oCharLoc, Array()) Then
sListaPalabras = sListaPalabras + oTextCursor.getString() + Chr(13)
End If
End If
oTextCursor.collapseToEnd()
End If |
The main change here is is in the isValid call. As the function isValid is present in two interfaces with the same name (one of the interfaces is depreciated), I specified the interface name in the function call. I believe this is the major reason for instabilities between different OO builds.
I also simplified the generation of the new text doc with the misspelled words.
Good luck,
ms777
| Code: | Sub WrongWordsList
oDocModel = ThisComponent
If IsNull(oDocModel) Then
MsgBox("There's no active document.")
Exit Sub
End If
If Not HasUnoInterfaces (oDocModel, "com.sun.star.text.XTextDocument") Then
MsgBox("This document doesn't support the 'XTextDocument' interface.")
Exit Sub
End If
oTextCursor = oDocModel.Text.createTextCursor()
oTextCursor.gotoStart(False)
oLinguSvcMgr = createUnoService("com.sun.star.linguistic2.LinguServiceManager")
If Not IsNull(oLinguSvcMgr) Then
oSpellChk = oLinguSvcMgr.getSpellChecker()
End If
If IsNull (oSpellChk) Then
MsgBox("It's not possible to access to the spellcheck.")
Exit Sub
End If
Do
If oTextCursor.isStartOfWord() Then
oTextCursor.gotoEndOfWord(True)
oCharLoc = oTextCursor.getPropertyValue("CharLocale")
If Not isEmpty (oCharLoc) Then
If Not oSpellChk.com_sun_star_linguistic2_XSpellChecker_isValid(oTextCursor.getString(),oCharLoc, Array()) Then
sListaPalabras = sListaPalabras + oTextCursor.getString() + Chr(13)
End If
End If
oTextCursor.collapseToEnd()
End If
Loop While oTextCursor.gotoNextWord(False)
If Len(sListaPalabras) = 0 Then
MsgBox("There are no errors in the document.")
Exit Sub
End If
oListDocModel = StarDesktop.loadComponentFromURL("private:factory/swriter", "_default", 0, Array())
oListDocModel.Text.String = sListaPalabras
oListDocModel.CurrentController.Frame.activate()
End Sub |
|
|
| Back to top |
|
 |
bluegecko General User

Joined: 12 Jun 2007 Posts: 45 Location: Portugal
|
Posted: Sat Mar 07, 2009 9:10 am Post subject: |
|
|
Wow, superuser indeed, ms777! - that code works fine for me.
Tommy27, if it works for you too, I'd suggest changing the title of this thread to something like "[Solved] Add all underlined words to dictionary UPDATED" to match the name of the original thread.
Thank you both,
~bluegecko |
|
| Back to top |
|
 |
Tommy27 OOo Advocate


Joined: 18 Nov 2006 Posts: 257
|
Posted: Sun Mar 08, 2009 1:56 pm Post subject: |
|
|
it works 4 me too!!!
thank you!!! |
|
| Back to top |
|
 |
fredwang General User

Joined: 30 Jul 2008 Posts: 7
|
Posted: Thu Mar 26, 2009 1:05 pm Post subject: [Solved]WrongWordsList macro works in italian not in english |
|
|
hi, great macro!
would it be possible to change this to search for italic words and create a list?
any help would be appreciated
regards
fred |
|
| Back to top |
|
 |
bluegecko General User

Joined: 12 Jun 2007 Posts: 45 Location: Portugal
|
Posted: Sat Mar 28, 2009 11:46 am Post subject: |
|
|
Find all italics...
Yup, try this. Works for me, but I'm not an expert, so I'm sure the code could be tightened, tweaked, prettified or bulletproofed...
| Code: |
REM List all italic words in a new document
Sub Main
oDocModel = ThisComponent
If IsNull(oDocModel) Then
MsgBox("No active document (not sure that's possible in OOo 3.1, but still.")
Exit Sub
End If
oTextCursor = oDocModel.Text.createTextCursor()
oTextCursor.gotoStart(False)
Dim foundWords, i
i = 0
foundWords = ""
Do
If oTextCursor.isStartOfWord() Then
oTextCursor.gotoEndOfWord(True)
oCharLoc = oTextCursor.getPropertyValue("CharPosture")
If (oCharLoc <> 0) Then
foundWords = foundWords + oTextCursor.getString + Chr(13)
i = i + 1
End If
oTextCursor.collapseToEnd()
End If
Loop While oTextCursor.gotoNextWord(False)
If i = 0 Then
MsgBox("No italic words found in the document.",,"Find italics")
Exit Sub
End If
oListDocModel = StarDesktop.loadComponentFromURL("private:factory/swriter", "_default", 0, Array())
oListDocModel.Text.String = foundWords
oListDocModel.CurrentController.Frame.activate()
End Sub
|
Hope that helps you,
~bluegecko |
|
| Back to top |
|
 |
Tommy27 OOo Advocate


Joined: 18 Nov 2006 Posts: 257
|
Posted: Mon Mar 30, 2009 5:20 am Post subject: |
|
|
| nice macro variation!!! |
|
| Back to top |
|
 |
|
|
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
|