Moving macros from user location to document one

I have a Base file that uses several macros. The macros were developed in python and saved as user macros.

Now I want to save the macros as document macros, that is, embed the macros in the document and have the macros work regardless of the computer or user running the Base file.

I have no problem embedding the macros in the file, even with APSO it is done in one click.

The problem I have is that when referencing the macros in the controls of the forms, the reference is saved in such a way that, besides the name of the macro, the location is saved. That is to say, in the properties of the control it looks something like this
invoices2.py$invoice_collaborator (user, Python).

Internally, inside the Base file, it is stored like this:
xlink:href="vnd.sun.star.script:invoices2.py$open_form?language=Python&location=user"

Changing the reference in each control, one by one, would be tedious because there are many references and I would surely forget some of them.

What I want is to know if there is an easy and quick way to replace all the references to ā€˜userā€™ with references to ā€˜documentā€™, so that all the macros look like
invoices2.py$invoice_collaborator (document, Python), which internally would be:
facturas.odb (1007,0 KB)

So you yourself indicated a simple solution: replace in the archive file(s) text

?language=Python&location=user

to

?language=Python&location=document

in any text editor. :slightly_smiling_face:

As you Know that is in the compressed file. If I do it, the file gets corrupted, also if I uncompress / compress the file.

Any case, Iā€™d need go form by form and there are lots of forms

.odb files are regular archives. You can unpack the archive into a folder, perform text replacements (some editors will allow you to do this for all files in the folder at once), pack the archive and check the work done.
This can be done with macros, but it seems to me that it will be more time-consuming.
Although @karolus does this in a couple of lines. :slightly_smiling_face:

Unless your change breaks XML, that shouldnā€™t happen

I usually end up with the opposite problem - developing the project in a separate file and then converting the forms for use in the extension. That is, I usually change location=document to location=application. To avoid digging through the compressed file, I open the form in the editor and use Export Dialog.

image

I open the resulting file in Notepad++ and use the replacement. Then I import the dialog back. Unfortunately, I donā€™t know a better way yet.

1 Like

Iā€™ve tried without change anything but the concrete words ā€œuserā€ and ā€œdocumentā€ and also the re-compressed document was corrupted.
(tried with two different compressors, 7zip an windows one, and the edition done with notepad++)

In this case that is not possible, Iā€™m speaking about (database) Forms, not about dialogs

Maybe, but certainly not without the document!
My crystal ball works only at full moon between midnight and 3am

1 Like

I had to reduce the document to upload, but although there are less forms it can be enough to test

Followed the steps indicated in my messages (took about 5 minutes). The result is attached.
The file should call a macro when opened

<office:event-listeners>
<script:event-listener script:language="ooo:script" script:event-name="dom:load" xlink:href="vnd.sun.star.script:facturas2.py$iniciar_programa?language=Python&location=document" xlink:type="simple"/>
</office:event-listeners>

but this macro is missing in your file.
facturas2.odb (996.8 KB)

Hi

May I suggest you have a look at event properties of ScriptForge Form and FormControl services. Those properties are editable and seem to fit your requirement.

Additionnally, BaseDocumenter may help you identify your .odb content if need be.