|
POST
|
Whenever I tried it exactly as you have it typed in your example, I get the following error.
... View more
07-01-2015
12:13 PM
|
0
|
4
|
4453
|
|
POST
|
I have background GP disabled. I leave it like that because there are parts of my script that export a table to an Excel sheet, and the tools for Excel functionality are not compatible with 64bit processing. Details on that are here. I added a script tool to a normal toolbox that references the .py document.
... View more
07-01-2015
12:00 PM
|
0
|
0
|
4453
|
|
POST
|
From what I can understand of your example, which may very well be incorrect, is that the result would fill the desired field with the literal text string of " + region + ", instead of the two digit region abbreviation that the mapName[:2] gives me. In the example I pasted in my original posting, if I use 'region' or "region" instead of just region, then it runs through just fine and updates my field with the literal string that I quoted, and not the value given to region earlier in the script.
... View more
07-01-2015
11:41 AM
|
0
|
8
|
4453
|
|
POST
|
I keep getting an error that says that my variable (region) is not defined. Please see the code below: # Set local variables
mapName = str(mxd.filePath).split('\\')[-1:][0][:-4]
region = mapName[:2]
inTable = nodeFeatures
inField = "CUSTRegion"
expression = "Reclass (!CUSTNodeID!, !CUSTRegion!)"
codeBlock = """def Reclass (CUSTNodeID, CUSTRegion):
if CUSTNodeID != None:
return region
else:
return None"""
# Execute CalculateField
arcpy.CalculateField_management(inTable, inField, expression, "PYTHON_9.3", codeBlock) The variable "mapName" grabs the name of the map and turns it into a string. The map name has 4 parts REGION - STATE - PROJECT - CUSTOMER. The variable "region" takes the mapName variable and grabs the first two characters, which is the abbreviated region code ("NC", "NE", etc...) I originally had these two variables at the top of the script just under where I import the modules, but I thought that I would move them down closer to the process that uses them hoping it would help (I'm still pretty green with Python so I'm not even sure if it matters where the variable is located). I put it at the top to begin with because there are A LOT of process in the whole script that use the same variables. I can run this script in the Python window just fine, but when I create a python tool in a toolbox, I keep getting the error that says that the variable "region" is not defined. I've tried it with replacing "region" with "mapName[:2]" and that just returns saying that "mapName" is undefined. I tried using "str(region)" and "str(mapName[:2])" to no avail. Do I need to move the variables somewhere or change some sort of defining operator or something?
... View more
07-01-2015
10:14 AM
|
0
|
10
|
8417
|
|
POST
|
Duly noted for future reference. I ended up resolving the issue, though. Please see the code pasted below. Thanks again for your help in this thread and all others. I've seen your name quite a bit in some of my threads, so thank you for all of your time.
... View more
06-29-2015
01:32 PM
|
0
|
0
|
2460
|
|
POST
|
I was looking at this the wrong way. I was assuming that the error was referring to the input table that was incorrect, but it was actually referring to the output file as being incorrect. Instead of simply giving the output a name, I gave it a save location with a name, and it worked just fine. See the code below: # Set local variables
inTable = outTable
outXLS = kmfFolder + "/general_KMF.xls" #this is where I had to give the file path and then the file name
# Execute TableToExcel
arcpy.TableToExcel_conversion(inTable, outXLS)
ersion(inTable, outXLS)
... View more
06-29-2015
01:29 PM
|
0
|
0
|
8426
|
|
POST
|
I moved past this portion of the script and on to a different part that pulls the feature classes exactly how they are in the map and does the exact same thing (TableToTable and then TableToExcel). That part works just fine, so I'm thinking that there's no compatibility issues going on. # Export TableToTable & TableToExcel
# Set Local Variables
exportTable = updatedTable # This table is the result of the summary statistics tool in the previous step
exportLoc = kmfFolder + "/" + outKMFgdb
outTable = "general_KMF"
outXLS = "general_KMF.xls"
# Execute TableToTable
arcpy.TableToTable_conversion(exportTable, exportLoc, outTable, "", "", "") # this part works fine
# Set Local Variables
inTable = outTable # hoping to grab the result of the TableToTable function above
# Execute TableToExcel
arcpy.TableToExcel_conversion(inTable, outXLS) In this instance, the TableToExcel keeps kicking back saying that the file type is invalid just as it did before, though. I've tried various ways of setting the inTable variable in line 13, but none of them have worked. I also tried to create a table view between the two tool functions and it still said invalid file type. I can't hard code the variable name because the location will be variable depending on the name of the map. Essentially the kmfFolder variable grabs the maps file location and adds a few characters that are standard between maps, and that is where everything is saved for the current map document. Examples of what I've tried using for the inTable variable: inTable = outKMFgdb + "/" + outTable inTable = exportLoc + "/" + outTable inTable = (combo of all above) + "/general_KMF" inTable = (combo of all above) + "/general_KMF.dbf" etc... *NOTE*: I intend on implementing the os.path.join suggestion mentioned above, but I'm just trying to get it working for now. Since the method I am using works in other areas of the script, especially in areas that due essentially the same thing, I don't think it's what's causing this particular issue.
... View more
06-29-2015
11:16 AM
|
0
|
2
|
2460
|
|
POST
|
Okay, that makes more sense now. Thanks for the clarification.
... View more
06-19-2015
09:43 AM
|
0
|
0
|
2460
|
|
POST
|
I have background geoprocessing turned off, so I'm wondering if this isn't the issue.
... View more
06-19-2015
08:44 AM
|
0
|
0
|
2460
|
|
POST
|
This may be getting me in the right direction. The feature class that I am using has duplicate fields for each customer, so say each customer has the same 20 fields, and the only difference between them is their customer identification. I want to loop through and say something like the following: if Customer1NodeID != None:
return regionvariable
if Customer2NodeID != None:
return regionvariable
if Customer3NodeID != None:
return regionvariable
else:
return None I'm just not sure how to nest multiple fields to be updated into one loop. Essentially I have 5 customers that I want to add data to their respective fields, but only if their NodeID field has data in it, otherwise leave it blank.
... View more
06-18-2015
01:26 PM
|
0
|
1
|
1338
|
|
POST
|
I am indeed using 64 bit background processing. Do you have any suggestions as to a workaround that doesn't result in me and everyone else that would use this tool having to install 32 bit libraries on top of the 64 bit libraries? Thanks!
... View more
06-18-2015
01:15 PM
|
0
|
2
|
2460
|
|
POST
|
Good catch, Darren. Blake, how would I construct this when I am using variables and added strings? I didn't fully understand the examples in the provided link. Also, why would concatenating strings be unreliable? Just trying to understand. Thanks to both of you!
... View more
06-18-2015
01:11 PM
|
0
|
2
|
5966
|
|
POST
|
I am taking a feature class and running the Table to Table tool to save it as a data table. Then I am taking that data table and exporting it to Excel.
... View more
06-18-2015
12:31 PM
|
0
|
0
|
5966
|
|
POST
|
I'll have to play around with the table view. Essentially I am porting over a very large model builder model. Following the workflow in order as it is in Model Builder, I just used the same table name thinking it would work. I'll try this with the table view option when I get a little more time to tinker with it and I'll respond with my results. Thanks!
... View more
06-18-2015
12:27 PM
|
0
|
0
|
5965
|
|
POST
|
Actually, I made an oversight when I pasted my code. I omitted some of the verbiage to not include customer names and whatnot, so instead of each NodeID field literally having a number after it, each number actually represents a customer name. But I will still use your sample code as reference for a FOR statement! . Can you think of a way to do it without the FOR iteration?
... View more
06-18-2015
12:25 PM
|
0
|
3
|
1338
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-16-2015 11:55 AM | |
| 1 | 02-04-2015 02:30 PM | |
| 2 | 03-23-2015 11:22 AM | |
| 7 | 03-23-2015 10:09 AM | |
| 3 | 03-23-2016 12:54 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-06-2025
09:05 PM
|