[Solved] How To Obtain Default PAra Style Name

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
cando
Posts: 2
Joined: Fri Jun 26, 2015 12:13 am

[Solved] How To Obtain Default PAra Style Name

Post by cando »

Hello,

I've spent the last couple of years creating a Writer Template that contains a good deal of OO Basic Macros that help create a chess document. One of the features is the ability to select a number of chess moves in the Writer document, then click on an icon to have those moves played out on an internal board. Now that the board position is in an internal structure, the user only has to click on another icon to have a chess diagram inserted into the document at the cursor.

All of this works just fine so long as the user is using an English version of the Open Office program itself, but it does not work for any of the non-English versions.

I know what the problem is, but I don't know how to go about fixing it. Before the diagram position is inserted, the paragraph style must be set to Default:

Code: Select all

mySelection.ParaStyleName = "Default"
Now, that works for English versions. But what i need to use for the Portuguese version is:

Code: Select all

mySelection.ParaStyleName = "Predefinição"
My question is, then: How do I go about obtaining the name of the Default paragraph style using OO Basic so that it works for all language versions of Open Office? What I'd like to do is get this Default para style name and store it in a variable at the start-up of the Template. (I've already got a Sub that gets called at start-up, so it shouldn't be a problem to add whatever code I need.)

I believe that I read something to the effect that some of these para styles have a universal name that works for all language versions of Open Office, but that may be something that was implemented for an older version ans has be deprecated since then.

Any help that I can get for this problem would be greatly appreciated.

Thanks!

cando
Last edited by RoryOF on Fri Jun 26, 2015 11:24 pm, edited 2 times in total.
Reason: Added green tick [RoryOF, Moderator]
OpenOffice 4.1 on Windows 8
FJCC
Moderator
Posts: 9280
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How To Obtain Default PAra Style Name

Post by FJCC »

My user interface is in Spanish. If I set the paragraph style of the first paragraph to Cuerpo de Texto (Text body in English) and then run this macro

Code: Select all

oText  = ThisComponent.Text
oCurs = oText.createTextCursor()
oCurs.gotoStart(False)
oCurs.ParaStyleName = "Standard"
The paragraph style changes to Predeterminado (Default in English). Will that work for you?
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: How To Obtain Default PAra Style Name

Post by B Marcelly »

A style object can, in principle, give the programmatic name of the style.
Example for french:

Code: Select all

Dim paragStyles As Object, aStyle As Object

paragStyles = ThisComponent.StyleFamilies.getByName("ParagraphStyles")
aStyle = paragStyles.getByName("Corps de texte")   ' localized name
print aStyle.DisplayName ' -> Corps de texte
print aStyle.Name        ' -> Text body
However that does not work for Default, at least for french:
DisplayName -> Standard
Name -> Standard

You should not depend on a Default style. In your template, create a specific style. Then you can use its name in every language.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
cando
Posts: 2
Joined: Fri Jun 26, 2015 12:13 am

Re: How To Obtain Default PAra Style Name

Post by cando »

Thanks to both of you, FJCC and Bernard, I really appreciate your solutions to my problem. Using Standard works for all language versions.

I'm still having a couple of other problems with the Basic code, but I'm hopeful that I can find solutions for them. I'm lucky to have a couple of users who are keen to work with me to iron out the odd bug.

Thanks again!

cando
OpenOffice 4.1 on Windows 8
Post Reply