How to convert a set of connected lines to a solid in CAD applications? Tool is being used can be AutoCAD, SketchUp, Solidworks, FreeCAD, or any other software you may know that can do this simple task painlessly. Note that the following graphics is only for demonstration. The desired resulting should be a valid CAD solid to be able apply all related operations such as boolean ones etc.

Just remember the job needs to be done thousands times so manual approaches are not suitable. Even some help to write a piece of code for this job is much appreciated (in any language), so you may explain how to code a simple DXF writer for just Solid, for example. Our play with some DXF exporters in Python was not successful.
Upadate: a simple Ruby code for SketchUp or VBA code for AutoCAD or Python for FreeCAD could be of most help.
Here are some Google SketchUp Ruby API snippets. It’s very simple, using the
Edge#find_facesmethod that will make SketchUp try and find possible faces for the given edge. https://developers.google.com/sketchup/docs/ourdoc/edge#find_facesFind faces for current selection:
Find faces for current context:
Find faces for all edges in model:
If you need to process a batch of DWG file for this you can automate that as well using
Model#importto import the DWG files. https://developers.google.com/sketchup/docs/ourdoc/model#importThis assumes that the edges are bounding coplanar surfaces. You will only get a solid if the wiregrid you import can represent one.