0

I am building a Ruby on Rails application and I need to display a thumbnail for uploaded .dwg (AutoCad) files. Is there any gem (ideally) or command line Unix library to do this? I had already crawled the entire web and found nothing but licensed Windows GUI interfaces.

I also tried with ImageMagick but it doesn't supports .dgw conversion.

I have a .exe that makes the conversion but I'll need to build a web service running on a Windows server just for this feature, that's why I need the library to run on Unix systems.

carpamon
  • 6,515
  • 3
  • 38
  • 51
  • Worth noting - there are [no open source viewers](https://en.wikipedia.org/wiki/.dwg#Freeware_and_open_source_viewers) - it'll have to be commercial software, I think. – halfer Mar 18 '12 at 09:57
  • That all said, these folks do [a viewer](http://opendesign.com/the_oda_platform/TD). – halfer Mar 18 '12 at 10:00

1 Answers1

1

I had to generate a DXF from my rails application, I couldn't find a gem, so I generated python code, using the lybrary DXFWriter, and called python sending the code to generate the DXF file, maybe it could solve part of this problem.

  def dxf
    elements = ''
    params[:_json].second.each do |l|  #Lines
      elements += "drw.add(dxf.line((#{l[:x1]}, #{l[:y1]}), (#{l[:x2]}, #{l[:y2]}), color=1));"
    end
    params[:_json].third.each do |a|  #Arcs
      elements += "drw.add(dxf.arc(#{a[:radius]}, (#{a[:left]}, #{a[:top]}),
                  #{(a[:startAngle] * Base::Part::TO_DEG).round(3)}, #{(a[:endAngle] * Base::Part::TO_DEG).round(3)}, color=1));"
    end
    file_name = "#{Rails.root}/tmp/#{Dir::Tmpname.make_tmpname([params[:_json].first[:part_name], '.dxf'], nil)}"
    base_script = "import sys;sys.path.insert(0, '" + Rails.root.to_s + "');from dxfwrite import DXFEngine as dxf;"\
                  "drw = dxf.drawing('#{file_name}');"\
                  "#{elements}drw.save()"

    %x(python -c "#{base_script}")
    render json: { export_basename: file_name }
  end
fabriciofreitag
  • 2,843
  • 22
  • 26