-2

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.

enter image description here

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.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Developer
  • 8,258
  • 8
  • 49
  • 58
  • What is the resulting format you need? You might want to add the word "programmatically" to your title / question. – agf Mar 18 '12 at 05:25
  • What is the input format for the 'set of connected lines'? A CAD drawing of those lines? Coordinate data in a text file? – Li-aung Yip Mar 18 '12 at 05:30
  • @Li-aungYip They are in format of DXF and also text file too. – Developer Mar 18 '12 at 06:36
  • @lllluuukke Can you do the job as detailed in the question automatically in Autodesk Inventor? I don't think so! – Developer Mar 18 '12 at 06:45
  • @agf The data as mentioned above is as DXF file, so the resultings need to be there. The output is good if DXF for easily export between programs. – Developer Mar 18 '12 at 06:47

2 Answers2

3

Here are some Google SketchUp Ruby API snippets. It's very simple, using the Edge#find_faces method that will make SketchUp try and find possible faces for the given edge. https://developers.google.com/sketchup/docs/ourdoc/edge#find_faces

Find faces for current selection:

# Find faces for selected edges:
model = Sketchup.active_model
model.start_operation( 'Find Faces in Selection', true )
for entity in model.selection.to_a
  next unless entity.is_a?( Sketchup::Edge )
  entity.find_faces
end
model.commit_operation

Find faces for current context:

# Find faces for current context:
model = Sketchup.active_model
model.start_operation( 'Find Faces in Current Context', true )
for entity in model.active_entities.to_a
  next unless entity.is_a?( Sketchup::Edge )
  entity.find_faces
end
model.commit_operation

Find faces for all edges in model:

# Find faces for all edges in model:
model = Sketchup.active_model
model.start_operation( 'Find Faces in Whole Model', true )
for entity in model.entities.to_a
  next unless entity.is_a?( Sketchup::Edge )
  entity.find_faces
end
for definition in model.definitions
  next if definition.image?
  for entity in definition.entities.to_a
    next unless entity.is_a?( Sketchup::Edge )
    entity.find_faces
  end
end
model.commit_operation

If you need to process a batch of DWG file for this you can automate that as well using Model#import to import the DWG files. https://developers.google.com/sketchup/docs/ourdoc/model#import

This assumes that the edges are bounding coplanar surfaces. You will only get a solid if the wiregrid you import can represent one.

thomthom
  • 2,854
  • 1
  • 23
  • 53
  • Thank you so much for your nice answer. This is really helpful to solve the old problem. – Developer Apr 10 '12 at 12:08
  • +1000 I should thank you again for very interesting links given in your answer. They are lovely resources. That is an amazing answer :) – Developer Apr 10 '12 at 12:11
1

If you can build a mesh from your collection of lines, and if that mesh is closed (water tight), you could use the AutoCAD convtosolid command in a script:

http://docs.autodesk.com/ACAD_E/2012/ENU/filesACR/WS1a9193826455f5ffa23ce210c4a30acaf-4cf2.htm

I think the command is new in AutoCAD 2012, but it might have been in 2011 too?

kitsu.eb
  • 2,996
  • 1
  • 26
  • 28