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 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!!

share|improve this question
    
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. –  dchaboya Dec 17 '12 at 19:46
    
Is the polygon feature in Postgres, MSSQL, Oracle etc.? –  tudorbarascu Nov 27 '13 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. –  geonerd Dec 9 '13 at 7:37
add comment

2 Answers 2

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()
share|improve this answer
    
After i use the getExtent method, i got an Error! lyr.getExtent() AttributeError: 'str' object has no attribute 'getExtent' Thanks, Geog –  Geog Nov 27 '13 at 17:54
    
Can you post your code as an edit to your question? –  artwork21 Nov 28 '13 at 3:27
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.