0

If my question does not make sense or needs clarification please let me know. I am struggling to solve it so I was struggling to phrase it into a question.

I have this code here:

import arcpy,os
from arcpy import env

#Name .gdb and set location. This will create the .gdb
out_folder_path = ("C:/Users..../Documents/test")
out_name= "Test.gdb"
arcpy.CreateFileGDB_management(out_folder_path, out_name)

# This will load the .xml into the .gdb created above
target_gdb = "C:/Users/..../Documents/test/Test.gdb"
in_file = "C:/Users..../MASTER.xml"
import_type = "DATA"
config_keyword = "DEFAULTS"

# Execute ImportXMLWorkspaceDocument
arcpy.ImportXMLWorkspaceDocument_management(target_gdb, in_file, import_type)

I am struggling to convert this into a tool. The problem I am encountering is I want the user to just set the .env settings, then input the database name and then location. Then the tool will take over and create the file gdb and then load the .xml workspace into it. The .xml workspace has been hardcoded to a certain location. I am just struggling with the target_gdb for the .xml import. It does work as is with hardcoded locations and for one time use. But for those who do are not python saavy having to change code everytime is not feasible. Again I want this to become a tool.

I did find this formum: Automating script to set geodatabase?

but this just confused me even more.

Updated code:02/4/14

import arcpy,os
from arcpy import env

Name .gdb and set location. This will create the .gdb

out_folder_path = arcpy.GetParameterAsText(0)
out_name= arcpy.GetParameterAsText(1)
arcpy.CreateFileGDB_management(out_folder_path,out_name)

This will load the .xml into the .gdb created above

target_gdb = out_folder_path + os.path.basename(out_name)
in_file = "C:/Users/.../MASTER.xml"
import_type = "DATA"
config_keyword = "DEFAULTS"

Execute ImportXMLWorkspaceDocument

arcpy.ImportXMLWorkspaceDocument_management(target_gdb, in_file, import_type)
  • So you want the script-tool to get input from the user? You probably want GetParameterAsText() (see doc). – Roland Feb 3 '14 at 23:56
  • Thanks for your help. I was able to get here this morning. It will create the .gdb, but errors out when loading the .xml into it. I need to point it to the .gdb that was just created. I have been playing around with os. If you have any more links you can point me to, that would be great. – T.J. Feb 4 '14 at 14:45
  • Are you defining the "folder" parameter for outpath and "string" for out_name? – Aaron Feb 4 '14 at 15:55
1

I was able to write a working script that I then converted into a tool. This will create a file gdb and then load in the XML workspace that was created from another .gdb. The tool asks the user to input the Location to save and give it a name. Thank you everyone for your help.

import arcpy,os from arcpy import env

Name .gdb and set location. This will create the .gdb

out_folder_path = arcpy.GetParameterAsText(0)
out_name= arcpy.GetParameterAsText(1)
arcpy.CreateFileGDB_management(out_folder_path,out_name)

This will load the .xml into the .gdb created above

target_gdb = out_folder_path + os.path.sep + out_name+".gdb"
in_file = "C:/Users/.../MASTER.xml"
import_type = "DATA"
config_keyword = "DEFAULTS"

Execute ImportXMLWorkspaceDocument

arcpy.ImportXMLWorkspaceDocument_management(target_gdb, in_file, import_type)
  • I just replicated this and also noticed that the ".gdb" was missing. I like using arcpy.AddMessage() to print variables to the foreground procesing window and check the string to make sure they are accurate. – Adam Feb 4 '14 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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