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!!
-
My first thought was to do what you have described (convert, read, delete). I know you can create AutoCAD scripts, but i'm not sure if you can do what you would like to do in that scripting environment. Maybe post that question here.– dchaboyaCommented Dec 17, 2012 at 19:46
-
Is the polygon feature in Postgres, MSSQL, Oracle etc.?– tudorbarascuCommented Nov 27, 2013 at 16:27
-
Thanks for your input. I was able to find a work around but found out I was creating a monster! I was clipping MrSID files but had no format in which to save the clipped file that did not create HUGE files. I am working with very large images (4 inch pixels covering about 100 acresas the clipped version) and ended up with unruly tif or jpg files. SO I abandoned the idea of doing this process.– user24727Commented Dec 9, 2013 at 7:37
2 Answers
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:
lyr.getExtent()
-
After i use the getExtent method, i got an Error! lyr.getExtent() AttributeError: 'str' object has no attribute 'getExtent' Thanks, Geog Commented Nov 27, 2013 at 17:54
-
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()[0].extent