Retrieve / Modify custom properties

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
jacklafrip
Posts: 7
Joined: Mon May 30, 2011 11:41 am

Retrieve / Modify custom properties

Post by jacklafrip »

Dear all,

I have a document that uses some custom properties.
These properties are used in other documents, so I want to use them.
I tried to retrieve the custom properties and modify the texts associated with them.

Code: Select all

XPropertySet xCustomProperty = (XPropertySet)((XMultiServiceFactory)TextDocument).createInstance("com.sun.star.text.textfield.docinfo.Custom");
xCustomProperty.setPropertyValue("Name", new uno.Any("CustomProperty1"));
xCustomProperty.setPropertyValue("CurrentPresentation", new uno.Any("TextForProperty"));
xCustomProperty.setPropertyValue("IsFixed", new uno.Any(true));
No modifications could be seen on the document.
What did I do for a mistake ?

Thanks
OpenOffice 3.3 on WindowsXP / VisualStudio 2005
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: Retrieve / Modify custom properties

Post by JohnSUN-Pensioner »

Useful Macro Information For OpenOffice.org By Andrew Pitonyak
5.18.3. Master Fields
 Edit: PS. At "OOME_3_0.odt" it is 14.8.2. Creating and adding text fields 
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
Pashahasband
Posts: 6
Joined: Thu Aug 01, 2019 4:21 pm

Re: Retrieve / Modify custom properties

Post by Pashahasband »

Hi, I ran into the same problem, was there a solution?
LibreOffice 6.2.4.2 (x64)
Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Retrieve / Modify custom properties

Post by Villeroy »

The answer is the same for 90% of all these questions.
1. Read the above linked book.
2. Install MRI. [Tutorial] Introduction into object inspection with MRI
No MRI, no macros.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Pashahasband
Posts: 6
Joined: Thu Aug 01, 2019 4:21 pm

Re: Retrieve / Modify custom properties

Post by Pashahasband »

I read the article above, but there is an example with fieldmaster, writing to user variables is normal for me. But writing to docinfo does not occur. Could you give an example of an entry in docinfo?
LibreOffice 6.2.4.2 (x64)
Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Retrieve / Modify custom properties

Post by Villeroy »

You know what? I don't know. I start MRI and look it up!
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Lupp
Volunteer
Posts: 3552
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Retrieve / Modify custom properties

Post by Lupp »

The UserDefinedProperties are implemented as a PropertyBag. This service inherits the interface XPropertyContainer which provides the functions you need.
See https://api.libreoffice.org/docs/idl/re ... ainer.html e.g.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Retrieve / Modify custom properties

Post by JeJe »

in Basic:

Code: Select all


propname = "New Property"
propvalue = "fish"

	with ThisComponent.DocumentProperties.UserDefinedProperties

		if .getPropertySetInfo().hasPropertyByName(propname) = false then
			.addProperty(propname,128,"")
		end if
			.setPropertyValue(propname, propvalue)
	
			MSGBOX .getPropertyValue(propname)
	end with

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply