Can anyone point me in the right direction for this one?
Want to write an out of process EXE that I can call with an argument, a file pathname and then search the block table for a particular block and if found extract the attribute values. Have the last part working fine but am having some trouble getting the AutoCAD connection section working correctly. Assume that I'll need to use COM Interop but I have yet to come up with a solid example.
Really appreciate some code examples.
Thanks in advance.
Try exploring this code.
[code]
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace acad_net
{
class Program
{
static void Main(string[] args)
{
//Instance of AutoCAD
Type AppType = Type.GetTypeFromProgID("Autocad.Application");
Object App = Activator.CreateInstance(AppType);
// Get AcadDocuments
Object doc =
AppType.InvokeMember("documents",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.GetProperty, null, App, null);
// Open a document and add it to the current database
doc =
doc.GetType().InvokeMember("open",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.InvokeMethod, null, doc, new Object[] { "C:\\drawing2.dwg", false });
// Make the document visible
AppType.InvokeMember("visible",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.SetProperty, null, App, new Object[] { 1 });
// Execute some command - zoom for this example
doc.GetType().InvokeMember("sendcommand",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.InvokeMethod, null, doc, new Object[] { "zoom e " });
//
Object ut = // utility object
doc.GetType().InvokeMember("utility",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.GetProperty, null, doc, null);
// Some prompt
ut.GetType().InvokeMember("prompt",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.InvokeMethod, null, ut, new Object[] { "Hello Hello Hello Hello : " });
// execute netload - if you fant to load something - load it yourself 🙂
doc = doc.GetType().InvokeMember("sendcommand",
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.InvokeMethod, null, doc, new Object[] { "netload" });
}
}
}
[/code]