Add User Defined Property function error

Hi All. I’m trying to set NEW user defined variables using Python macro with the following code

    props = doc.getDocumentProperties().getUserDefinedProperties()

    if not props.getPropertySetInfo().hasPropertyByName(name):
        props.addProperty(name, 0, value)

And everything works if “value” has “string” type for example props.addProperty(‘par1’, 0, ‘val1’)
But if I try to set props.addProperty(‘par2’, 0, 1) I see an Illegal type error
image

I would immediately assume some mismatch between the default (unspecified!) marshaling of Python number to UNO interface, and the actually expected/supported types.

And therefore, I’d try passing a strictly typed value, like in SDK/python : selecting "Print to File..." as printer from API may be fraught with difficulty? - #28 by mikekaganski.

Can you try with ('par2',4,1)
I think that the second attribute is the type of property and can be 4

Text 0
DateTime 1
Date 2
Duration 3
Number 4
Yes or No 5

The same error on props.addProperty(‘param3’, 4, 1). Grok said that the second param indicates read only feature “props.addProperty(name, read_only, value)” he said that type of prop is set accrding the default value in “value” param. But it doesn’t work for me(

Here is the specification LibreOffice: XPropertyContainer Interface Reference

1 Like

Where can these things come from? Glad that @Roman001 found the correct documentation - but the previous comments were so much unexpected, and likely to increase overall entropy…

Can’t believe. Would expext a BASIC error because there is an IF without a THEN.
With a correct Sub I get no problem under V25.8.0.4.
(Neither with Writer nor with Calc, nor with value being a number.)

Added “common” to the tags.

Hello, Wolfgang!
The colon at the end of the first line tells us we’re in the Python universe.
And please, strictly 4-space indentation - otherwise jail time. :slight_smile:

:slight_smile: I would even risk guessing, that that’s @Roman001 who tells that:

1 Like

Thanks. I actually missedf that. Sorry!
However, the Python code and my Basic code use the same API objects. If it works in Basic, but not in Python: Can there be a problem with the bridge?
Did somebody check the OQer’s claim using Python?
I didn’t because I dislike Python even more than Basic.

@Lupp please see the thread that I linked to in my initial reply. I compared the bridge code for Basic and for Python … but it turned out, that a change there wasn’t needed after all. Marshaling may differ between languages / bridges, for legitimate reasons; so in this case, an evaluation is needed from actual Python developers, if they actually would benefit from the possible change…

See also this topic.