Seite 1 von 1

Python: Problem: Neu aus Dokumentvorlage

Verfasst: Di, 19.01.2016 14:06
von preklov
Beim Erstellen eines neuen Dokuments aus einer Dokumentvorlage soll ein Makro starten, das in der Dokumentvorlage liegt.

Das Dokument erscheint wie gewünscht als 'Unbenannt 1', allerdings mit folgender Fehlermeldung:
Meldung: <class 'uno.com.sun.star.uno.RuntimeException'>: Couldn't convert file url to a system path for reason (21)
/opt/openoffice4/program/uno.py:92 in function fileUrlToSystemPath() [return pyuno.fileUrlToSystemPath( url )]
vnd.sun.star.tdoc:/1/Scripts/python/tasks.py:19 in function <module>() [None]
/opt/openoffice4/program/pythonscript.py:450 in function getModuleByUrl() [exec(code, entry.module.__dict__)]
/opt/openoffice4/program/pythonscript.py:991 in function getScript() [mod=self.provCtx.getModuleByUrl( fileUri )]
Ich vermute, es liegt daran, wie ich die Scripte in den Pythonpfad einbinde:

Code: Alles auswählen

import uno
import sys

doc = XSCRIPTCONTEXT.getDocument()

pythonPath = uno.fileUrlToSystemPath(doc.URL) + '/Scripts/python'
if pythonPath not in sys.path: sys.path.append(pythonPath)
Das funktioniert wohl nicht, weil die Datei noch nicht gespeichert ist. Welche Lösung wäre richtig? Im Internet habe ich nichts gefunden.

Schöne Grüße
Volker

Re: Python: Problem: Neu aus Dokumentvorlage

Verfasst: Di, 19.01.2016 16:15
von preklov
Ich glaube, ich muss das Problem klarer beschreiben. Es geht nicht wirklich darum, dass ein einziges Makro aufgerufen wird. Meine Funktionen habe ich auf verschiedene Dateien verteilt und importiere mehrfach genutzte Funktionen von der Datei toolbox.py:

Code: Alles auswählen

doc = XSCRIPTCONTEXT.getDocument()

pythonPath = uno.fileUrlToSystemPath(doc.URL) + '/Scripts/python'
if pythonPath not in sys.path: sys.path.append(pythonPath)

from toolbox import *
Wenn ich alles in eine einzige Datei packe, brauche ich keinen gesonderten Pythonpfad. Aber ich verliere die Übersicht.

Gibt es eine Lösung für mich?

Volker