Select to view content in your preferred language

Model builder scribt export to Phyton

619
1
06-26-2011 11:24 PM
Florianflo
Emerging Contributor
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, "")
   




Tags (2)
0 Kudos
1 Reply
Florianflo
Emerging Contributor
i solved the problem by myself
# 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")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx")
#script arguments


#orbit = "D:/f/Cap/tanProblem/output/o_90.lyr"
orbit = "D:/f/Cap/tanProblem/input/o_90.shp"
O1_mollw_90 = "o_90"
O1_mollw_90_1_Dissolve_shp = "D:/f/Cap/tandem Problem/input/o_90_Dissolve.shp"
tandem_shp = "D:/f/Cap/tanProblem/output/new/tan.shp"
tandem_Copy_shp = "D:/f/Cap/tanProblem/output/new/tan_Copy.shp"
#add join
tap_dbf = "D:/f/Cap/tanProblem/Test_o1.dbf"
v90_output = "D:/f/Cap/tanProblem/output/new"
Output_Feature_Class = "D:/f/Cap/tanProblem/output/90_output/tan_CopyFeatures.shp"
#read row of txt file

f=open("D:/f/Capa/tanProblem/Test_o13.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 Orbit == "O":
        continue

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

    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 = "%d-3" % (index)
    

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

    
    gp.makefeaturelayer(O1_m_90_1_Dissolve_shp, "walk2")
#  Process: Calculate Field...    
    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", tandem_shp, "")
   
    gp.makefeaturelayer(tandem_shp, "tan")
# Process: Add Join...
    gp.AddJoin_management("tan", "FID", tap_dbf, "OID", "KEEP_COMMON")
  
# Process: Feature Class To Shapefile (multiple)...
    gp.CopyFeatures_management("tan", Output_Feature_Class, "", "0", "0", "0")
    #gp.DeleteField_management(Output_Feature_Class, "Id;ET_ID;Test_o;Test_o_1;Test_o_4;Test_o_5")
    gp.FeatureClassToShapefile_conversion(Output_Feature_Class, v90_output)
0 Kudos