Find information vnd.sun.star.tdoc

Hello,
I am trying to find out about the vnd.sun.star.tdoc “url”. In my attempt to find the location of the python macro, i ran the following code:

import os
import inspect
f_name = inspect.getfile(inspect.currentframe())
print(f_name)

I get the following result:

vnd.sun.star.tdoc:/6966025016/Scripts/Python/LibraryDbCons/ModulePgCon.py

I was reading up on vnd.sun.star.tdoc but the documentation is quite cryptic.

In Python and Basic how can I get this object and view the attributes?

This interface allows you to work with the internal structure (archive) of an open document.
Example: similarly to APSO, we add a Python script to an open document.

Sub CreatePythonScript
  Dim oDoc, oSfa, pathPy As String
  oDoc=ThisComponent
  oSfa = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
  pathPy="vnd.sun.star.tdoc:/" & oDoc.RuntimeUID & "/Scripts/python/"
  oSfa.createFolder(pathPy)
  oSfa.copy ConvertToUrl("C:\temp\test1.py"), pathPy & "test1.py"

End Sub

1 Like

This is very interesting. I have accepted this as the answer. Just one last question, is there a way to convert the vnd.sun.star.tdoc:/### url to a filepath? Thank you.

As far as I understand, this interface only exists for the open document and takes into account all changes made to the document since the file was opened.
Essentially this is the filepath:

Sub ShowTdoc
  Dim oDoc As Object, oSfa As Object, arr
  oDoc=ThisComponent
  oSfa = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
  arr=oSfa.getFolderContents("vnd.sun.star.tdoc:/" & oDoc.RuntimeUID, True)
  Msgbox Join(arr, Chr(10))
End Sub

No, because »vnd.sun.star.tdoc:« is the LO-internal-Protocol

A. Pitonyak calls this interface “13.18. The coolest trick I know” (OOME_4_1.odt) :slightly_smiling_face:

Yes, and pretty much the only use case where I use: »sfa.copy( tmp_uri, file_uri )« to embed python files in documents.
Otherwise I prefer native python functions for general file handling

1 Like