.NET

Reply
Active Member
PacificorpJB
Posts: 8
Registered: ‎10-25-2010
Message 1 of 3 (368 Views)

Out of process VB.Net

368 Views, 2 Replies
11-10-2010 04:40 PM

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.

 

Valued Contributor
ognyandim
Posts: 59
Registered: ‎05-21-2008
Message 2 of 3 (344 Views)

Re: Out of process VB.Net

11-11-2010 03:26 AM 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 :smileyhappy:
            doc = doc.GetType().InvokeMember("sendcommand",
              BindingFlags.DeclaredOnly |
              BindingFlags.Public | BindingFlags.NonPublic |
              BindingFlags.Instance | BindingFlags.InvokeMethod, null, doc, new Object[] { "netload" });
         }
    }
}

[/code]

 

 


 

Active Member
PacificorpJB
Posts: 8
Registered: ‎10-25-2010
Message 3 of 3 (336 Views)

Re: Out of process VB.Net

11-11-2010 08:25 AM in reply to: ognyandim

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.