Python script runs but doesn't change anything

2890
8
Jump to solution
04-28-2015 08:28 AM
Jim_Gay
New Contributor III

I have been doing some testing with models that I want to schedule and to start with I created a basic model that only creates a feature class within one of my file geodatabases.

My toolbox name is: CDWGeocoding

The alias name is: CDWGeo

Model name: ImportTest

This model has no parameters.

I've been running the following script (which completes just fine).  The problem is the feature class is not being created.  This runs fine with ArcGIS just not when running through a script.

import arcpy

import os

from datetime import datetime

print("Starting toolbox import.....")

arcpy.ImportToolbox(r"C:\Users\JOEBOBSMITH\Documents\ArcGIS\CDWGeocoding.tbx")

print("Import Complete")

print("Model executing.....")

try:

#CDWGeo is the toolbox alias

    arcpy.ImportTest_CDWGeo

    print("Model complete.")

except:

    print arcy.GetMessages(2)

I've been using this page as a reference:

Scheduling a Python script or model to run at a prescribed time | ArcGIS Blog

Does anyone see any problems with this script?  It seems pretty straight forward and simple.  I'm sure it's something simple that I am missing.  Thanks!

0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

You are calling your function as a property of arcpy, not a function (not sure why it doesn't give an error, but it's not doing what you think it's doing). It should be:

arcpy.ImportTest_CDWGeo()

View solution in original post

8 Replies
SepheFox
Frequent Contributor

It's hard to tell without seeing the model or the toolbox, but is it printing all the messages? What about the final GetMessage?

0 Kudos
Jim_Gay
New Contributor III

All messages are being printed.

python_ss.jpg

I can post an image of the model shortly.  It's just the one tool to create the feature class.  Very basic.

0 Kudos
Jim_Gay
New Contributor III

Here is the model in questions:

python_model.jpg

Properties of create feature class:

python_props.jpg

0 Kudos
SepheFox
Frequent Contributor

I'm wondering if the feature class is being created, but not where you expect it to. I think you need to set the workspace in the python script.

0 Kudos
Jim_Gay
New Contributor III

I tried adding this piece of code but the results are still the same:

#Set workspace

uri = r"C:\Users\JOEBOBSMITH\Documents\ArcGIS\PDADEV.gdb"

arcpy.env.workspace = uri

0 Kudos
DarrenWiens2
MVP Honored Contributor

You are calling your function as a property of arcpy, not a function (not sure why it doesn't give an error, but it's not doing what you think it's doing). It should be:

arcpy.ImportTest_CDWGeo()
Jim_Gay
New Contributor III

Sometimes it takes a village!  Thank you.  Working perfectly now. 

curtvprice
MVP Esteemed Contributor

It doesn't give an error because if you enter a function without the () Python will simply return the text representation of the object "arcpy.method".  (The method has been imported, so it exists, so no error.)