DesignCAD Developement with .NET DLL Extensions

Started by SFDev, January 29, 2007, 12:23:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SFDev

   I've been researching what it would take to get .NET working with DesignCAD and I believe there is more capability than previously anticipated.  We all know we can write a application to hook into DCAD via OLE.  That's great and it works well.  The only major drawbacks are speed and .NET compatibility.  The .NET compatiblity issue might not be an issue at all.  We haven't tested it completely and I really haven't seen anything on the forums with anybody deep into development using .NET.  What I've been testing applies to AutoCAD but can also be applied to any COM capable application such as DesignCAD.  I really think that it can open up a new door for DCAD developement. The information below applies to AutoCAD so please bare with me. In the end, it can be applied to DesignCAD.  Anyways, here's what we have been testing:

   Out last AutoCAD version, built before ACAD's 2006 .NET capability, used OLE to take control of AutoCAD.  Our latest version is loaded as a DLL extension straight into ACAD.  The code is almost the same since we're still using ACAD's ActiveX to take control, but the difference in speed is approx a 4000% increase.  The 4000% increase is a medium of the time difference between ten thousand block placements and drawing entity enumeration functions with using OLE and an extension DLL. Basically, it boils down to OLE being slow.  For those of you that aren't familiar with ACAD's .NET managed libraries, I have a perfect test example with pure ActiveX with .NET totally out of the equation.  I wrote a single function for ACAD to draw 10000 lines on a drawing.  That function was then tested in a VB6 EXE by hooking into ACAD using OLE and the second test was written as an ActiveX control which was then loaded into ACAD via ACAD's VBA.

Program 1:
Type:  EXE using OLE Automation (same thing we do with DCAD)
Draw Time:  approx 65 seconds

Program 2:
Type:  ActiveX control loaded into a ACAD VBA module.  VBA passed the ActiveX Autocad.Application object to the "Test" ActiveX object and then called the public function to draw the lines.
Draw Time:  faster than I could click my mouse, look at my watch, and look back up.  I'd actually have to put a timer in to get the actual time but I think the point was made.

Both draw functions in each program were identical:

' *****************************************************
public acApp as AcadApplication

public sub drawTestLines

   dim acDoc as AcadDocument
   dim acLine as AcadLine

   dim sPoint(2) as Double
   dim ePoint(2) as Double
   dim i as Integer

   set acDoc = acApp.ActiveDocument

   for i = 0 to 10000         
      sPoint(0) = i 'x
      sPoint(1) = 0 'y   
      sPoint(2) = 0 'z

      ePoint(0) = i 'x
      ePoint(1) = 10000 'y   
      ePoint(2) = 0 'z

      set acLine = acDoc.ModelSpace.AddLine(sPoint, ePoint)
      acLine.Update
   next

end sub
' *****************************************************

The only difference was if the acApp Application object was set from OLE (CreateObject or GetObject) and having it loaded into ACAD on a much lower level (VBA).  VBA was used because it's fast, runs internally within ACAD, can load an ActiveX DLL, and had the AcadApplication object readily available to pass to the DLL.

   Now, how can this be applied to DesignCAD?  If there was some function in DesignCAD to dynamically load an ActiveX DLL and run a a public "startup()" function in that DLL, we could see some BLAZING DCAD custom programs.  All the ActiveX DLL would need is to reference the DesignCAD Type Library so that when it is loaded into DCAD, DCAD can pass it a reference to the DesignCAD Application object and it could then do whatever it was written to do. I'm not a C++ programmer so I can't write example code on how to load the DLL, however, I do know WIN32's API LoadLibrary() function can do it. 

   With this functionality a whole new door would be opened. We would then be able to write custom DCAD apps with VB.NET... even C#.  The backwards compatiblity from a .NET DLL to a COM DLL has already been tested inside and out by the Microsoft Interoping and Upgrading community.  There are some MDI form issues, however, that is being fixed as we "speak".  Just to be sure of things, I wrote a .NET DLL that contained a single form.  The DLL referenced the ACAD type library, had the previously shown drawTestLines() function, had several functions containing code using .NET specific datatypes, had docking treeviews, toolbars, etc. Before the project was compiled, the Register as COM Interop option was checked, and then the project was compiled.  I then wrote a VBA app in Access that referenced my new COM DLL, created an instance of it, then fired up the single form inside the DLL.  All the controls and code worked flawlessly.  The only thing lost was the XP visual styles on the buttons.  The same thing was done inside ACAD VBA which worked fine also.  Basically, all this boils down to that we can write .NET DLL's and have them run as COM DLL's. 

Now, if we can just get DCAD to load them...

DrollTroll

NET is one of those areas that we just haven't had time to look very deeply into yet. I know it's the "wave of the future", and I've been doing some preliminary exploration with it, but I don't yet know what it will take to get DesignCAD to be more .NET-friendly. For the moment, DesignCAD doesn't have the ability to load and use extension dll's in the manner you describe, but that's an area I hope to research in the near future.

As for .NET in general, my intention is to include a bunch of .NET sample projects in the next dev kit, but I haven't gotten as far as I would like with that effort.


25 years with DesignCAD