C#でコマンドを実行する

以下、サンプルプログラムです。

using System;
using System.Diagnostics;

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Process p = new Process();

            p.StartInfo.FileName = "ls"
            p.StartInfo.Arguments = "-al";
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;

            p.Start();
            string output = p.StandardOutput.ReadToEnd();
            string erroutput = p.StandardError.ReadToEnd();

            p.WaitForExit();
            p.Close();
            p.Dispose();

            Console.Write(output);
            Console.Write(erroutput);
        }
    }
}
MacOSでTerminal.appを起動して下記のように実行すればMacOSでも動作します。
/Library/Frameworks/Mono.framework/Versions/5.18.1/bin/mono32 test.exe 

netDxfでDXFを操る

netDxfはDXFの.net用の読書きライブラリです。
https://github.com/haplokuon/netDxf

DXFはHEADERやCLASSES、図の本体部分のENTITIESなどの各セクションを真面目に記載しようとすると結構面倒。
そうした面倒な部分を意識することなく、C#やVB.NETでDXFを読書きできるライブラリがnetDxfです。

使い方はこんな感じになります。

using System;
using netDxf;
using netDxf.Entities;

namespace netdxftest
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            string file = "sample.dxf";
            DxfDocument dxf = new DxfDocument();
            Line entity = new Line(new Vector2(5, 5), new Vector2(10, 5));
            dxf.AddEntity(entity);
            dxf.Save(file);
        }
    }
}


上記は x=2,y=5 の点から x=10,y=5 まで線を描き、sample.dxf に保存するプログラムです。

ところで、MacOSXのVS2017で上記のプログラムをコンパイルして動作させる為にはmonoフレームワークから実行する必要があります。

手元の環境では以下の方法で実行できました。

/Library/Frameworks/Mono.framework/Versions/5.18.1/bin/mono32 netdxftest.exe

そして、出来上がったDXFをWeb上で描画するサービスをAutodeskが提供していて、以下のサイトにDXFをアップロードするとWeb上で描画することができます。
https://viewer.autodesk.com

利用にはアカウント登録が必要です。