Example
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
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...
pth <SPAN class="operator token">=</SPAN> <SPAN class="string token">"drive:\...some...\...path...\to_a.gdb"</SPAN> desc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>pth<SPAN class="punctuation token">)</SPAN> desc<SPAN class="punctuation token">.</SPAN>keys<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> dict_keys<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'catalogPath'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'FIDSet'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'baseName'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'children'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'childrenExpanded'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'connectionProperties'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'connectionString'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'currentRelease'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'dataElementType'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'dataType'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'domains'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'extension'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'file'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'fullPropsRetrieved'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'metadataRetrieved'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'name'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'path'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'release'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'workspaceFactoryProgID'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'workspaceType'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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
http://pro.arcgis.com/en/pro-app/tool-reference/environment-settings/what-is-a-geoprocessing-environment.htm
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.
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:
For anyone still trying to figure this out, you can control what Environment settings appear on the Environments tab in a Python Toolbox by editing the tool's xml metadata file adjacent to your pyt.
Hi Ted,
@TedHoward2 I am a little confused. In my case ,the XML file doesn't existed until I added the pyt file into my ArcGIS Pro (Catalog-Toolboxes-Add Toolbox). So how can this be preconfigured before I distribute the pyt file to my end user?
If the xml file exists in the same folder as the pyt, then it will be used when the toolbox is added to an ArcGIS Pro project. You must distribute both the pyt and any relevant xml files if you want the metadata help to be included for the end user.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.