Hi, this is day 3 of my Python experience and what I have so far works but results in a disorganized, cluttered mess in my map document. I need to clean it up before I go any further and get things any more complicated. I suspect I will shove a lot of questions into one blog post so I will number them as I go to make responding easy.
I have been reading about the os package and arcpy.mapping and arcpy.env and workspaces and default GDBs and things.
- So far, I have been writing my code in PyCharm and copy/pasting it into the ArcGIS Python window so I can check that it works. arcpy.GetParameterAsText(0) does not ask for my input whether I run it in PyCharm or ArcGIS. Is that something that only works when creating a script tool?
- Can you set the default GDB in python or is that something that HAS to happen when the map is created?
- Does os.makedirs() accept a full file path or does it have to reference the current directory? I would like the user to input the .mxd file and use indexing to remove the .mxd extension to create a folder with the same name as the map document, and again to create a scratch folder. ... And also I want to create a GDB with the same file path and name (for the default GDB).
- When running my scripts, I found that most of my files went into the default GDB but one went into my scratch folder. Is there a rhyme or reason for determining where the intermediate files go? I would like the useful files to go into the default GDB and the intermediate files to go into the scratch folder. After the workspace is established, can I specify where I want created files to go in the workspace by shortening the file path to something like "/MapDocument/MapDocument.gdb/Polygon" or "MapDocument/scratch/Polygon"? where Polygon is the name of an intermediate shapefile?
- Is there a way to stop the intermediate files from being added to the Map Document automatically? As a follow up to number 5, if I turn automatic addition off in the environments, how do I add one to the map? Arcpy.mapping.AddLayer() or something else?
- Is there a way to add a group layer to the map without having to create a blank group layer and saving it and referencing it? That does not seem good for automation.
- Similarly, how would I modify arcpy.mapping.MoveLayer() to move a layer into a group layer?