Customer Service | Training | Contact Us
You are here: Home > User Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - Geoprocessing Scripting (Python, JavaScript, VB) forum

Making a selection within a Python script   Annemiek van der Veen - van Snik Sep 16, 2004
Re: Making a selection within a Python scri...   Ghislain Prince Sep 16, 2004
Re: Making a selection within a Python scri...   Paul Lohr Sep 17, 2004
Report Inappropriate Content • Top • Print • Reply    
Subject Making a selection within a Python script 
Author Annemiek van der Veen - van Snik 
Date Sep 16, 2004 
Message Hi all

I like to select 1 polygon from a shapefile and save that in a new shapefile. I'v tried several things. The code below is exported as a python script from a working model.

The debugger can't debug the following select statement
""WSD_ID" = 'MM4-2'"

How can I get this to work. I've tried changing ""WSD_ID"" to "'WSD_ID'". The code does work, only it's saving a the polygons to the new shapefile.

I hope someone can help me...

Kind regards
Annemiek van Snik 
 
# ---------------------------------------------------------------------------
# vv.py
# Created on: Thu Sep 16 2004 03:21:38 PM
#   (generated by ArcGIS/ModelBuilder)
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, win32com.client

# Create the Geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

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


# Local variables...
temp = "C:/temp"
wsd41en42_Layer = "wsd41en42_Layer"
wsd41en42_shp = "Z:/sectoraal-nat/water/watersysteemdelen_scheepvaart/wsd41en42.shp"
temp__2_ = "C:/temp"

# Process: Make Feature Layer...
gp.MakeFeatureLayer_management(wsd41en42_shp, wsd41en42_Layer, ""WSD_ID" = 'MM4-2'", "", "AREA AREA VISIBLE;PERIMETER PERIMETER VISIBLE;WSD WSD VISIBLE;WSD_ID WSD_ID VISIBLE;NAAM_WSD NAAM_WSD VISIBLE;OMSCHRIJVI OMSCHRIJVI VISIBLE;TYPE_VAARW TYPE_VAARW VISIBLE;VAN_KM VAN_KM VISIBLE;TOT_KM TOT_KM VISIBLE;STREEFD STREEFD VISIBLE;INGRIJPD INGRIJPD VISIBLE;ONDERHDP ONDERHDP VISIBLE;KPSP_NAP KPSP_NAP VISIBLE;DIEPGANG DIEPGANG VISIBLE")

# Process: Feature Class To Shapefile (multiple)...
gp.FeatureClassToShapefile_conversion("wsd41en42_Layer", temp__2_, )
 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Making a selection within a Python script 
Author Ghislain Prince 
Date Sep 16, 2004 
Message Hi Annemiek,
from python documentation: "The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. "

The Export To Script functionality at 9.0 and 9.0 Sp1 did not have this logic. We're testing this for 9.0 Sp2. In the meantime, see below for how to make it work.

Hope this helps 
 
# change this
""WSD_ID" = 'MM4-2'"

# to this
"\"WSD_ID\" = 'MM4-2'"
 
  Ghislain Prince
ESRI 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: Making a selection within a Python script 
Author Paul Lohr 
Date Sep 17, 2004 
Message Instead of: "D:/MYDIRECTORY/83104_All/msla02/Polygon".

Try:
"D:\\MYDIRECTORY\\83104_All\\msla02\\Polygon".

Perhaps using the double slashes anywhere you have a path will correct the problem.

Hope this helps. 
  Paul Lohr
Johnson Engineering, Inc.