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") groupLayer = arcpy.mapping.Layer(r"CAD") targetGroupLayer = arcpy.mapping.ListLayers(mxd, "CAD", df) 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: