Select to view content in your preferred language

Export to CAD

1344
1
07-11-2011 06:09 AM
ClaireParsons
Emerging Contributor
I'm fairly new to programming in python so please bear with me.  I'm trying to create a script that loops through all the layers in my TOC and exports them to a CAd file. As first I tried ListFeatureClasses but this lists the whole feature class name e.g. shape.shp, which produces an error  as it tries to export shape.shpdxf

So I then tried ListLayers but get an error 000840 the value is not a CAD drawing dataset. Any Ideas?

from arcpy import env
import os
#Set the workspace
env.workspace = "C:\data"
mxd = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(mxd)
for lyr in layers:
  print(lyr)
  arcpy.ExportCAD_conversion(lyr,"DWG_R2007",lyr,"Ignore_Filenames_in_Tables","Overwrite_Existing_Files")

thanks
Claire
Tags (2)
0 Kudos
1 Reply
ClaireParsons
Emerging Contributor
Well, I'm quite pleased with myself as I've managed to sort the problem 😄
I've used ListFeatureClasses to create a list and then 'rstrip(".shp")' to take shp from the end then added '.dwg'.  See below.

import arcpy
from arcpy import env
import os
#Set the workspace
env.workspace = "C:/data"
fclist = arcpy.ListFeatureClasses()
outputloc = "C:/data/"
fextension = ".dwg"
for fc in fclist:
  arcpy.ExportCAD_conversion(fc,"DXF_R2007",outputloc + fc.rstrip(".shp") + fextension,"Use_Filenames_in_Tables","Overwrite_Existing_Files")

Maybe this means I am on the way to understanding Python!!! :eek:
0 Kudos