Here's the source of the only two files and code I added to a standard mixed arx/net application wizard solution in VS2002. If you have any trouble creating the solution just holler.
The header file
// IronPyCommandReg.h
// Created: 24th Aug. 2007
// By: Mick Duprez DCS Pty Ltd.
// Usage:
// Used to register commands from IronPython scripts using
// the .net wrapper api for AutoCAD.
#pragma once
#include "stdafx.h"
using namespace System ;
using namespace Autodesk::AutoCAD::Geometry ;
using namespace Autodesk::AutoCAD::DatabaseServices ;
namespace IronPy {
namespace CommandReg {
public __gc class IronPyCommandReg
{
public:
IronPyCommandReg(void);
~IronPyCommandReg(void);
static void RegisterCommand(String* cmd_group,
String* cmd_global_name,
String* cmd_local_name,
System::Int32 cmd_flags,
System::IntPtr pyFunction);
// command flag def's exposed to .net, may not be required???
static int CMD_MODAL = ACRX_CMD_MODAL;
static int CMD_TRANSPARENT = ACRX_CMD_TRANSPARENT;
static int CMD_USEPICKSET = ACRX_CMD_USEPICKSET ;
static int CMD_REDRAW = ACRX_CMD_REDRAW;
static int CMD_NOPERSPECTIVE = ACRX_CMD_NOPERSPECTIVE ;
static int CMD_NOMULTIPLE = ACRX_CMD_NOMULTIPLE;
static int CMD_NOTILEMODE = ACRX_CMD_NOTILEMODE ;
static int CMD_NOPAPERSPACE = ACRX_CMD_NOPAPERSPACE ;
static int CMD_PLOTONLY = ACRX_CMD_PLOTONLY ;
static int CMD_NOOEM = ACRX_CMD_NOOEM;
static int CMD_UNDEFINED = ACRX_CMD_UNDEFINED;
static int CMD_INPROGRESS = ACRX_CMD_INPROGRESS;
static int CMD_DEFUN = ACRX_CMD_DEFUN ;
static int CMD_NONEWSTACK = ACRX_CMD_NONEWSTACK ;
static int CMD_NOINTERNALLOCK = ACRX_CMD_NOINTERNALLOCK;
static int CMD_DOCREADLOCK = ACRX_CMD_DOCREADLOCK;
static int CMD_DOCEXCLUSIVELOCK = ACRX_CMD_DOCEXCLUSIVELOCK;
static int CMD_INTERRUPTIBLE = ACRX_CMD_INTERRUPTIBLE;
static int CMD_NOHISTORY = ACRX_CMD_NOHISTORY ;
static int CMD_NO_UNDO_MARKER = ACRX_CMD_NO_UNDO_MARKER;
static int CMD_NOBEDIT = ACRX_CMD_NOBEDIT;
};
}
}
The cpp file
// IronPyCommandReg.cpp
// Created: 24th Aug. 2007
// By: Mick Duprez DCS Pty Ltd.
// Usage:
// Used to register commands from IronPython scripts using
// the .net wrapper api for AutoCAD.
#include "StdAfx.h"
#include "IronPyCommandReg.h"
//-----------------------------------------------------------------------------
//- Template class that wraps GCHandle from mscorlib.dll
#include <gcroot.h>
//-----------------------------------------------------------------------------
//- autodesk interop header, to aid converting between unmanaged ObjectARX and managed ObjectARX.NET
#include "mgdinterop.h"
using namespace System::Runtime::InteropServices;
IronPy::CommandReg::IronPyCommandReg::IronPyCommandReg(void)
{
}
IronPy::CommandReg::IronPyCommandReg::~IronPyCommandReg(void)
{
}
void IronPy::CommandReg::IronPyCommandReg::RegisterCommand(String* cmd_group,
String* cmd_global_name,
String* cmd_local_name,
System::Int32 cmd_flags,
System::IntPtr pyFunction)
{
acedRegCmds->addCommand(StringToCIF(cmd_group),
StringToCIF(cmd_global_name), StringToCIF(cmd_local_name),
(unsigned int)cmd_flags,
/**** This is the bit that needs work maybe!, we have to marshal a delegate/method
for acad to call when the registered command is invoked ------------------*/
(AcRxFunctionPtr)(void*)Marshal::GetUnmanagedThunkForManagedMethodPtr(pyFunction,0,0));
}
<edit> fixed formatting