using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Exception = System.Exception;
[assembly: CommandClass(typeof(AutoCAD_CSharp_plug_in35.MyCommands))]
namespace AutoCAD_CSharp_plug_in35
{
public class MyCommands
{
[LispFunction("test", "MyLispFunctionLocal")]
public void MyLispFunction(ResultBuffer args) // This method can have any name
{
if (args != null)
{
TypedValue[] values = args.AsArray();
if (values .Length == 1 && values[0].TypeCode == (int)LispDataType .ObjectId )
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
try
{
var id =(ObjectId ) values[0].Value;
var obj = (DBObject) id.GetObject(OpenMode.ForRead);
foreach (MemberInfo objMemberInfo in obj.GetType().GetMembers())
{
ed.WriteMessage("\n" + objMemberInfo.Name.ToString());
}
tr.Commit();
}
catch (Exception)
{
throw;
}
}
}
}
}
}
}
http://bbs.xdcad.net/thread-679007-1-1.html
<CommandMethod("Tctype1", CommandFlags.Modal)> _
Public Sub MyLispFunction()
' This method can have any name
Dim dwg As Document = Application.DocumentManager.MdiActiveDocument
Dim result As PromptEntityResult = dwg.Editor.GetEntity(vbLf & "Select entity: ")
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim tr As Transaction = db.TransactionManager.StartTransaction()
Using tr
Try
Dim id As ObjectId = CType(result.ObjectId, ObjectId)
Dim obj As DBObject = CType(id.GetObject(OpenMode.ForRead), DBObject)
For Each objMemberInfo As MemberInfo In obj.[GetType]().GetMembers()
ed.WriteMessage(vbLf + objMemberInfo.Name.ToString())
Next
tr.Commit()
Catch generatedExceptionName As Exception
Throw
End Try
End Using
End Sub
[本日志由 tiancao1001 于 2019-08-14 02:37 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |