This is for inside ArcGIS Pro but I assume it also applies to Desktop. I assume there is some way to advertise the environments in same way as the internal tools do but could not locate a single example or mention of it in the documentaion.
Thanks
This is for inside ArcGIS Pro but I assume it also applies to Desktop. I assume there is some way to advertise the environments in same way as the internal tools do but could not locate a single example or mention of it in the documentaion.
Thanks
Thanks, but that is not quite what I am looking for. I know how to get the parameters from the arcpy.env variable and do so to do things like build pyramids for generated rasters if that is the current env setting. I could duplicate all the inputs that is normally in the environments tab as inputs for my tool (with defaults being the env variable setting), but that seems needlessly cumbersome. Most of the ESRI tools that honor environment settings advertise them in the second tab. I am looking to do the same e.g.:
That is what I was saying, I do it by code. The only way you 'access' what is set is by what is set at the project level.
Arcpy can help... you can access some of these through.... arcpy's GetSystemEnvironment ... ListEnvironments plus others in that area.
As you know, at the end of each tool's help there is the list of the Environments that tool observes. If I want to ensure a specific setting, I set it. If you are creating script tools for arctoolbox, then there are environments that can be set there
http://pro.arcgis.com/en/pro-app/help/analysis/geoprocessing/basics/create-a-python-script-tool.htm
Environment | A parameter can derive its default value from a geoprocessing environment. So if the specified geoprocessing environment is set, the value will be used as the default for the given parameter when the tool's dialog box opens. |
If using tools and/or models, there is a hierarchy that is followed as discussed here
So setting things at the project level is your first course of action, then at the tool level. If you don't set anything at the tool level then whatever you did or didn't set gets passed on to the tool. Hence, my preference for setting things via code since it is easy to find what environment parameters are honored by any existing tool.
And that is what I said. I know how to do it by code and can do so, and I am not setting anything I am getting the project environment settings.
To maybe make make it clearer, I am implementing my own custom Python toolbox (.pyt file mechanism) and want to have an environments tab populated with the controls for each environment that it respects.
What I want is to advertise it in the same way as the built in tools so that the Environment tab is not empty and I do not need to needlessly duplicate every one of the parameters as inputs to my tool so that user's can both see what the tool honors and can override it if they want (e.g. pick a different output coordinate system). Less magic than the tool just using these settings in the code and replicates the experience for the built in tools.
It is very possible that this is simply not possible currently in a Python toolbox. Was just wondering if I am missing something.
Ahhhh Now I get you. Here is a custom tool that I haven't completed setting the environments for
Looks like they aren't empty but the default when you go to each is the project (aka system) level option first.
If I want it to 'show up' in there, I set it.
Set them in tool validation script is one option... setting directly in the tool's script is my preferred option...
saving and loading (LoadSettings.... from an xml stored in the same folder as the script is a 3rd option.
They are your control options.
Thanks. I will see if I can somehow load settings saved from a Custom toolbox but not sure this will work. Note I am not implementing a Custom toolbox but rather a Python toolbox. In the Python toolbox that tab is empty.
A tip...
import sys
script = sys.argv[0] # ---- for eample
script
'C:/Git_Dan/arraytools/tools.py'
xml = 'my.xml' # ---- stored in the same location as your script
pth = script.split("/")[:-1] # or "\\" for split
pth.append(xml)
pth # ----- all the bits... and everything is relative to the script
['C:', 'Git_Dan', 'arraytools', 'my.xml']
xml_path = "\\".join(pth)
xml_path
'C:\\Git_Dan\\arraytools\\my.xml'
Oh this won't work. I am interested in respecting the current settings and not loading preset constant values from an XML file. Even for custom tools one cannot seem to hide the environments that doe not apply and Using the Environments field is not really useful:
you can't hide anything... you can set stuff see my example of using an existing file...
You can even set stuff in an accompanying script and 'import' it just like any other module.
As you already discovered, you cannot hide the environment settings that are not relevant to the tool. Would be nice if that would be possible. However, you can provide a description to the end user in your tool to indicate which settings are relevant. When the user decides to change other settings, they won't effect the tool, nor other processes (since they were defined at the tool run level).
See the hierarchy in defining the environment setting What is a geoprocessing environment setting?—Geoprocessing | ArcGIS Desktop :
It would actually be better if it was a problem of note being able to hide them (as is the case with tools custom script tools created via the catalog). Once again; note I am not implementing a Custom toolbox but rather a Python toolbox. In the Python toolbox that tab is empty.
I should have probably attached the following to my original question to clear up the confusion since we seem to be caught up in discussions about custom toolboxes. Here is what my tools show:
I see... What environment settings would you like to provide to the end user in your python toolbox tool?
At this moment I want to expose the build pyramids and statistics settings, but potentially might want to add others like output coordinate system etc. I know it is possible to add an input parameter for each of the settings involved but that really bloats the input parameters unnecessarily and puts controls in the first tab (Parameters) that belong in the second (Environment).
Use a regular toolbox since you really haven't specified any real need for a python toolbox unless I am missing something from your description of the tool's purpose
There are multiple reasons for using a python toolbox outlined in: Comparing custom and Python toolboxes. My reasons align with the ones described there (e.g. maintainability as well as test-ability since validation logic is defined in Python code, value tables etc.) and I am also building a toolbox that will be installed on systems with a Pro SDK AddIn that utilizes them inside the arcgispro-py3 environment along with dependent Python packages etc. The toolbox need to appear for any ArcGIS Pro project without users needing to import them into each project.
I am familiar with the differences. I just do my validation differently. Yes, a multiuser environment can be a hastle. As for a toolbox appearing in any new project, ...at least at the single user level, ... is readily handled under Project, Options, General, Default toolbox (use the same toolbox as the default for all projects). BUT that won't help if you have several toolboxes to use.
Good luck... maybe put in an ArcGIS Idea if we haven't overlooked something simple
Thanks. I just did that. Guess I was just holding on to the fact that I might be missing some existing way to do this. I assume the internal tools uses something of this sort.
I set them and/or derive them from input parameters.
http://pro.arcgis.com/en/pro-app/tool-reference/environment-settings/current-workspace.htm begins a whole list.
If I want to set something I do it via code, so as to never leave anything to chance or by assumption.
Is there something specific you are wondering about? the arcpy.da.Describe returns lots more information in dictionary form
For example...