Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I created a model in python that clips and converts different data sets into DWG based on the the grid number. I will like the DWG data (Output) to go into the folder I created as part of the geoprocessing.

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")

# Set the Geoprocessing environment...
gp.overwriteOutput = 1
gp.autoCommit = "1000"
gp.XYResolution = ""
gp.XYDomain = ""
gp.scratchWorkspace = ""
gp.MTolerance = ""
gp.randomGenerator = "0 ACM599"
gp.outputCoordinateSystem = ""
gp.ZDomain = ""
gp.snapRaster = ""
gp.configKeyword = ""
gp.outputZFlag = "Same As Input"
gp.qualifiedFieldNames = "true"
gp.extent = "MAXOF"
gp.XYTolerance = ""
gp.MDomain = ""
gp.spatialGrid1 = "0"
gp.outputZValue = ""
gp.outputMFlag = "Same As Input"
gp.geographicTransformations = ""
gp.spatialGrid2 = "0"
gp.ZResolution = ""
gp.spatialGrid3 = "0"
gp.MResolution = ""
gp.ZTolerance = ""
mapNO = "035A2" 

# Script arguments...

Expression = "MAPNO = '" + mapNO + "'" 
# Local variables...
grid = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\grid"
GRID_200SCALE = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\GRID_200SCALE"
BuildingAnno = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\BuildingAnno"
Building = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\Building"
Building_DWG = "C:\\Export\\Completed\\Building_" + mapNO + ".DWG"
BUILDING__2_ = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\BUILDING"
BUILDING_ANNO = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\BUILDING_ANNO"
Contours__2_ = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\Contours"
ContourAnno = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\ContourAnno"
Contours_DWG = "C:\\Export\\Completed\\Contours_" + mapNO + ".DWG"
CONTOURS = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\CONTOURS"
Rec = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\Rec"
RecAnno = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\RecAnno"
RecAnno__3_ = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\RecAnno"
Rec_DWG = "C:\\Export\\Completed\\Rec_" + mapNO + ".DWG"
CONTOUR_ANNO = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\CONTOUR_ANNO"
Rec__2_ = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\Rec"
CommTowers = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\CommTowers"
COMMUNICATION_TOWERS = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\COMMUNICATION_TOWERS"
Comm_DWG = "C:\\Export\\Completed\\Comm_" + mapNO + ".DWG"
CultAnno = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\CultAnno"
CultAnno__2_ = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\CultAnno"
Cult = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\Cult"
Cultural = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\Cultural"
Cultural_DWG = "C:\\Export\\Completed\\Cultural_" + mapNO + ".DWG"
HydroAnno = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\HydroAnno"
HYDROLOGY_ANNO = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\HYDROLOGY_ANNO"
HydroL = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\HydroL"
HydroP = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\HydroP"
HYDROLOGY_LINE = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\HYDROLOGY_LINE"
HYDROLOGY_POLY = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\HYDROLOGY_POLY"
Hydro_DWG = "C:\\Export\\Completed\\Hydro_" + mapNO + ".DWG"
Rail = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\Rail"
Rail__2_ = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\Rail"
RailAnno = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\RailAnno"
RailAnno__2_ = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\RailAnno"
Rail_DWG = "C:\\Export\\Completed\\Rail_" + mapNO + ".DWG"
Road = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\Road"
ROAD__2_ = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\ROAD"
RoadAnno = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\RoadAnno"
ROAD_ANNO = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\ROAD_ANNO"
Road_DWG = "C:\\Export\\Completed\\Road_" + mapNO + ".DWG"
Trans = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\Trans"
Transmission = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\Transmission"
Trans_DWG = "C:\\Export\\Completed\\Trans_" + mapNO + ".DWG"
Veg = "C:\\Export\\Geodatabases\\Planimetrics.gdb\\Veg"
Veg_DWG = "C:\\Export\\Completed\\Veg_" + mapNO + ".DWG"
Vegetation = "C:\\Export\\BaltimoreAppendedFINALDB.gdb\\PLANIMETRIC\\Vegetation"
MAPNO____001A3_ = "C:\\Export\\Completed\\MAPNO = '" + mapNO +"'"          #### what does this do ?????????????????
Completed = "C:\\Export\\Completed"##########This should contain the expression/concatination that inserts data into its folder                                                                                                                                      


# Process: Select...
gp.Select_analysis(GRID_200SCALE, grid, Expression)

# Process: Clip (3)...
gp.Clip_analysis(BUILDING__2_, grid, Building, "")

# Process: Clip (2)...
gp.Clip_analysis(BUILDING_ANNO, grid, BuildingAnno, "")

# Process: Create Folder...
gp.CreateFolder_management(Completed, Expression) ######### This should go on top /// Replace this with a create folder function I already created ?????????????

