Relima;
I've had this same quest for a while now, I've managed to do it relatively easy with Kosmo in X simple steps:
- Convert dwg to dwg 2000 with Teigha File Converter fro the Open Design Alliance;
- Open this dwg in Kosmo;
- Save it as an ESRI Shape file, as you mention it will create 2 or 3 shapes point, polygons and lines;
- Select elements by the field Layer, where field layer=X and save it as x.shp
- Repeat step 4 until desired layer are now in shp format.
I also started a semi automated process using Python, the input would be a shp like the one described in step 3 above, from there this program would create a catalog of layers and save as a shp file all the elements from each distinct layer; the program os not working properly I don't know why but it only makes copies of the original shape file, if you run the ogr command it works OK but not when this programa runs it.
This is th python program
import shlex, subprocess, sys, fileinput
from dbf import *
from string import strip
def process():
Read dbf
a = open ("capas1.txt","w+")
print 'Ingresa el nombre del shape que deseas leer'
b = raw_input()
print '\n'
dbf = Dbf(b+".dbf",new=False)
for rec in dbf:
for fldName in dbf.fieldNames:
if fldName == 'LAYER':
l=()
l=rec[fldName]
a.write(l)
a.write("\n")
#dbf.close()
a.close()
Get a txt with the the attribute of the dbf layers
a = open ("capas1.txt","r")
catalogo = open ("unico1.txt","w")
unique = set(a.read().split("\n"))
catalogo.write("".join([line + "\n" for line in unique]))
catalogo.close()
a.close()
Execute ogr2ogr
for line in open("unico1.txt", "r"):
p = subprocess.Popen(['C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr', line.replace("\n", "") +'.shp', '-where', "\"LAYER='"+ line.replace("\n", "") +"'\"" , b+'.shp'])
process()