I dug up this bit of code I was working on some time back (on acad 2005) when I was exploring the idea of custom objects with C#, I'm sure I had some more complete code but this is a start.
There is a reference to some of the ARX functions I wrapped required to register the CO but I think PInvoking them would be a better option (mine have a DCS prefix).
In theory I think it's quite possible, the only problem is registering the callbacks acad needs to get the object/entity's description and such so it may be a good exercise in marshaling if nothing else.
The CO is quite simple as I derived from an existing object and simply pass the required calls back to the base object to handle the db work, I did it this way just to get a proof of concept object up and registered, once this is done I can't see a problem with starting from scratch with a Entity base class if you wanted.
For study on what's required you need to dig into the doc's and look under 'Runtime class identification', 'class declaration macros', 'class implementation macros' and 'class initialization function' under the custom objects heading.
This code was written for ac2005 so things like the editor and prompt code will need changing but it's more of an 'layout' than workable code.
If I can dig out the more advanced one I post it as well.
the object-
using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
//using DCSRxFuncs;//******* you can get rid of this and PInvoke probably***********//
namespace ArxTest
{
/// <summary>
///
/// </summary>
public class DCS3dSolid : Solid3d
{
public DCS3dSolid()
{
//
// TODO: Add constructor logic here
//
}
//File writting overrides
public override void DwgInFields(DwgFiler filer)
{
base.DwgInFields(filer);
}
public override void DwgOutFields(DwgFiler filer)
{
base.DwgOutFields(filer);
}
public override void DxfInFields(DxfFiler filer)
{
base.DxfInFields(filer);
}
public override void DxfOutFields(DxfFiler filer)
{
base.DxfOutFields(filer);
}
public override Boolean WorldDraw(WorldDraw wd)
{
Boolean retcode = base.WorldDraw(wd);
return retcode;
}
public override void Extrude(Region region, double height, double taperangle)
{
base.Extrude(region, height, taperangle);
}
//class initialisation and description functions
public static IntPtr gpDesc;
public static RXClass desc()
{
Dictionary D;
D = SystemObjects.ClassDictionary;
return (RXClass)D.At("DCS3dSolid");
}
public static RXClass isA()
{
return desc();
}
public static void rxInit()
{
gpDesc = DCSRxObj.RegisterClass("DCS3dSolid","AcDb3dSolid",0,"DCS3DOBJ","AutoCAD");
return;
}
}
}
the init section at loading -
using System;
using System.IO;
using System.Diagnostics;
using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.ApplicationServices;
//using DCSRxFuncs;//*****USE PINVOKE INSTEAD*******//
[assembly:ExtensionApplication(typeof(ArxTest.DCSApp))]
[assembly:CommandClass(typeof(ArxTest.Commands))]
namespace ArxTest
{
/// <summary>
/// The entry point for autocad, here is where I will (try to) register
/// my custom object with autocad's class hierachy
/// </summary>
public class DCSApp : IExtensionApplication
{
public void
Initialize()
{
AcadApplication app = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
app.ActiveDocument.Utility.Prompt(string.Format("\nLoading DCSApp..."));
DCS3dSolid.rxInit();
app.ActiveDocument.Utility.Prompt(string.Format("\n...made it past rxInit()"));
DCSRxObj.BuildClassHierarchy();
app.ActiveDocument.Utility.Prompt(string.Format("\nLoaded successfully!..."));
}
public void
Terminate()
{
//No point, can not unload .net apps from editor...
//....unloads on close of Autocad!
}
}
}