I am trying to add an CAD Drawing Dataset into ArcMap using Python.

Question is how to add a Auto-CAD .dwg file to ArcMap using Python

Normally comes in as CAD file within a Group layer with: annotation, point, line, polygon, multipatch

this is the code I have so far

import os
import arcpy

#In reality the file path is not hard coded
filePath = "F:\2012\01001\ACAD\1201000AB_R1.dwg"

df=arcpy.mapping.ListDataFrames(mxd,"Project Area")[0]

groupLayer = arcpy.mapping.Layer(r"CAD")
targetGroupLayer = arcpy.mapping.ListLayers(mxd, "CAD", df)[0]
addLayer = arcpy.mapping.Layer(filePath)

#Have tried this too, plus escaping the \, and same error
#addLayer = arcpy.mapping.Layer(r"F:\2012\01001\ACAD\1201000AB_R1.dwg")
#arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")

UPDATE!!! I got it to work sort of by doing this

addLayer = arcpy.mapping.Layer(r"F:\\Jobs2012\\05665\\ACAD\\1205665WS_R1.dwg\\Annotation")

You have to explicitly name what part of the .dwg you want in this case the Annotation layer. What I need to do now is create a loop that adds 1205665WS_R1.dwg\wildcard to add all the layers at once.


I get the following Error

<type 'exceptions.ValueError'>: Object: CreateObject Layer invalid data source

Note: I have gotten this to work when adding a .shp file

These are some of the resources of have consulted thus far:


Adding new group layer with ArcPy?

Adding shapefile as layer in ArcMap via Python scripting?

How do you use folders as input/output parameters

Shapefiles are not being added to MXD using ArcPy?

  • I decided to leave this and not delete it since it took me some time to figure out that you have to explicitly call the .dwg. The whole I hope others don't suffer as I have suffered thing. – Tristan Forward Jun 20 '12 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.