/* Commands.cs
* © Andrey Bushman, 2014
* При необходимости закомментируйте или раскомментируйте обозначенные ниже
* символы компиляции соответственно Вашей версии AutoCAD.
* В коде определены следующие команды:
* - Cmd1
* - Cmd2
*/
#define AUTOCAD
// #define AUTOCAD_NEWER_THAN_2012
// #define AUTOCAD_NEWER_THAN_2014
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
#if AUTOCAD
using cad = Autodesk.AutoCAD.ApplicationServices.Application;
using Ap = Autodesk.AutoCAD.ApplicationServices;
using Db = Autodesk.AutoCAD.DatabaseServices;
using Ed = Autodesk.AutoCAD.EditorInput;
using Rt = Autodesk.AutoCAD.Runtime;
using Wn = Autodesk.AutoCAD.Windows;
#endif
namespace Bushman.CAD.Samples.Help {
public class Commands : Rt.IExtensionApplication {
#region PInvoke
#if AUTOCAD_NEWER_THAN_2012
const String fnc_location = "accore.dll";
#else
const String fnc_location = "acad.exe";
#endif
#if AUTOCAD_NEWER_THAN_2014
const String x86_Prefix = "_";
#else
const String x86_Prefix = "";
#endif
#region acedSetFunHelp
const String acedSetFunHelp_Name = "acedSetFunHelp";
[DllImport(fnc_location, CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "acedSetFunHelp")]
private static extern Int32 acedSetFunHelp_x64(
String functionName,
String helpFile,
String helpTopic,
Int32 cmd);
[DllImport(fnc_location, CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl,
EntryPoint = x86_Prefix + "acedSetFunHelp")]
private static extern Int32 acedSetFunHelp_x86(
String functionName,
String helpFile,
String helpTopic,
Int32 cmd);
internal static Int32 acedSetFunHelp(
String functionName,
String helpFile,
String helpTopic,
Int32 cmd) {
if(IntPtr.Size == 4)
return acedSetFunHelp_x86(functionName, helpFile, helpTopic, cmd);
else
return acedSetFunHelp_x64(functionName, helpFile, helpTopic, cmd);
}
#endregion // acedSetFunHelp
#endregion // PInvoke
const String throughAcedSetFunHelp = "ThroughAcedSetFunHelp";
const String f1_msg = "\nНажмите клавишу F1 для открытия нужного " +
"раздела справочной системы.\n";
[Rt.CommandMethod("cmd1", Rt.CommandFlags.Modal)]
public static void Cmd1_Command() {
Ap.Document doc = cad.DocumentManager.MdiActiveDocument;
if(null == doc) {
return;
}
using(doc.LockDocument()) {
doc.Editor.GetPoint(f1_msg);
}
}
[Rt.CommandMethod("cmd2", Rt.CommandFlags.Session)]
public static void Cmd2_Command() {
Ap.Document doc = cad.DocumentManager.MdiActiveDocument;
if(null == doc) {
return;
}
using(doc.LockDocument()) {
doc.Editor.GetPoint(f1_msg);
}
}
public void Initialize() {
Ap.Document doc = cad.DocumentManager.MdiActiveDocument;
Int32 result = Commands.acedSetFunHelp("cmd1",
@"C:\public\ACAD\Debug\MyHelp\MyHelp.chm", throughAcedSetFunHelp, 0);
Int32 result2 = Commands.acedSetFunHelp("cmd2",
@"C:\public\ACAD\Debug\MyHelp\MyHelp.chm", throughAcedSetFunHelp, 0);
}
public void Terminate() { }
}
}