Extracting Coordinate System from CAD File Name

822
3
Jump to solution
02-08-2021 08:39 AM
AdOl2
by
New Contributor

Having an issue running the following script. It seems to work when I print the values of the functions, but I think? my problem is that I don't know how to assign those functions (or variables in this case) to the geoprocessing tool correctly. Thoughts?

I have ran the CAD drawing manually through Pro 2.5 and it works, so the I don't see an issue being with the data.

Error

Traceback (most recent call last):
File "<string>", line 39, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\conversion.py", line 1123, in CADToGeodatabase
raise e
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\conversion.py", line 1120, in CADToGeodatabase
retval = convertArcObjectToPythonObject(gp.CADToGeodatabase_conversion(*gp_fixargs((input_cad_datasets, out_gdb_path, out_dataset_name, reference_scale, spatial_reference), True)))
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 511, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool

 

import arcpy
import os

#Temp/Processing GDB
working = r"C:\Users\a\Documents\ArcGIS\Projects\DGN_Import\W_DGN_Import.gdb"

#Final/Production GDB
final = r"C:\Users\a\Documents\ArcGIS\Projects\DGN_Import\DGN_Import.gdb"

#CAD Dataset
cad = r"C:\Users\a\Documents\ArcGIS\Projects\DGN_Import\JODKH-BNDY-TOPO_SPILWest1202.dgn"

#CoordinateSystems
SPCEast = "NAD_1983_2011_StatePlane_Illinois_East_FIPS_1201_Ft_US"
SPCWest = "NAD_1983_2011_StatePlane_Illinois_West_FIPS_1202_Ft_US"

#OutputName
def opn(x):
    folder = os.path.splitext(os.path.basename(x))[0]
    return  str(folder.rsplit('_',1)[0])

#If statement to extract Coordinate System
def cs(x):
    folder = os.path.splitext(os.path.basename(x))[0]
    return  str(folder.split('_',2)[1])

#Match extraction to identify input coordinate system
def csm(y):
    if y is 'SPILEast1201':
        return SPCEast
    else:
        return SPCWest

#Execute Functions
outputname = opn(cad)
coordsys = cs(cad)
coordsysmatch = csm(cs)
#CAD to Geodatabase; use SPC from csm
arcpy.conversion.CADToGeodatabase([cad], [working], [outputname], '1000', [coordsysmatch])

 

 

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

Are you looking to build this into a bigger tool (e.g. process more than one dataset)?

The documentation CAD To Geodatabase (Conversion)—ArcGIS Pro | Documentation shows that the only argument supplied as a list is the list of CAD files.

Try removing the other lists, like this:

arcpy.conversion.CADToGeodatabase([cad], working, outputname, '1000', coordsysmatch)

 

View solution in original post

3 Replies
DavidPike
MVP Frequent Contributor

Are you looking to build this into a bigger tool (e.g. process more than one dataset)?

The documentation CAD To Geodatabase (Conversion)—ArcGIS Pro | Documentation shows that the only argument supplied as a list is the list of CAD files.

Try removing the other lists, like this:

arcpy.conversion.CADToGeodatabase([cad], working, outputname, '1000', coordsysmatch)

 

AdOl2
by
New Contributor

You were correct David. What I thought the [] were used for was incorrect.

Thanks!

DavidPike
MVP Frequent Contributor

Also your feature dataset name is probably invalid as it contains hyphens - JODKH-BNDY-TOPO.

You will probably need to do a .replace("-","_") or similar.

0 Kudos