Сообщество программистов Autodesk в СНГ

ADN Club => AutoCAD .NET API => Тема начата: Bigmazy от 22-05-2015, 14:24:45

Название: Расстояние между 2мя точками. Метод Editor.GetDistance()
Отправлено: Bigmazy от 22-05-2015, 14:24:45

Доброго времени суток.
Уважаемые форумчане, помогите пожалуйста разобраться начинающему.
В студии компилируется без ошибки.

Код - C# [Выбрать]
  1. [CommandMethod("GDBT")]
  2. public Double GetDistanceBetweenTwoPoints()
  3.         {
  4.             Document acDoc = Application.DocumentManager.MdiActiveDocument;
  5.             PromptDoubleResult pDblRes;
  6.             pDblRes = acDoc.Editor.GetDistance ("\nPick two points: ");
  7.             string p =pDblRes.Value.ToString();
  8.             double pDBL = Math.Round(Double.Parse(p),1);
  9.             return pDBL;
  10.         }

В автокаде вылетает exception

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type.
   at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure)
   at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method)
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
Acdbmgd
    Assembly Version: 19.1.0.0
    Win32 Version: 19.1.108.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202014/AcdbMgd.DLL
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34238 built by: FX452RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR
Название: Re: Расстояние между 2мя точками. Метод Editor.GetDistance()
Отправлено: Александр Ривилис от 22-05-2015, 14:35:00
Приветствую на форуме!
1) Прочитай у меня в подписи как форматировать код.
2) Скопируй в виде текста весь код ошибки и выложи на форум.

P.S.: Ошибка у тебя в том, что GetDistanceBetweenTwoPoints должна возвращать void, а не double.
Функция, которая имеет атрибут CommandMethod не должна ничего возвращать.
Название: Re: Расстояние между 2мя точками. Метод Editor.GetDistance()
Отправлено: Bigmazy от 22-05-2015, 14:44:57
Большое спасибо. )))