in very conventional programming without uno path functions and type=draw functions
use suggestions of karolus below (and or above) to improve text manipulation (or circumvent it)
(edited and added on request of @karolus)
import uno
ctx = uno.getComponentContext()
smgr = ctx.ServiceManager
StarDeskTop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
#these variables are useful in many defs, for convenience: the dispatcher functionality
dispatcher = smgr.createInstanceWithContext("com.sun.star.frame.DispatchHelper", ctx)
def transfer():
oDoc = XSCRIPTCONTEXT.getDocument()
if not oDoc.hasLocation() : # new document without a name/location
return
sText = oDoc.URL
i = sText.rfind("/")
sPath = sText[:i+1]
i = sText.rfind(".")
if sText[i+1:] != "odg":
return
sText = sPath + "mycalc.ods"
args = dictToProperty({"Hidden":True})
mycalc = StarDeskTop.loadComponentFromURL(sText, '_default', 0, args)
# add data to mycalc
mycalc.storeAsURL( sText , () )
mycalc.dispose()
def dictToProperty(values):
# call: arg as { 'FilterName': 'writer_pdf_Export' , "Hidden" : False , ...}
ps = tuple([PropertyValue(Name=n, Value=v) for n, v in values.items()])
return ps
edit by @karolus repared codeblock