.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C# Developer Information for AutoCAD Automation

1 REPLY 1
Reply
Message 1 of 2
btillman
1240 Views, 1 Reply

C# Developer Information for AutoCAD Automation

We're switching from VB.NET to C#.NET so I'm doing lots of searches today. Trouble is I keep finding old code which no longer applies to what we're trying to do. These will be COM methods, stand-alone exe's which will work outside of AutoCAD. At least for the moment. So where can I find the latest development docs for this?

 

And still being new to this...we have some people running 2009, some 2013 and a few 2014 copies in this shop. Is it impossible to write one set of code which will work for all versions or how would one go about handling this setup?

1 REPLY 1
Message 2 of 2
mcicognani
in reply to: btillman

For documentation, samble, SDKs and whatever else, your starting point should be 'Autodesk Developer Network Open'.

 

For your specific questions:

In you want to develop plug-ins (internal application extensions) for AutoCAD, you will have a complete and well documented access, but you wouldn't be able to have a single binary working on every version. AutoCAD breaks binary compatibility every 3 years, if not less. So, you would be able to have a single DLL working for 2010-2011-2012 version, one for 2013-2014 and one for 2015. Basically you need to change the NET library version. I'm writing out of memory, I'm sure you'll find better references.

 

If you want to develop a stand-alone application you may choose your compiler/language/NET library, but you'll still need COM interfaces.

For easier development you may prefer to reference a specific AutoCAD Type Library (2012, 2013, 2014, 2015, ecc.) but this will tie your application to a specific version, thus falling back to the plugin problem.

You may however develop a stand alone application without referencing a specific type library. This will free your application, but would be extremely more complicated to develop.

 

For example, this is the code for generic access to an AutoCAD application and get the list of Documents:

 

public static List<String> GetOpenFiles()
{
    List<String> result = new List<String>();
 
    try
    {
        // get Application COM Object
        Object acadApp = Marshal.GetActiveObject("AutoCAD.Application");
         if (acadApp == nullreturn null;
 
        // Get current document list
        object objDoc = acadApp.GetType().InvokeMember("Documents"BindingFlags.IgnoreCase | BindingFlags.GetProperty, null, acadApp, null);
        if (objDoc == nullreturn null;
 
        Int64 iCount = Convert.ToInt64(objDoc.GetType().InvokeMember("Count"BindingFlags.IgnoreCase | BindingFlags.GetProperty, null, objDoc, null));
 
        for (int i = 0; i < iCount; i++)
        {
            object[] dataArray = new object[1];
            dataArray[0] = i;
 
            object obj = objDoc.GetType().InvokeMember("Item"BindingFlags.IgnoreCase | BindingFlags.InvokeMethod, null, objDoc, dataArray);
            if (obj != null)
            {
                object objName = obj.GetType().InvokeMember("FullName"BindingFlags.IgnoreCase | BindingFlags.GetProperty, null, obj, null);
                String szName = objName.ToString();
 
                object objRead = obj.GetType().InvokeMember("ReadOnly"BindingFlags.IgnoreCase | BindingFlags.GetProperty, null, obj, null);
                bool bReadOnly = Convert.ToBoolean(objRead);
 
                if (szName.Length > 0) result.Add((bReadOnly ? "R""W") + szName);
            }
        }
    }
    catch (System.Exception ex)
    {
        result = null;
    }
 
    return result;
}

 

Given the added complexity, I'd suggest to go for a multiple plugin versions. The difference between AutoCAD versions are minimal, mainly the NET framework version. The Autoloader mechanism is easy enough to allow to distribute a single bundle folder for every AutoCAD version you may decide to support.

I usually maintain and develop against the latest version, and if needed, I'll port the changes on older versions projects. However, I do not support versions older than 2012, since it was the first version to support the autoloader feature with .bundle folders.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost