Esri / arcgis-osm-editor

ArcGIS Editor for OpenStreetMap is a toolset for GIS users to access and contribute to OpenStreetMap through their Desktop or Server environment.
Apache License 2.0
395 stars 129 forks source link

"Copy as Python Snippet" results in broken snippet #195

Closed Chaz6 closed 5 years ago

Chaz6 commented 6 years ago

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'
mboeringa commented 6 years ago

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

scw commented 6 years ago

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

neogeomat commented 5 years ago

I tried this code arcpy.OSMGPFileLoader_osmtools(interpreter_osm, "CONSERVE_MEMORY", "", overpass, overpass_osm_pt, overpass_osm_ln, overpass_osm_ply) and got this error TypeError: OSMGPFileLoader() takes 0 positional arguments but 7 were given

scdub commented 5 years ago

@neogeomat Add the ImportToolbox command above that @mboeringa mentions -- we have an internal bug for this, but performing the above step is a solid work-around.

neogeomat commented 5 years ago

@scdub without the ImportToolbox command it gives tool not found an error. I have the imported the toolbox and it is working (checked with arcpy.loadtoolbox). The error is related to #197