How to call extension from GS script with relative paths?


Extensions can currently be called using hardcoded paths, for example:
SETINI ENTRY.PARAM1=5
GX C:\Users\v.savenije\Documents\Geosoft\Desktop Applications\python\entry.py
but to distribute the gs script, all paths need to be relative of course, something like
SETINI ENTRY.PARAM1=5GX python\entry.py
But this doesn't work.
In OMN files, extensions are recognized simply file name, pointing to anything in the python folder.
How to the extension entry point with relative paths?
This functionality feels like it should be there and I am thus missing something, so therefore I am asking here.
Answers
-
Hi @VictorSavenije if i'm not mistaken reading a post earlier around this from @EmilNielsen - maybe you can help?
0 -
Hi @VictorSavenije.
I am not familiar with the ENTRY.PARAM1. I am curious with what GX function you are using it?
When calling a python script from a GS file, I simply write:
GX .\\py\my_python_script.py
Where the path is relative to the location of the project file (my_geosoft_project.gpf)
Then it is possible to distributing a project folder with the geosoft project, and a folder with the python scripts, that will not be depend on where the project folder is located.
The same holds if calling the python script from an OMN. Here it would be something like:
ITEM "Call py script" , ".\\py\my_python_script.py"
Hope that makes sense and is useful.Best,
Emil0 -
Hello Emil,
The problem with your solution is that you would need to put the extension in every project folder. All documentation of extension points at 'installing' an extension by putting it in the ../user/python folder, which also allows one to make a menu item pointing to it.
https://geosoftgxdev.atlassian.net/wiki/spaces/GXD93/pages/105775181/Create+a+Menu+to+Run+Python+Extensions
0 -
Hi Victor,
I think what Emil says makes sense because the .// can replace the root to the project directory, but your custom python extension would have to be saved in your project directory (wherever you have your *.gpf file saved). But I'm not sure how to replace the root to the User Python folder so that it calls anything in that folder, which I think is what you are asking?. I will ask one of our developers to have a look at your question.
Just to be clear, you are trying to call a custom python extension that you have saved in the following location:C:\Users\Becky.Bodger\Documents\Geosoft\Desktop Applications\python
Thanks,
Becky Bodger
Customer Solutions - Geophysics
Seequent0 -
Thanks @BeckyBodger2 for escalating the issue.
I can confirm I have a custom python extension saved in my version of
C:\Users\Becky.Bodger\Documents\Geosoft\Desktop Applications\pythonjust like documentation suggests.
If GS script are able to find files over there, just like how it is possible with OMN files, it would allow a user to record and execute these with GS just like any of the other tools in Oasis.
1 -
Hi again Victor.
I see what you are looking for.
I just tried to see if it was possible to use the %USERPROFILE%, but no luck.So, at the moment I don't have a good solution, maybe something will come up.
Best,
Emil0 -
Hi Victor,
The Geosoft registry command for varying User Names is <GEOSOFT2> the GEOSOFT2 key is set to %USERPROFILE%\Documents\Geosoft\Desktop Applications
Have you tried a variation of "<GEOSOFT2>\python"
*not sure on the syntax to use the registry keys0 -
@SeanPlener Do you know if it's theoretically possible to use the registry inside a GS script?
in any case, GX "<GEOSOFT2>\python\script.py" doesn't work because it's the variable isn't substituted.
0 -
As far as I know the only syntax possible in a GS script are the CURRENT, SETINI, INTERACTIVE, and GX commands.
0 -
@VictorSavenije I have seen it used in OMN (Custom menus)
For example the below was used to call a custom menu item:
ITEM "&DrawArrow..." ,<geosoft2>\bin\DrawArrow(Draw.ArrowProcessing;Run)I have not tested it to set the current database or Map.
0 -
@VictorSavenije I just did some quick testing and set up a new registry string GSOUT = %USERPROFILE%\Out\
I recorded a simple Gridding gsI was able to confirm that the Current would not recognize the Path to the out folder (with or without "")
CURRENT Database,<GSOUT>\testorig1.gdb
But the gs input did recognize the string
SETINI GRIDDING_TOOL_1_RANGRID.GRID="<GSOUT>\testorig_Z_0_.grd(GRD)"
Output the file to my user folder\out
Please note there is a reported issue with the registry string being truncated. The total number of characters that can be used at this time is 30 including filepath and name0 -
@SeanPlener hmm, interesting. Recall that I am actually interested in setting it in a GX command, so I point to
%USERPROFILE%\Documents\Geosoft\Desktop Applications\
which is where extensions where recommended to be stored.
0 -
hi @VictorSavenije, the GX command (for python) supports relative paths but they are relative to the project folder, not the GS file itself. This decision comes with tradeoffs, one of them being that calling a GS from two different projects might not work because the relative paths might not evaluate to the same.
But in this case, we expect the "extension" python script to be saved in some folder, and for the GS script to reference it by absolute path.
Also, unfortunately the GX command does not support environment variables ie %USERPROFILE%
0 -
Thanks @SerbanMarin1 . Would you agree it would be low hanging fruit to make it possible to call python extensions from GS scripts?
(just like it's possible to call them from omn menus items)
Could be implemented by supporting environment variables or something else.
0 -
@VictorSavenije I might be a bit missing something but you should already be able to call python extensions from GS scripts via absolute path. Supporting environment variables only means that instead of writing C:\SomeFolder\AnotherFolder\extension.py you write %MYVAR%\extension.py. In either cases you still need to either setup a env variable, or edit the GS absolute path.
In the original comment you write "but to distribute the gs script, all paths need to be relative of course". I don't see why that has to be the case. Maybe you can describe your distribution process so we get a better understanding.
0 -
@SerbanMarin1 My 'distribution process' is giving a zip a file containing a omn file and some py files and telling people to unzip it in the equivalent of C:\Users\v.savenije\Documents\Geosoft\Desktop Applications
So this one varies per user, and is problematic with absolute paths only GS scripts, because the username is inside the path. I think I landed at this location, because the error message that Oasis gives when it can't find the the python extension file points to this location ( C:\Users\v.savenije\Documents\Geosoft\Desktop Applications\python )
1 -
@SerbanMarin1 Could you confirm where python extensions should be stored?
The documentation seems to point at two different places:
1)
"Place this in ../user/python folder:"
Which I guess is normally in C:\Program Files\Geosoft\Desktop Applications\user\python
But I don't get this method to work.
In contrast, this page
2)
says to store in %USERPROFILE%\Documents\Geosoft\Desktop Applications\python
which is what I have been doing. This contains %USERPROFILE% and therefore a path that is different per user, which is what this post is all about.
0