Monday, July 5, 2010

How to insert Python Script in OOwriter as macro

Python being an object oriented language has great benefit in designing the API but in case you want to automate the oowriter you need to compromise in terms of ease of coding as is provided with openoffice.org basic.But Good news is that this problem occur only if you want to write Macros in Python but if you want to design API to OpenOffice using UNO (Universal Network Object) than python programming is great.But as i already said that the major disadvantage of doing python scripting in oowriter is that you cann't write script directly into your openoffice.

Instead we need to use a separate text editor you may use any and write down your code within file with extension .py.
After that if you wish to add this script in oowriter as macro just do the following:

Script Location

Scripts to be excuted in OpenOffice.org can be stored within the following locations:

OpenOffice.org's user directory

This is the standard place for self written python scripts. The script files are simply stored within the file system.
On windows, the directory can typically be found in:
windows - C:\Documents and Settings\Application Data\OpenOffice.org 2.0\user\Scripts\python
unix - ~/.openoffice.org.2.0/user/Scripts/python
Note, that the last python subdirectory may need to be created initially. Make sure, the python is completely written lowercase. You can add arbitrary deeply nested subdirectories, the names of these directories are reflected in the UI.
Example: The dynamicDialog.py file can simply be placed in the above directory. Afterwards, open the
->Tools->Macros->Run macro dialog and navigate to the position shown in the above picture.
Click on Run to execute the python script, which opens another dialog with a push button and a label field. Clicking the button will increase the number within the label field. The dialog can be closed by pressing ESC.

OpenOffice.org's share directory


Scripts that shall be shared throughout all users of a concrete OpenOffice.org installation can be stored with the share directory. All default scripts coming with OpenOffice.org are located here. In general, this directory should not be used for script deployment (see later uno-packages).
The script files are simply stored within the file system. The directory can typically be found in
windows C:\Program Files\OpenOffice.org 2.0\share\Scripts\python
unix /usr/lib/openoffice/share/Scripts/python

No comments:

Post a Comment