C++学习求助
本人采用AutoCAD.net(VS2008,acad2008, 项目已选用NET Framework 2.0)编写一个简单的lisp函数,编译时出现如下提示:------ 已启动全部重新生成: 项目: ClassLibrary2, 配置: Debug Any CPU ------C:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\AutoCAD 2008\acdbmgd.dll" /reference:"C:\Program Files\AutoCAD 2008\acmgd.dll" /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\ClassLibrary2.dll /target:library Class1.cs Properties\AssemblyInfo.cs
编译完成 -- 0 个错误,0 个警告
ClassLibrary2 -> G:\c++bak\ClassLibrary2\ClassLibrary2\bin\Debug\ClassLibrary2.dll
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
而在CAD运行时出现如下错误:System.ArgumentException: 绑定到目标方法时出错。 在 System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo
method, Boolean throwOnBindFailure)
在 AcMgCommandClass.InvokeWorker(AcMgCommandClass* , MethodInfo mi, Object
commandObject, Boolean bLispFunction)
在 AcMgCommandClass.InvokeWorkerWithExceptionFilter(AcMgCommandClass* ,
MethodInfo mi, Object commandObject, Boolean bLispFunction)
在 AcMgCommandClass.Invoke(AcMgCommandClass* ,
gcroot<System::Reflection::MethodInfo ^>* mi, Boolean bLispFunction)
在 AcMgCommandClass.CommandThunk.InvokeLisp(CommandThunk* )
错误:ADS 请求错误
不知是如何原因
代码呢 不要贴一大堆错误提示 谢谢,代码很简单。
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using System.Runtime.InteropServices; // 用DllImport 需用此命名空间
using System.Reflection; // 使用Assembly 类需用此命名空间
using System.Reflection.Emit; // 使用ILGenerator 需用此命名空间
namespace ClassLibrary2
{
public class Class1
{
public static void bb(ResultBuffer rbArgs)
{
if (rbArgs != null)
{
string strVal1 = "";
string strVal2 = "";
int nCnt = 0;
foreach (TypedValue rb in rbArgs)
{
if (rb.TypeCode == (int)Autodesk.AutoCAD.Runtime.LispDataType.Text)
{
switch (nCnt)
{
case 0:
strVal1 = rb.Value.ToString();
break;
case 1:
strVal2 = rb.Value.ToString();
break;
}
nCnt = nCnt + 1;
}
}
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nName: " + strVal1 + " " + strVal2);
}
}
} LispFunction应该有返回值吧 你可以用TypedValue返回一个值或者用resultbuffer返回一个列表或点对 谢谢,三楼代码从《Autocad.net开发指南-2012版》抄来,
现改为如下代码:
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using System.Runtime.InteropServices; // 用DllImport 需用此命名空间
using System.Reflection; // 使用Assembly 类需用此命名空间
using System.Reflection.Emit; // 使用ILGenerator 需用此命名空间
namespace ClassLibrary4
{
public class Class1
{
public string bb(ResultBuffer rbArgs)
{
if (rbArgs != null)
{
string strVal1 = "";
string strVal2 = "";
int nCnt = 0;
foreach (TypedValue rb in rbArgs)
{
if (rb.TypeCode == (int)Autodesk.AutoCAD.Runtime.LispDataType.Text)
{
switch (nCnt)
{
case 0:
strVal1 = rb.Value.ToString();
break;
case 1:
strVal2 = rb.Value.ToString();
break;
}
nCnt = nCnt + 1;
}
}
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nName: " + strVal1 + " " + strVal2);
return strVal1;
}
}
}
}
编译时出现如下错误:
已启动全部重新生成: 项目: ClassLibrary4, 配置: Debug Any CPU ------
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\AutoCAD 2008\acdbmgd.dll" /reference:"C:\Program Files\AutoCAD 2008\acmgd.dll" /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\ClassLibrary4.dll /target:library Class1.cs Properties\AssemblyInfo.cs
G:\c++bak\ClassLibrary4\ClassLibrary4\Class1.cs(18,23): 错误 CS0161: “ClassLibrary4.Class1.bb(Autodesk.AutoCAD.DatabaseServices.ResultBuffer)”: 并非所有的代码路径都返回值
编译完成 -- 1 个错误,0 个警告
========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ========== 本帖最后由 雪山飞狐_lzh 于 2014-9-8 14:53 编辑
按下面的格式
示例,判断字符串是否是由数字组成
public static object IsNumber(ResultBuffer rb)
{
var t = new TypedValue((int)LispDataType.T_atom);
var nil = new TypedValue((int)LispDataType.Nil);
if (rb == null)
return nil;
var arr = rb.AsArray();
if (arr.Length != 1 || arr.TypeCode != (short)LispDataType.Text)
{
return nil;
}
else
{
Regex r = new Regex(@"^\d+(\.)?\d*$");
return r.IsMatch((string)arr.Value) ? t : nil;
}
}命令: (tls:IsNumber "123")
T
命令: (tls:IsNumber "12a3")
nil TypeValue [] tvs = rbArgs.AsArray();
页:
[1]