ぼやき雑記

とあるフリーランスプログラマのぼやきです。

dxf2gcodeをmacに入れる話

仕事で、arduinoで作られたCNCマシンにデータを入れる作業をしてたのですが、少し迷ったことがあったのでメモを残しておきます。

手元の環境

いただいたデータはdxf形式。手元にあるマシンはmac。これでwindows環境が手元にあればちょっと楽だったのかもしれませんね。

arduinoにデータを入れるためには

gcodeのデータが欲しい

arduinoに入れるためのソフトは次のpythonスクリプトを使う想定です。

grbl/simple_stream.py at master · grbl/grbl · GitHub

ですが、このスクリプトはgcode形式を入れることを前提としています。なのでdxfをgcodeに変換する必要があります。

dxf2gcodeを入れてみる

macで動かすためには?

python3の環境を用意

こちらのサイトなどを参考にpython3の環境を用意
qiita.com

ただPyQt5 (>=5.9)が必要なのですが、これはpipでインストールするのは面倒なのでbrewでインストール

brew install qt5

それ以外はpipでインストール可能です。

まずはdmg化する方法を試した

マニュアルにはこうありました。

  - macOS (not tested at all):
    $ python3 ./make_tr.py
    $ python3 ./make_py_uic.py
    $ python3 ./setup.py bdist_dmg # this should create Mac disk image

試したのですが、以下のエラーで詰まりました。

error: /Library/Developer/CommandLineTools/usr/bin/install_name_tool: input file: build/DXF2GCODE-2017.09.25.app/Contents/MacOS/DXF2GCODE-001.ico is not a Mach-O file
llvm-objdump: 'build/DXF2GCODE-2017.09.25.app/Contents/MacOS/DXF2GCODE-001.ico': Object is not a Mach-O file type.
@rpath/QtWidgets.framework/Versions/5/QtWidgets
error: can't copy '@rpath/QtWidgets.framework/Versions/5/QtWidgets': doesn't exist or not a regular file


これも工夫すれば対応できる気がするのですが、今回は見送り。

次にUnixでインストールする方法を試した

マニュアルにはこうありました

  - Unix (assumes bash shell):
    $ ./make_tr.py     # generates .qm translation files in i18 directory
    $ ./make_py_uic.py # generates: dxf2gcode_ui5.py and dxf2gcode_images.qrc
    $ python3 ./st-setup.py build
    # python3 ./st-setup.py install
    $ dxf2gcode


なるほど。これでも良さそう。

ただ、このままインストールをしようとすると、exeファイルが見つかりませんよ。って怒られるんですよね・・・・・って中身をみると。

make_ty.pyを一部抜粋

if "linux" in sys.platform.lower() or "unix" in sys.platform.lower():
    #On Linux, the executable are normaly on the PATH (just install which contains those executables)
    PLYPATH = "pylupdate5"
    LREPATH = None
    names = ["/usr/bin/lrelease-qt5", "/usr/bin/lrelease5", "/usr/bin/lrelease"]

macでのsys.platform.lower()を試すと darwin となります。なのでここを修正。またqt5のインストール先を確認してそれも追記しました。私の場合は /usr/local/opt/qt5/bin/lreleaseを追記

if "linux" in sys.platform.lower() or "unix" in sys.platform.lower() or "darwin" in sys.platform.lower():
    #On Linux, the executable are normaly on the PATH (just install which contains those executables)
    PLYPATH = "pylupdate5"
    LREPATH = None
    names = ["/usr/bin/lrelease-qt5", "/usr/bin/lrelease5", "/usr/bin/lrelease", "/usr/local/opt/qt5/bin/lrelease"]

make_py_uic.pyも同様にdarwinが必要な場所があったので

if "linux" in sys.platform.lower() or "unix" in sys.platform.lower():

if "linux" in sys.platform.lower() or "unix" in sys.platform.lower() or "darwin" in sys.platform.lower():

と変更

すると私の場合はコンパイルが通りました。

実行

こんな感じでインストールできました。
f:id:oouchida:20180629191752p:plain

終わりに

大したことではないのですが、結構長い時間を潰してしまったので、メモとして残しました。誰かの役に立てば幸いです。