Problem executing sample python code in the help documents

4868
4
10-29-2010 11:56 AM
by Anonymous User
Not applicable
I'm trying to run the code sample CadtoGeodatabase.py at
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00120000001z000000.htm

I have edited the variables with my particular settings. All I get  is

C:\Temp\PyProcess>python CadtoGeodatabase.py
Traceback (most recent call last):
  File "CadtoGeodatabase.py", line 23, in <module>
    arcpy.CadToGeodatabase_conversion (input_cad_dataset, out_gdb_path, out_data
set_name, reference_scale, spatial_reference)
AttributeError: 'module' object has no attribute 'CadToGeodatabase_conversion'


Also note on that sample code that spatial_reference variable is defined but not used.

I get the same result if I execute this script in a cmd window or in a python window in ArcMap.  The only way I have gotten this to run is using the toolbox and specifying the variables in the parameters window.

What am I missing?  The full code follows...

# Name: CadtoGeodatabase.py
# Description: Create a feature dataset
# Author: ESRI

# Import system modules
import arcpy
from arcpy import env

# Set workspace
env.workspace = "C:/Temp/PyProcess"

# Set local variables
input_cad_dataset = "C:/Temp/PyProcess/0028.01.dwg"
out_gdb_path = "C:/Temp/PyProcess/FM.gdb"
out_dataset_name = "_0028_01_dwg"
reference_scale = "1000"
spatial_reference = "NAD_1983_StatePlane_Tennessee_FIPS_4100_Feet"

# Create a FileGDB for the fds
arcpy.CreateFileGDB_management("C:/Temp/PyProcess", "FM.gdb")

# Execute CreateFeaturedataset
arcpy.CadToGeodatabase_conversion (input_cad_dataset, out_gdb_path, out_dataset_name, reference_scale, spatial_reference)
0 Kudos
4 Replies
maxsteinbrenner
New Contributor II
for python you want to change all your pathing to look like this:

this
"C:/Temp/PyProcess/FM.gdb"

should be
"C:\\Temp\\PyProcess\\FM.gdb"

or
r"C:\Temp\PyProcess\FM.gdb"
0 Kudos
by Anonymous User
Not applicable
Thanks for the reply.  I tried both replacements with no effect.  Any other thoughts?
0 Kudos
ScottKutz
New Contributor II
I am relatively new to using Python for invoking the geoprocessing tools, and I also encountered the same errors mentioned in the original posting when attempting to use the sample script in the ArcGIS Help system.

After some amount of trial-and-error, I have finally been able to get the script to execute. I'm not sure this is the "correct solution", but it at least permits the script to execute successfully. That seems to make it worthwhile sharing with the users of this forum.

To the best I can tell, there are three problems with the sample script:
1. Missing the import statement for: arcpy.conversion  (See "Note" following the script example.)
2. Invalid technique for defining a spatial reference.
3. Typo in the tool's name. The tool name is "CADToGeodatabase", not "CadToGeodatabase".

An updated version of the script is included below, with comments inserted to note the above three problems.

#Name: CADtoGeodatabase.py
# Description: Create a feature dataset
# Author: ESRI

# Import system modules
import arcpy
from arcpy import env
# --- Problem 1 of 3 with original example: missing import for arcpy.conversion (need to include new line below)
# --- Without this statement, execution terminates with the error:
# ---     AttributeError: 'module' object has no attribue 'CADToGeodatabase'
import arcpy.conversion

# Set workspace
env.workspace = "C:/data"

# Set local variables
input_cad_dataset = "C:/data/City.DWG"
out_gdb_path = "C:/data/HabitatAnalysis.gdb" 
out_dataset_name = "analysisresults"
reference_scale = "1000"
# --- Problem 2 of 3 with original example: spatial_reference generates "Parameters are not valid" execution error
# spatial_reference = "NAD_1983_StatePlane_California_VI_FIPS_0406_Feet"
prjfile = r"C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\State Plane\NAD 1983 (US Feet)/NAD 1983 StatePlane California VI FIPS 0406 (US Feet).prj"
spatial_reference = arcpy.SpatialReference(prjfile);

# Create a FileGDB for the fds
arcpy.CreateFileGDB_management("C:/data", "HabitatAnalysis.gdb")

# Execute CreateFeaturedataset 
# --- Problem 3 of 3 with original example: (1) typo in tool name ("Cad" vs. "CAD") and (2) missing SR parameter
# arcpy.CadToGeodatabase_conversion(input_cad_dataset, out_gdb_path, out_dataset_name, reference_scale)
arcpy.CADToGeodatabase_conversion(input_cad_dataset, out_gdb_path, out_dataset_name, reference_scale, spatial_reference)



Note:
- Curiously, I was consistenly getting the execution error "AttributeError: 'module' object has no attribue 'CADToGeodatabase'" every time I ran the script, until stumbling on including the statement:
import arcpy.conversion

- While preparing this posting, I decided to just try commenting out the import arcpy.conversion statement to confirm the execution error returned.

- Well, the execution error no longer seems to occur even after commenting out the import arcpy.conversion statement.

- The only thing I can speculate is that forcing the import arcpy.conversion one time appears to have somehow updated something in the Python execution environment for my userid.

- At any rate, script references the CADToGeodatabase can now be successfully resolved and the tool executes.

I hope this is helpful to others who are attempting to use the CADToGeodatabase tool.

Scott
rymaaneliunas
New Contributor II

I am getting the same error, what is the cause? There was never really an answer to this issue.

0 Kudos