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

UserDefinedAttributes with PyUNO

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


Joined: 27 Aug 2003
Posts: 4
Location: Ireland

PostPosted: Wed May 04, 2005 7:21 am    Post subject: UserDefinedAttributes with PyUNO Reply with quote

Hi

I am trying set a user defined attributes on a table cell ( com.sun.star.table.CellProperties ) using the PyUNO binding but when I use the code below:

Code:
table.getCellByName( cellId )
try:
    userAttrs = cell.getPropertyValue( "UserDefinedAttributes" )

    myAttr = uno.createUnoStruct("com.sun.star.beans.PropertyValue")   
    myAttr.Name = "URL"
    myAttr.Value = "myURL"
               
    uno.invoke( userAttrs , "insertByName", (myAttr.Name, uno.Any( \   
        "[]com.sun.star.beans.PropertyValue", myAttr)) )

except RuntimeException, rte:
    raise rte
   

I get the following error:
return pyuno.invoke( object, methodname, argTuple )
com.sun.star.uno.RuntimeException: conversion not possible!


Is there something wrong in the way I am setting up and passing in my values to insertByName function?

Is there a better way to set attributes for the User Defined Attributes of Properties?

Thank you,

--
Darragh Sherwin
Code:
Quote:
Quote:
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed May 04, 2005 11:12 am    Post subject: Reply with quote

I created a spreadsheet with a user defined attribute like this....
Code:
Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************
   
IDLE 1.0     
>>> import Danny.OOo.OOoLib
>>> from Danny.OOo.OOoLib import *
>>> oDoc = StarDesktop.loadComponentFromURL( "private:factory/scalc", "_blank", 0, Array() )
>>> oSheet = oDoc.getSheets().getByIndex( 0 )
>>> oCell = oSheet.getCellByPosition( 2, 5 )
>>> oUserDefinedAttributes = oShape.UserDefinedAttributes

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in -toplevel-
    oUserDefinedAttributes = oShape.UserDefinedAttributes
NameError: name 'oShape' is not defined
>>> oUserDefinedAttributes = oCell.UserDefinedAttributes
>>> oUserDefinedAttributes.hasByName( "MeowMix" )
False
>>> oMyAttribute = createUnoStruct( "com.sun.star.xml.AttributeData" )
>>> oMyAttribute.Type = "CDATA"
>>> oMyAttribute.Value = "Giddy Gat"
>>> oUserDefinedAttributes.insertByName( "MeowMix", oMyAttribute )
>>> oCell.UserDefinedAttributes = oUserDefinedAttributes
>>> oDoc.storeToURL( convertToURL( "C:\\Documents and Settings\\dbrewer\\Desktop\Test.sxc" ), Array() )
>>> oDoc.close( True )
>>>

Please note that it is IMPORTANT to store the collection of user attributes back to the property like so....
Code:
oCell.UserDefinedAttributes = oUserDefinedAttributes

in the example above.


Then, using a new python session, I reloaded the document and verified that it had my custom attribute....
Code:
Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************
   
IDLE 1.0     
>>> import Danny.OOo.OOoLib
>>> from Danny.OOo.OOoLib import *
>>> oDoc = StarDesktop.loadComponentFromURL( convertToURL( "C:\\Documents and Settings\\dbrewer\\Desktop\Test.sxc" ), "_blank", 0, Array() )
>>> oSheet = oDoc.getSheets().getByIndex( 0 )
>>> oCell = oSheet.getCellByPosition( 2, 5 )
>>> oUserDefinedAttributes = oCell.UserDefinedAttributes
>>> oUserDefinedAttributes.hasByName( "MeowMix" )
True
>>> oMyAttribute = oUserDefinedAttributes.getByName( "MeowMix" )
>>> oMyAttribute.Value
u'Giddy Gat'
>>> oDoc.close( True )
>>>


See Also....

http://www.oooforum.org/forum/viewtopic.phtml?p=69530#69530

Danny's Python Modules
http://www.oooforum.org/forum/viewtopic.phtml?t=14409
_________________
Want to make OOo Drawings like the colored flower design to the left?
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