I have Civil 3D 2012 with ArcGIS for AutoCAD 300. I want to read the extents of a polygon in the drawing. Feature Class in A4A300 = Boundaries, the CAD layer is PROP-BNDY, there is only one polygon on that layer since it is the perimeter of the site. Do I have to convert the polygon to a temporary shapefile, read it, and then delete it? I will be using the boundary extents plus a constant in all directions to clip raster images. The process should not involve user input. I have 30 directories that I will be looping through, a drawing file in each directory and a polygon in each drawing. I have the python routines for creating a list of directories that have the *map.dwg files in them and I'm familiar with clipping the rasters, I just cannot find how to read the polygon extents in the dwg file. Your help is greatly appreciated!!
As you have suggested you will have to convert the CAD polygon feature to a GIS feature class or feature layer, then you may use arcpy to get the geometry extent.
First, to make a temp/in-memory layer your could use Make Feature Layer function, see example code below:
polyCAD = "C:\\Temp\\xyz.dwg\\Polygon" lyr = "Polygon_Layer" # Process: Make Feature Layer using a expression arcpy.MakeFeatureLayer_management(polyCAD, lyr, "\"Layer\" = 'PROP-BNDY'")
Alterntivley, if you want the temp layer to be converted to an actual temp file you could use Feature Class to Feature Class.
For both cases you can then get the layer extent using the getExtent() method:
You can convert dwg file to feature class, then get the extent of the polygon, using the code below:
arcpy.CADToGeodatabase_conversion(path_dwg, output_gdb, "fc" , 200) extent = arcpy.da.SearchCursor( "fc" , ["SHAPE@" ] , "\"Layer\" = 'PROP-BNDY'").next().extent