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

Autodesk.AutoCAD.AppliationServices.Application -- FileNotFoundException

4 REPLIES 4
Reply
Message 1 of 5
ranger4290
944 Views, 4 Replies

Autodesk.AutoCAD.AppliationServices.Application -- FileNotFoundException

The following is the message that I've been getting when trying to run my application:

FileNotFoundException was unhandled

The specified module could not be found. (Exception from HRESULT: 0x8007007E)

 

In my application, which runs independently, i am finding an instance of autocad(or creating if it does not exist), opening a drawing, and then editing the drawing using code from a different working application (altered slightly) to edit the drawing.

I am able to open autocad and the drawing with no problem, but trying to run the other code runs in to lots of issues.


At first I thought my issues were regarding mdiActiveDocument, since autocad is minimized once the drawing is opened, but as I've been exploring what is wrong I've relized that it is the entire acadApp (using acadApp = Autodesk.Autocad.ApplicationServices.Application) reference is causing issues. I used this multiple times in the original code and I have all the same references both in the drawing and the solution, yet it still is not working.

 

I've pretty much ran out of ideas for how to fix this, any help would be greatly appreciated!

 

Here's some code (let me know if you need anything more):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

using System.IO;

using System.Runtime.InteropServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;

 

...

private void genButton_Click(object sender, EventArgs e)
        {
            // Start AutoCAD
            const string progID = "AutoCAD.Application.18";
            AcadApplication acApp = null;

            try
            {
                acApp = (AcadApplication)Marshal.GetActiveObject(progID);
            }
            catch
            {
                try
                {
                    Type acType = Type.GetTypeFromProgID(progID);
                    acApp = (AcadApplication)Activator.CreateInstance(acType, true);
                }
                catch
                {
                    MessageBox.Show("Cannot create object of type \"" + progID + "\"");
                }
            }

            if (acApp != null)
                acApp.Visible = true;

 

            // Open the drawing (starting with Gen1) that is going to be used.
            string strFileName = @"C:\fileName.dwg"


            
            acApp.ActiveDocument.Close();//close initial blank document

            if (File.Exists(strFileName))
                 acApp.Documents.Open(strFileName, false);
            acApp.WindowState = AcWindowState.acMin; //Minimize the window so it's not in the way


            //DocumentCollection acDocMgr = acadApp.DocumentManager; //causes error

            //if (File.Exists(strFileName))
            //    acDocMgr.Open(strFileName, false);
            //else
            //acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName + " does not exist.");


            Auto105 a105 = new Auto105();
            a105.executeSave(database);

            //acApp.Documents.Close();
            //acApp.Quit();
        }

 

//--From Auto105 class:

        public void executeSave(string DB)
        {
            database = DB;
            LoadBlockIDs();
            SaveBlocks();
            SaveDrawing();
        }

        private void LoadBlockIDs()
        {
            blockIds = new string[10];

            numBlocks = 0;

           //Again the following lines are causing the error (with my adjustments to make it this far)

            Document acDoc = acadApp.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            .....

          }

 

Thanks again for any help!!!

4 REPLIES 4
Message 2 of 5
caddzone
in reply to: ranger4290

You're trying to use the AutoCAD managed API from another application.

 

You can't do that.  It can only be used in a NETLOADed DLL.



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 3 of 5
ranger4290
in reply to: caddzone

Is there a way I can use my NETLOADed .dll from this application then?

Like trigger the .dll to start a command in Autocad?

That would work for my purposes; essentially I'm automating an application I already have working so it would do same/similar code just without the dialog boxes

Message 4 of 5
caddzone
in reply to: ranger4290

The only way to talk to a NETLOADed dll from another process is to

use ActiveX.  You make the NETLOADed dll an ActiveX server and

you access it from aother process using the AcadApplication's

GetInterfaceObject() method.



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Message 5 of 5
ranger4290
in reply to: caddzone

Thanks for your advice and prompt replies. I think what I will end up doing is making this an automated process which runs inside of AutoCAD, rather than a standalone application. That seems to be much easier for me Smiley Happy, and shouldn't be much of a hassle for our engineers and drafters.

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