sbfly

Model builder scribt export to Phyton

Discussion created by sbfly on Jun 26, 2011
Latest reply on Jun 27, 2011 by sbfly
Why does the following scribt not work ?
# ---------------------------------------------------------------------------
# test.py
# Created on: Mi Jun 22 2011 11:23:51 
#   (generated by ArcGIS/ModelBuilder)
# Usage: test <o_90> <min_row> <max_row> <Zeile> <O> 
# ---------------------------------------------------------------------------

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

# Create the Geoprocessor object
gp = arcgisscripting.create()
# 
gp.SetProduct("ArcInfo") # or ArcEditor or ArcInfo
gp.overwriteoutput = 1



# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.AddToolbox("C:/Program Files/ET GeoWizards 9.9 Floating/ET GeoWizards.tbx")

#script arguments


orbit = "D:/f/Cap/tanProblem/output/o_90.lyr"
O1_mollw_90 = "o_90"
O1_mollw_90_1_Dissolve_shp = "D:/figwer/Capacity/tandem Problem/input/orbit_90_Dissolve.shp"
tan_shp = "D:/figwer/Cap/tanProblem/output/new/tan.shp"
O1_mollw_90_1_Dissolve_shp__2_ = "D:/f/Cap/tanProblem/input/o_90_Dissolve.shp"
#read row of txt file

f=open("D:/f/Cap/tanProblem/Test_o1.txt","r")

for line in f.readlines():  #in huge file f.xreadlines maybe to use

    werte = line.split('\t')# für tab-separate
    min_row = werte[4]
    max_row = werte[5]
    index   = werte[0]
    O   = werte[3]

    if O == "O":
        continue

    O = int(O)
    min_row = int(min_row)
    max_row = int(max_row)

    print "min_row=%s, max_row=%s, index=%s, O=%s" % (min_row, max_row, index, O)


    Expression = "\"FID\" >= %d+90*(%d-1) AND \"FID\" <= %d+90*(%d-1)" % (min_row, O, max_row, O)
    #Expression = "\"FID\" >= %min_row%+90*(%O%-1) AND \"FID\" <= %max_row%+90*(%O%-1)"
    Expression_2 = "%index%-3"
    

# Process: Select Layer By Attribute...,
    gp.makefeaturelayer(o, "walk")
    gp.SelectLayerByAttribute_management ("walk" , "NEW_SELECTION", Expression)
#----------------------------------------------------------------------------------------
    #übergabe funktioniert nicht 
#----------------------------------------------------------------------------------------
 # Process: Dissolve...
    gp.Dissolve_management("walk", O1_mollw_90_1_Dissolve_shp, "FID", "", "MULTI_PART", "DISSOLVE_LINES")

# Process: Calculate Field...
    gp.makefeaturelayer(O1_mollw_90_1_Dissolve_shp, "walk2")

    gp.CalculateField_management("walk2", "Id", Expression_2, "VB", "")

# Process: ET Select And Export...
    gp.toolbox = "C:/Program Files/ET GeoWizards 9.9 Floating/ET GeoWizards.tbx";
    gp.ET_GPSelectAndExport("walk2", tan_shp, "")
   




Outcomes