//创建 AutoCAD 对象
var cad = com.cad();
cad.Visible = true;
//创建 C# 语言编译器
var compiler = cad.NetCompiler("C#");
compiler.Source = /******
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using Wnd = System.Windows.Forms;
public class TestFunctions
{
[LispFunction("ListfunSelfiles")]
public static ResultBuffer ListfunSelfiles(ResultBuffer DataIn)
{
ResultBuffer Ret = new ResultBuffer();
if (DataIn == null) return null;
TypedValue[] Tranlisp = DataIn.AsArray();
try
{
if (Tranlisp.Length == 2)
{
string Title = Tranlisp[0].Value as string;
string Filter = Tranlisp[1].Value as string;
string FilterIn = "(*." + Filter + ")|*." + Filter;
Wnd.OpenFileDialog openDlg = new Wnd.OpenFileDialog();
openDlg.Title = Title;
openDlg.Filter = FilterIn;
openDlg.Multiselect = true;
Wnd.DialogResult openRes = openDlg.ShowDialog();
if (openRes == Wnd.DialogResult.OK)
{
string[] strNames = openDlg.FileNames;
for (int i = 0; i < strNames.Length; i++)
{
Ret.Add(new TypedValue((int)LispDataType.Text, strNames[ i ]));
}
}
else
{
return null;
}
}
}
catch (Autodesk.AutoCAD.Runtime.Exception)
{
return null;
}
return Ret;
}
}
******/
var assembly = compiler.Compile("/ListfunSelfiles.dll"); //编译并返回程序集
console.log(compiler.getLastError()); //查看编译器错误信息