# Process: Export to CAD...
gp.ExportCAD_conversion("C:\\Export\\Geodatabases\\Planimetrics.gdb\\Building;C:\\Export\\Geodatabases\\Planimetrics.gdb\\BuildingAnno", "DWG_R2000", Building_DWG, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")

# Process: Clip (5)...
gp.Clip_analysis(CONTOURS, grid, Contours__2_, "")

# Process: Clip (4)...
gp.Clip_analysis(CONTOUR_ANNO, grid, ContourAnno, "")

# Process: Export to CAD (2)...
gp.ExportCAD_conversion("C:\\Export\\Geodatabases\\Planimetrics.gdb\\Contours;C:\\Export\\Geodatabases\\Planimetrics.gdb\\ContourAnno", "DWG_R2000", Contours_DWG, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")

# Process: Clip (6)...
gp.Clip_analysis(Rec__2_, grid, Rec, "")

# Process: Clip (7)...
gp.Clip_analysis(RecAnno__3_, grid, RecAnno, "")

# Process: Export to CAD (3)...
gp.ExportCAD_conversion("C:\\Export\\Geodatabases\\Planimetrics.gdb\\Rec;C:\\Export\\Geodatabases\\Planimetrics.gdb\\RecAnno", "DWG_R2000", Rec_DWG, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")

# Process: Clip (8)...
gp.Clip_analysis(COMMUNICATION_TOWERS, grid, CommTowers, "")

# Process: Export to CAD (4)...
gp.ExportCAD_conversion("C:\\Export\\Geodatabases\\Planimetrics.gdb\\CommTowers", "DWG_R2000" , Comm_DWG, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")

# Process: Clip (9)...
gp.Clip_analysis(CultAnno__2_, grid, CultAnno, "")

# Process: Clip (10)...
gp.Clip_analysis(Cultural, grid, Cult, "")

# Process: Export to CAD (5)...
gp.ExportCAD_conversion("C:\\Export\\Geodatabases\\Planimetrics.gdb\\CultAnno;C:\\Export\\Geodatabases\\Planimetrics.gdb\\Cult", "DWG_R2000", Cultural_DWG, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")

# Process: Clip (11)...
gp.Clip_analysis(HYDROLOGY_ANNO, grid, HydroAnno, "")

# Process: Clip (12)...
gp.Clip_analysis(HYDROLOGY_LINE, grid, HydroL, "")

# Process: Clip (13)...
gp.Clip_analysis(HYDROLOGY_POLY, grid, HydroP, "")

# Process: Export to CAD (6)...
gp.ExportCAD_conversion("C:\\Export\\Geodatabases\\Planimetrics.gdb\\HydroAnno;C:\\Export\\Geodatabases\\Planimetrics.gdb\\HydroL;C:\\Export\\Geodatabases\\Planimetrics.gdb\\HydroP", "DWG_R2000", Hydro_DWG, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")

# Process: Clip (14)...
gp.Clip_analysis(Rail__2_, grid, Rail, "")

# Process: Clip (15)...
gp.Clip_analysis(RailAnno__2_, grid, RailAnno, "")

# Process: Export to CAD (7)...
gp.ExportCAD_conversion("C:\\Export\\Geodatabases\\Planimetrics.gdb\\Rail;C:\\Export\\Geodatabases\\Planimetrics.gdb\\RailAnno", "DWG_R2000", Rail_DWG, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")

# Process: Clip (16)...
gp.Clip_analysis(ROAD__2_, grid, Road, "")

# Process: Clip (17)...
gp.Clip_analysis(ROAD_ANNO, grid, RoadAnno, "")                                                                                                                                                                        

# Process: Export to CAD (8)...
gp.ExportCAD_conversion("C:\\Export\\Geodatabases\\Planimetrics.gdb\\Road;C:\\Export\\Geodatabases\\Planimetrics.gdb\\RoadAnno", "DWG_R2000", Road_DWG, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")

# Process: Clip (18)...
gp.Clip_analysis(Transmission, grid, Trans, "")

# Process: Export to CAD (9)...
gp.ExportCAD_conversion("C:\\Export\\Geodatabases\\Planimetrics.gdb\\Trans", "DWG_R2000", Trans_DWG, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")

# Process: Clip (19)...
gp.Clip_analysis(Vegetation, grid, Veg, "")

# Process: Export to CAD (10)...
gp.ExportCAD_conversion("C:\\Export\\Geodatabases\\Planimetrics.gdb\\Veg", "DWG_R2000", Veg_DWG, "Ignore_Filenames_in_Tables", "Overwrite_Existing_Files", "")
share|improve this question
1  
So, are you trying to create a unique folder for each DWG export, or just one folder that all of the DWGs get dumped in? If it's the latter, then definitely put your folder creation code at the top before you do any geoprocessing. Also, what is the naming basis for the folder(s)? –  Baltok Mar 9 '12 at 23:37
add comment

1 Answer

Where are the outputs going?

You may want to try putting 'r' in front of your file paths like this:

BASE_PATH = r"C:\Export\Completed"
...
Building_DWG = os.path.join(BASE_PATH, "Building_" + mapNO + ".DWG")
Contours_DWG = os.path.join(BASE_PATH, "Contours_" + mapNO + ".DWG")

(You could tidy this code up a lot too, perhaps using a list and a list comprehension to do the joins since there is so much repetition, but this will work and is simple for explanation purposes). The 'r' tells Python that your string is raw, so it treats the backslashes as backslashes and not escape characters. Both '\e' and '\c' are escapes and this can give you problems with your paths, if nothing else. The alternative (less pythonic) is to manually 'escape' your backslashes like this:

BASE_PATH = "C:\\Export\\Completed"

...but that gets messy quickly. However, it might be easier for a global search and replace operation if you don't want to refactor your code to be prettier and more compact.

I would test your process with something much more compact than your code above to be sure this is your problem.

The bit where you say "what does this do?" (vegetation, at the end of your local variables). It does nothing. That is, you are adding a null string to the end of your path. It is unnecessary but should be harmless so long as you don't need an extension that is (I don't know what this output is meant to be)!

The next comment is also fine because it is just a variable for your path and that variable is referenced when you create the folder later on (where you say 'This bit should go on top'). The data are placed in the folder by the processes. That huge string of variables are the paths and they all seem to contain the correct path (except for the possible escapes).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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