question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Copy as Python Snippet" results in broken snippet

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
scwcommented, Aug 24, 2018

@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.

1reaction
mboeringacommented, Jul 4, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found