I want to have an interactive Input layer for a tool in a python Toolbox. I'm only interested in the geometry the user specified, other attributes don't matter.
This is what I have now:
def getParameterInfo(self):
p1 = arcpy.Parameter(name = "point", displayName = "bla", datatype = "GPFeatureRecordSetLayer", parameterType = "Required", direction = "Input")
# get target layer from MapDocument and create a temporary copy
mxd = arcpy.mapping.MapDocument("CURRENT")
layer = arcpy.mapping.ListLayers(mxd, "layer_name")
temp_path = "Path:\\to\\layer.lyr"
layer.saveACopy(temp_path)
# assign the layer to p1
p1.value = temp_path
return [p1]
That works, but it's very cumbersome (it's slow, there has to be a layer with the geometry I want in the map, I can't hardcode the layer path, because I can't be sure the user has write permissions (and I can't save it to in_memory), and I would have to delete the layer to avoid cluttering random directories).
Is it possible to create a point (or line or whatever) layer file on the fly? Or can I somehow save a layer with the python modules and reference it in the script?
Have a great day!
Johannes