|
POST
|
I'm trying to export my feature class to a table, and then also create a copy as an Excel document. The following code keeps kicking back with an error saying that I am using the wrong file type. Error message: "Failed to execute. Parameters are not valid. ERROR 000814: Invalid file type Failed to execute (TableToExcel)." Code: ##########
# Create a file geodatabase for attribute tables to be saved in
##########
# Set local variables - uses variables derived earlier in script
attFolder = mapFolder + "/" + "6)Deliverables/4)Feature_Class_Attribute_Tables/" + version
outATTgdb = 'attribute_tables.gdb'
# Execute CreateFileGDB
arcpy.CreateFileGDB_management(attFolder, outATTgdb, 'CURRENT')
##########
# General Features export
##########
# Set local variables
inTable = generalFeatures
exportLoc = attFolder + "/" + outATTgdb
outTable = "general_attributes"
outXLS = "general_attributes.xls"
# Execute TableToTable
arcpy.TableToTable_conversion(inTable, exportLoc, outTable)
arcpy.env.workspace = 'attFolder'
# Execute TableToExcel
arcpy.TableToExcel_conversion(inTable, outXLS)
I've tried modifying this a bit, with no positive results. For the outXLS variable I tried to make it equal the entire save location, and then removed the arcpy.env.workspace variable, but everything that I have tried results in the same "invalid file type" error. Any recommendations? Thanks in advance!
... View more
06-16-2015
02:16 PM
|
0
|
23
|
16311
|
|
POST
|
This looks like it'll do just what I need. I'll give it a try a little later and respond with my results. Thanks for responding.
... View more
06-16-2015
01:58 PM
|
0
|
0
|
1346
|
|
POST
|
Wow, that's some pretty cool stuff! Thanks for sharing.
... View more
06-16-2015
01:57 PM
|
0
|
0
|
1346
|
|
POST
|
I have a script that works, but I replicate it in order to conditionally update 5 different fields. I would like to bolster the script to conditionally calculate all 5 fields into one if I can. # Calculate Region
# Set local variables
inTable = nodeFeatures
inField = "Region1"
expression = "Reclass (!NodeID1!, !Region1!)"
codeBlock = """def Reclass (NodeID1, Region1):
if NodeID1 != None:
return region #variable is declared earlier in the script
else:
return None"""
# Execute CalculateField
arcpy.CalculateField_management(inTable, inField, expression, "PYTHON_9.3", codeBlock)
The script above works just fine, but as I mentioned, I end up duplicating it to calculate 4 other fields. In this example we'll call all 5 fields Region1, Region2, etc... They would all have an accompanying NodeID1, NodeID2, etc... Is it possible to expand upon this script in order to reduce the 5 separate scripts to calculate them all in one, or is it just the way it has to be in order to calculate a value of completely separate fields? Thanks in advance!
... View more
06-16-2015
01:31 PM
|
0
|
8
|
4928
|
|
POST
|
I actually just fixed it while tinkering. I changed the expression type to "PYTHON" and added single quotes around the region variable. Correct code: # Calculate Region
# Set local variables
inTable = fiberFeatures
inField = "ProjectRegion"
expression = 'region'
# Execute CalculateField
arcpy.CalculateField_management(inTable, inField, expression, "PYTHON")
I've been stuck on this error for over an hour. I would finally decide to ask on here and then figure it out right away . Thanks for responding, though!
... View more
06-16-2015
11:55 AM
|
1
|
0
|
1468
|
|
POST
|
Thanks for the response, but that results in the same error message.
... View more
06-16-2015
11:46 AM
|
0
|
2
|
1468
|
|
POST
|
I am trying to calculate a field based on derived values within a python script. I keep getting the following error, though: "Empty value for ObjectID = 3005 The calculated value is invalid for the row with ObjectID = 3005. For example, the calculated value may be too large for the field or you may be trying to add a string to a number field. This row will not be updated." The script runs through every single feature and returns an error message identical to the one above for each feature. # Calculate Region
# Set local variables
inTable = fiberFeatures
inField = "ProjectRegion"
expression = region
# Execute CalculateField
arcpy.CalculateField_management(inTable, inField, expression, "VB")
All variables check out just fine when I print them in the ArcMap Python window, and the field within my feature class is of text type. The region is a simple two letter code such as "NC", "NE", "SW", etc... I've tried with various combinations of alternatives, such as adding single/double quotes around region, I've added single/double/triple quotes around expression within the CalculateField function, and I've tried entering the variable straight into the function. The only help I can find through internet searches that pertains exactly to what I'm doing is HERE, but it is a little different and I'm not sure how to make it apply to my situation. I'm working on a Windows 7 machine and I'm running ArcGIS Standard version 10.3.0.4322
... View more
06-16-2015
11:38 AM
|
0
|
4
|
3935
|
|
POST
|
EUREKA! That did the trick!!!!! The final working code is: # Name: Map to KML
# Description: This script is used within a model to export the map to a KMZ file for distribution
# Author: Coy Potts
# Parts: (1) Apply Symbology Layer File, (2) Save mxd, (3) MapToKML tool, (4) Apply Symbology Layer File
# Import system modules
import arcpy
from arcpy import env
import arcpy.mapping as map
# Part 1:
# Apply Symbology Layer file
# Set current workspace
env.workspace = r'file path for layer files'
# Set layer to apply symbology to
inputLayer = r'feature class'
# Set layer file for the output symbology
symbologyLayer = r'layer file'
# Apply the symbology from the symbology layer to the input layer
arcpy.ApplySymbologyFromLayer_management (inputLayer, symbologyLayer)
# Part 2:
# Save the map
# Set the map document to the current map
mxd = map.MapDocument("CURRENT")
# Save the map
mxd.save()
# Part 3:
# Map to KML tool
# Set current workspace
env.workspace = "C:\Users\cpotts\Desktop\Test_Folders"
# Set local MapToKML variables
df = arcpy.mapping.ListDataFrames(mxd)[0].name
outputKML = "C:\Users\cpotts\Desktop\Test_Folders\output_test.kmz"
mapScale = 0
composite = 'NO_COMPOSITE'
vector = 'VECTOR_TO_VECTOR'
extent = r'feature class'
imageSize = 1024
dpi = 96
ignore_z = 'ABSOLUTE'
# Execute MapToKML
arcpy.MapToKML_conversion(mxd.filePath, df, outputKML, mapScale, composite, vector, extent, imageSize, dpi, ignore_z)
Thanks for all of the help in getting this to working for me . Now...I need to get the output kmz and workspace to be dynamic instead of static. I'll play around with the getparameterastext functions and see what I can come up with.
... View more
05-15-2015
09:49 AM
|
0
|
2
|
3215
|
|
POST
|
Still kicking back and referencing line 2278 of the conversion.py script. ... # Part 3:
... # Map to KML tool
...
... # Set current workspace
... env.workspace = "C:\Users\cpotts\Desktop\Test_Folders"
...
... # Set local MapToKML variables
... inputMap = mxd
... df = arcpy.mapping.ListDataFrames(mxd)[0]
... outputKML = "C:\Users\cpotts\Desktop\Test_Folders\output_test.kmz"
... mapScale = 0
... composite = 'NO_COMPOSITE'
... vector = 'VECTOR_TO_VECTOR'
... extent = r'Entire Coverage Area\Fiber Segments'
... imageSize = 1024
... dpi = 96
... ignore_z = 'ABSOLUTE'
...
... # Execute MapToKML
... arcpy.MapToKML_conversion(mxd, df, outputKML, mapScale, composite, vector, extent, imageSize, dpi, ignore_z)
...
...
...
Runtime error
Traceback (most recent call last):
File "<string>", line 54, in <module>
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\conversion.py", line 2278, in MapToKML
raise e
RuntimeError: Object: Error in executing tool
>>> I also went ahead and set all of the other variables too just to try it out. It accepts them all, but I get the error at the bottom.
... View more
05-15-2015
09:34 AM
|
0
|
0
|
1104
|
|
POST
|
How do I make it hold the actual data frame instead of a string variable?
... View more
05-15-2015
09:17 AM
|
0
|
3
|
1264
|
|
POST
|
The data frame does have the same name as the mxd. I did as you suggested above and I still got the exact same error as above. Question regarding your suggestion, though: I thought that the line that sets the current workspace (line 39) within Part 3 was taking care of where the outputKML would be saved...?
... View more
05-15-2015
09:07 AM
|
0
|
0
|
1264
|
|
POST
|
I actually finally got one of the above suggestions to work in regards to getting the map name as a string. Their suggestion wasn't properly written, so it didn't work for me. I changed ".filepath" to ".filePath" and it worked like a charm. Here is the latest run and error message for the entire code: >>> # Name: Map to KML
... # Description: This script is used within a model to export the map to a KMZ file for distribution
... # Author: Coy Potts
... # Parts: (1) Apply Symbology Layer File, (2) Save mxd, (3) MapToKML tool, (4) Apply Symbology Layer File
...
... # Import system modules
... import arcpy
... from arcpy import env
... import arcpy.mapping as map
...
... # Part 1:
... # Apply Symbology Layer file
...
... # Set current workspace
... env.workspace = r'layer file drive path'
...
... # Set layer to apply symbology to
... inputLayer = r'feature class'
...
... # Set layer file for the output symbology
... symbologyLayer = r'layer file'
...
... # Apply the symbology from the symbology layer to the input layer
... arcpy.ApplySymbologyFromLayer_management (inputLayer, symbologyLayer)
...
... # Part 2:
... # Save the map
...
... # Set the map document to the current map
... mxd = map.MapDocument("CURRENT")
...
... # Save the map
... mxd.save()
...
... # Part 3:
... # Map to KML tool
...
... # Set current workspace
... env.workspace = "C:\Users\cpotts\Desktop\Test_Folders"
...
... # Set local MapToKML variables
... mapname = str(mxd.filePath).split('\\')[-1:][0][:-4]
... inputMap = mxd
... dataFrame = mapname
... outputKML = "output_test.kmz"
...
... # Execute MapToKML
... arcpy.MapToKML_conversion(inputMap, dataFrame, outputKML)
...
...
...
...
Runtime error
Traceback (most recent call last):
File "<string>", line 48, in <module>
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\conversion.py", line 2278, in MapToKML
raise e
RuntimeError: Object: Error in executing tool There's something with my execution of the MapToKML tool that it's not liking. The three variables that I used in the MapToKML execution are the three that are required inputs. Do you think that it requires that all 10 inputs be included?
... View more
05-15-2015
08:54 AM
|
0
|
11
|
1264
|
|
POST
|
I finally got this part to work. The part that was throwing my code off is that you type a lowercase "p" in filepath, but it needs to be uppercase. >>> import arcpy
>>> import arcpy.mapping as map
>>> mxd = map.MapDocument("CURRENT")
>>> mapname = str(mxd.filePath).split('\\')[-1:][0][:-4]
>>> print mapname
NW-CA-FERRYGRW-VZW This is exactly what I needed to get the map name as a string.
... View more
05-15-2015
08:41 AM
|
0
|
0
|
1578
|
|
POST
|
I would like to get away from it, but it was the only way I could think of to add a dynamic variable that the user could change. I'm getting errors with the code suggestions above to try and strip the file path. I get the following error: >>> import arcpy
>>> import arcpy.mapping as map
>>> mxd = map.MapDocument("CURRENT")
>>> mapname = str(mxd.filepath).split('\\')[-1:]
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'MapDocument' object has no attribute 'filepath'
>>> Just as you have suggested, I went ahead and gave literal values in place of the variables and I get the following: ... # Part 3:
... # Map to KML tool
...
... # Set current workspace
... # env.workspace = "C:\Users\cpotts\Desktop\Test_Folders"
...
... # Set local MapToKML variables
... inputMap = mxd
... outputKML = "output_test.kmz"
...
... # Execute MapToKML
... arcpy.MapToKML_conversion(inputMap, outputKML)
...
...
...
...
Runtime error
Traceback (most recent call last):
File "<string>", line 46, in <module>
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\conversion.py", line 2278, in MapToKML
raise e
RuntimeError: Object: Error in executing tool As per this LINK there are 10 conditions that are within the MapToKML tool, and I wonder if they're all required in order for the tool to run. If that is the case, hothw do you configure pyon to simply run with the defaulted value instead of having to set that parameter. When I run the tool manually, the data frame that it selects defaults to the only data frame in our map, which is again named identically to the map document, thus leading to the same issue as stated above where I still need to get the map name into a string so I can use it as a variable. I suppose I could change our map template to have a static data frame name, which I could then hard code into the script since it would never change, but I don't want to do that unless I have to. The image below shows the inputs that I use when I manually run the tool. I choose my mxd, it defaults to the only data frame in the map, I name the output file, and then I set the extent properties to match that of one of the feature classes. Every other input I leave as the default value. Thanks again for all the help guys! I think we're getting closer to a solution . This is the first script that I have ever tried to construct to run ArcMap tools, so I'm definitely at the forefront of the beginners stage lol.
... View more
05-15-2015
08:11 AM
|
0
|
1
|
1578
|
|
POST
|
arcpy.MapToKML_conversion(inputMap, outputKML)
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\conversion.py", line 2278, in MapToKML
raise e
RuntimeError: Object: Error in executing tool
The "t" was only in the version that I had written in NotePad. The code above is what I had typed into the actual ArcMap Python window.
... View more
05-15-2015
07:02 AM
|
0
|
3
|
1578
|
| 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
|