Etienne,

I used in the past this code: ( founded on the OO-forum with thanks to JonnV:-)
hope it helps
Fernand

 sub InsertUserField
  oDoc = ThisComponent
oField = oDoc.createInstance("com.sun.star.text.FieldMaster.User")
  oField.Name  = "New field13" 'need to be Unique
  oField.Value = "New Field Text" 'your text

  objField = oDoc.createInstance("com.sun.star.text.TextField.User")
  objField.attachTextFieldMaster(oField)

  oVC = oDoc.CurrentController.getViewCursor
  oDoc.Text.insertTextContent(oVC,objField,false)
end sub



Thank you very much Fernand.
Can you please show how you assign a Name and Content to the field in Basic?
The creation of the field seems okay, but the glitch appears when I would to 
put something in it.

Thanks again,
-Etienne


----- Mail Original -----
De: "Fernand Vanrie" <s...@pmgroup.be>
À: dev@udk.openoffice.org
Envoyé: Jeudi 22 Octobre 2009 19h01:11 GMT +00:00 GMT - Grande-Bretagne, 
Irlande, Portugal
Objet: Re: [udk-dev] PyUNO : Inserting a User field

Etienne
in basic its done like:
Dim Doc As Object
Dim DateTimeField As Object
Dim Cursor As Object
Doc = StarDesktop.CurrentComponent
Cursor = Doc.Text.createTextCursor()
DateTimeField = Doc.createInstance("com.sun.star.text.T"com.sun.star.text.TextField.User")")
Doc.Text.insertTextContent(Cursor, DateTimeField, False)

hope it helps
fernand
Dear list,

First I hope I am in the right place... Please forgive me and direct me to the appropriate mailing-list/forum/whatever if I'm off-topic...

I'm trying to develop an application that would interact with OpenOffice via PyUNO, and I am not able to create a User field. I started from the Java example here: http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Text/Text_Fields, and tried to convert it in Python...

Dim Doc As Object
Dim DateTimeField As Object
Dim Cursor As Object
Doc = StarDesktop.CurrentComponent
Cursor = Doc.Text.createTextCursor()
DateTimeField = Doc.createInstance("com.sun.star.text.T"com.sun.star.text.TextField.User")")
Doc.Text.insertTextContent(Cursor, DateTimeField, False)
#-------------------------------------
import uno

localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext ) ctx = resolver.resolve( "uno:pipe,name=OOo_pipe;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager

desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
model   = desktop.getCurrentComponent()

if model.getImplementationName()=='SwXTextDocument':
   xUserField = model.createInstance("com.sun.star.text.TextField.User")
xMasterPropSet = model.createInstance("com.sun.star.text.FieldMaster.User")
   xMasterPropSet.setPropertyValue("Name", "UserEmperor")
ctx.ServiceManager
#-------------------------------------

I get an error "__main__.IllegalArgumentException", on the xMasterPropSet.setPropertyValue("Name", "UserEmperor") line. If I run dir(xMasterPropSet), I get all the expected method and properties, so it just look like the setPropertyValue is either not the implementation I expected, or that the argument types are wrong?

Can anyone give me a hint on how to do that?

Thanks a lot!.
-Etienne



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@udk.openoffice.org
For additional commands, e-mail: dev-h...@udk.openoffice.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@udk.openoffice.org
For additional commands, e-mail: dev-h...@udk.openoffice.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@udk.openoffice.org
For additional commands, e-mail: dev-h...@udk.openoffice.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@udk.openoffice.org
For additional commands, e-mail: dev-h...@udk.openoffice.org

Reply via email to