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

Out of process VB.Net

2 REPLIES 2
Reply
Message 1 of 3
PacificorpJB
587 Views, 2 Replies

Out of process VB.Net

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.

 

2 REPLIES 2
Message 2 of 3
ognyandim
in reply to: PacificorpJB

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]

 

 


 

Message 3 of 3
PacificorpJB
in reply to: ognyandim

Thank you I'll try and take a look today.

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