-1

The question I am seeking an answer to: If I make several layers with MakeFeatureLayer_Management(), is there a way to programmatically search for and list the names of the layers created? (Without the need of creating actual .lyr files)

Bonus Question: Where does MakeFeatureLayer_Management() actually make the layers?

At first I thought it would be something like "in_memory" but that is more like a temporary geodatabase, not a temporary mxd. Is there an in memory mxd that is being created? if so, is it an object i can interact with?

EDIT:

When I try to use ReconcileVersions it does not delete the version if i have a layer that was created referencing the version.

Do I really need to use ChangeVersion_Management() to change the layer to some other version just to delete it?

closed as too broad by PolyGeo Jul 5 '18 at 20:05

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Since the name of the feature layer is a required input to the tool, I'd suggest just creating a list of the feature layers you're creating, as you create them. – smiller Jul 5 '18 at 13:58
  • Yeah this is what I am doing. I was hoping there was a way to collect the data just to help prevent user error. – MTorres Jul 5 '18 at 14:29
1

When you run this tool either in an IDE outside ArcMap or within ArcMap (may be as a tool/model/python console) it creates an object that you can think of as floating around in the memory of the computer. IN_MEMORY as you correctly identify is a special type of Workspace for storing temporary datasets, it does not store layer objects.

The reason why you get a layer added to your table of contents in ArcMap is because you set the geo-processing environment to automatically add the output of any tool to the map.

So you can have layers in an MXD which you added yourself or you created via the make featurelayer tool. Only if you save the MXD do they persist and when you open the MXD they are created again and visualised.

I know of no way of asking if a layer object was created by a tool or simply added to the map by you. This would require a property to exist to record this and that does not exist to my knowledge.

  • Sorry i wasn't clear. I'm not explicitly looking for layers that were created using MakeFeatureLayer(), more so that when you use that method it creates the layer object and puts it "somewhere" that isn't an MXD. The only way i could figure to say it is to describe it as layers made using MakeFeatureLayer() – MTorres Jul 5 '18 at 14:27
  • In that case I would say you are asking how python stores objects and controls their lifetime, I think you are getting into the realms of memory stacks/heaps and garbage collection and not really a GIS related question. – Hornbydd Jul 5 '18 at 14:32
  • I figured it had something to do with the way that ArcPy, and by extension ESRI, wrote the libraries. The layer is referenced using a string "thisLayer" and not a memory reference. This led me to believe that there is some sort of workspace that arcpy creates that services as an in_memory.mxd . I guess another question would be, How would you delete or 'remove' a layer you created using CreateFeatureLayer_Management()? – MTorres Jul 5 '18 at 14:40
  • 1
    Please try to refrain from asking multiple questions in the same post. But, you can just delete the layers using delete management, by name. e.g. arcpy.Delete_management("stringnameoflayer") – smiller Jul 5 '18 at 14:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.