AutoLISP 函数定义 (.NET) 
定义 AutoLISP 函数时,请使用该属性。该特性需要一个字符串值用作正在定义的 AutoLISP 函数的全局名称。除了全局函数名称外,该结构还可以接受以下值:LispFunctionLispFunctionLispFunction 
 定义 AutoLISP 函数的语法下面演示如何创建定义名为 InsertDynamicBlock 的 AutoLISP 函数的属性。LispFunction VB.NET<LispFunction("InsertDynamicBlock")> _
Public Sub InsertDynamicBlock(ByVal rbArgs As ResultBuffer)
 . . .
End Sub
 
		C#[LispFunction("DisplayFullName")]
public static void DisplayFullName(ResultBuffer rbArgs)
{
 . . .
}
 
		检索传递到 AutoLISP 函数中的值使用循环单步执行 AutoLISP 函数中返回的值。A 是对象的集合。对象的属性可用于确定传递给 AutoLISP 函数的每个值的值类型。该属性用于返回对象的值。ForeachResultBufferResultBufferTypedValueTypeCodeTypedValueValueTypedValue 支持的数据类型包括: 
 定义 AutoLISP 函数此示例代码定义了一个名为 的 AutoLISP 函数。虽然 .NET 项目中定义的方法接受单个值,但 AutoLISP 函数需要两个字符串值才能生成正确的输出。DisplayFullName 将.NET项目加载到AutoCAD中,然后在命令提示符下输入以下命令: (displayfullname "First" "Last") 以下是执行AutoLISP函数后显示的输出: Name: First Last VB.NETImports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
 
<LispFunction("DisplayFullName")> _
Public Sub DisplayFullName(ByVal rbArgs As ResultBuffer)
  If Not rbArgs = Nothing Then
      Dim strVal1 As String = "", strVal2 As String = ""
 
      Dim nCnt As Integer = 0
      For Each rb As TypedValue In rbArgs
          If (rb.TypeCode = Autodesk.AutoCAD.Runtime.LispDataType.Text) Then
              Select Case nCnt
                  Case 0
                      strVal1 = rb.Value.ToString()
                  Case 1
                      strVal2 = rb.Value.ToString()
              End Select
 
              nCnt = nCnt + 1
          End If
      Next
 
      Application.DocumentManager.MdiActiveDocument.Editor. _
         WriteMessage(vbLf & "Name: " & strVal1 & " " & strVal2)
  End If
End Sub
 
		C#using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
 
[LispFunction("DisplayFullName")]
public static void DisplayFullName(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);
  }
}
 
		 | 
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1   苏公网安备32011402011833)
GMT+8, 2025-11-4 19:06
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.