0

I'm doing an internship, and they want me to organize their data. I decided to do a script that would create the folders based on user input and stuff so once I'm gone they'll still be able to use it. Everything works really well until I get to maps. I get error messages, as seen at the bottom of the code. I'd like to have the folder created be the area the map is saved to. It's been a year since I took Python for GIS so I'm a little bit rusty and I can't quite figure out what the problem is.

Could I get some help figuring out exactly what I'm doing wrong?

I've also tried replacing folder in the .saveACopy with (folder_location+folder_name). The process runs, but no map shows up.

import arcpy,os

# Create a folder and geodatabase
#local variables
folder_location= raw_input("please write where you want the folder to be.")
folder_name=raw_input("Please name your folder.")

folder=arcpy.CreateFolder_management(folder_location,folder_name)
##Create GDB:

# Set local variables

out_name = raw_input("Please choose a name for your GeoDataBase.")

# Execute CreateFileGDB
arcpy.CreateFileGDB_management(folder, out_name)
mxdname=raw_input("Please create a map name.")
#Choose the mxd
mxd=arcpy.mapping.MapDocument(r"z:/MaryGIS/Testmap.mxd")
mxd.saveACopy( folder + mxdname+".mxd")

The error I get is: Traceback (most recent call last): File "Z:/Python labs/CreatefileGDB.py", line 24, in mxd.saveACopy( folder+mxdname+".mxd") TypeError: unsupported operand type(s) for +: 'Result' and 'str'

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
m.odell
  • 25
  • 5

1 Answers1

2

The line folder=arcpy.CreateFolder_management(folder_location,folder_name) is outputting a Result Object into your folder variable, not a folder name like C:\Temp.

For your mxd.saveACopy() line, try concatenating the folder location, folder name and mxd name together:

mxd.saveACopy(os.path.join(folder_location, folder_name, "{0}.mxd".format(mxdname)))
Midavalo
  • 29,696
  • 10
  • 48
  • 104