Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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"

mxd=arcpy.mapping.MapDocument(r"CURRENT")
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.

END OF UPDATE

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:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/AddLayer/00s300000025000000/

Add a new group layer with python ArcGIS 10

How do I add a shapefile in ArcGIS via python scripting?

How do you use folders as input/output parameters

Shape files are not being adding to MXD using arcPy

share|improve this question
    
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. –  TForward Jun 20 '12 at 14:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.