carpamon
carpamon

Reputation: 6633

Unix DWG to BMP|JPG|PNG|SVG converter

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.

Upvotes: 0

Views: 1999

Answers (1)

fabriciofreitag
fabriciofreitag

Reputation: 2883

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

Upvotes: 1

Related Questions