Someone asked by email how to get the block import code first shown last week and further discussed in yesterday's post working with AutoCAD 2006. I've been using AutoCAD 2007 for this, but to get it working there are only a few changes to be made.
Firstly you'll need to make sure you have the correct versions of acmgd.dll and acdbmgd.dll referenced into the project (you should be able to tell from their path which version of AutoCAD they were installed with).
Secondly you'll need to modify your code slightly, as WblockCloneObjects() has changed its signature from 2006 to 2007. The below code segment shows how to use pre-processor directives to implement conditional compilation in C#. You will need to set either AC2006 or AC2007 as a "conditional compilation symbol" in your project settings for this to work:
#if AC2006
mapping = sourceDb.WblockCloneObjects(blockIds,
destDb.BlockTableId,
DuplicateRecordCloning.Replace,
false);
#elif AC2007
sourceDb.WblockCloneObjects(blockIds,
destDb.BlockTableId,
mapping,
DuplicateRecordCloning.Replace,
false);
#endif
You would possibly use #else rather than #elif above, simply because that would make your code more future-proof: it would automatically support new versions without needing to specifically add code to check for them.
On a side note, you can actually specify that entire methods should only be compiled into a certain version. Firstly, you'll need to import the System.Diagnostics namespace:
using System.Diagnostics;
Then you simply use the Conditional attribute to declare a particular method (in this case a command) for a specific version of AutoCAD (you might also specify a debug-only command by being conditional on the DEBUG pre-processor symbol, should you wish):
namespace BlockImport
{
public class BlockImportClass
{
[Conditional("AC2007"),CommandMethod("IB")]
public void ImportBlock()
{
...