"Copy as Python Snippet" results in broken snippet
See original GitHub issueI have run the GP tool "“Load OSM File”, and used the “Copy as Python Snippet” command, resulting in the following:-
arcpy.OSMGPFileLoader_osmtools(in_osmFile="[*.osm]", in_conserveMemory="CONSERVE_MEMORY", in_attributeselect="", out_targetdataset="[target.gdb/layer]", out_osmPoints="[target.gdb/layer/layer_osm_pt]", out_osmLines="[target.gdb/layer/layer_osm_ln]", out_osmPolygons="[target.gdb/layer/layer_osm_ply]")
When trying to use this in the Python window, the following error is given:-
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'OSMGPFileLoader_osmtools'
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Where is Copy As Python Snippet of ArcGIS Pro?
After running a tool from the Geoprocessing pane, I found that I could right click on the successful run at the bottom (in...
Read more >Copy as Python Snippet without running tool
In the geoprocessing results window, you can right-click on a result and select Copy as Python Snippet. This is very handy when writing ......
Read more >Copying and pasting code into the Python interpreter
You can usually easily and safely do copy-pasting with IPython, through the commands %cpaste (manually end code with -- ) and %paste ...
Read more >Use Python code snippets—ArcGIS Notebook Server
Use Python code snippets in the ArcGIS Notebooks Editor. ... select the cell you want to add as a code snippet and click...
Read more >100 Python Code Snippets for Everyday Problems
Input/Output (12 Snippets) · Printing on the Same Line · Making a Python Script Shortcut · Checking if a File Exists · Parsing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Chaz6 As @mboeringa mentions, there is an open internal issue for this – the additional step being the ImportToolbox that currently “Copy as Python Snippet” doesn’t correctly auto-generate.
@Chaz6 ,
Although ESRI provides this kind of “convert to Python” code auto-conversion, e.g. also with ModelBuilder toolboxes, the result is rarely directly usable, and you always need to review the resulting code and generally make changes.
This is a known issue, and I guess conversions like this are simply not so straightforward given the rich language Python represents.
Anyway, in your case, I thinks you simply need to add an import toolbox statement as the first line in your code snippet, so before the actual tool call, like you can see in this other thread that does something similar: https://github.com/Esri/arcgis-osm-editor/issues/194
So add this:
arcpy.ImportToolbox(r'c:\program files (x86)\arcgis\desktop10.6\ArcToolbox\Toolboxes\OpenStreetMap Toolbox.tbx'
Just take care of the proper version number of your ArcGIS install to not break the path to the toolbox.