.NET

Reply
Valued Contributor
Ertqwa
Posts: 99
Registered: ‎10-03-2011
Message 1 of 4 (460 Views)
Accepted Solution

Active Document - eNotFromThisDocument error

460 Views, 3 Replies
01-14-2012 03:33 PM

Hello Forum,

 

the following code gives me an eNotFromThisDocument error:

 

[LispFunction("MyFunction")]
public ResultBuffer MyFunction(ResultBuffer rbParameter)
{
    ...
    objDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(strPath, false);
    if (!objDocument.IsReadOnly)
    {
        using (objDocumentLock = objDocument.LockDocument())
        {
            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = objDocument;
            objDocument.Database.TileMode = true; //  = eNotFromThisDocument.
        }
        objDocument.CloseAndSave(strPath);
        objDocument.Dispose();
    }
    ...
}

 I think it is because the Editor does not get linked to the newly opened drawing. In other words, I can not change tilemode of objDocument, because the drawing from which I called this function is still the active/current drawing. How can I tell AutoCAD that objDocument should be the active/current drawing, so I can change the tilemode, and use Editor functionality, such as SendString()?

 

Thank you.

Hi,

 

as a guess: in LISP you get lost if the document changed as LISP-code it runs document-based. If you start a LISP in A.DWG you can start to load B.DWG but the lisp-code will not continue in B.DWG.

That you load a drawing and make the this other drawing active within a LISP-function may be the source of the problem.

 

- alfred -

*Expert Elite*
Alfred.NESWADBA
Posts: 9,378
Registered: ‎06-29-2007
Message 2 of 4 (447 Views)

Re: Active Document - eNotFromThisDocument error

01-15-2012 12:39 AM in reply to: Ertqwa

Hi,

 

as a guess: in LISP you get lost if the document changed as LISP-code it runs document-based. If you start a LISP in A.DWG you can start to load B.DWG but the lisp-code will not continue in B.DWG.

That you load a drawing and make the this other drawing active within a LISP-function may be the source of the problem.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 4 (427 Views)

Re: Active Document - eNotFromThisDocument error

01-15-2012 12:01 PM in reply to: Ertqwa

See if this works for yoy, tested on A2010

<code>

[LispFunction("MyFunction")]
public ResultBuffer MyFunction(ResultBuffer rbParameter)
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
string strPath = .....;
using (DocumentLock objDocumentLock = doc.LockDocument())
{
Document objDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(strPath, false);
if (!objDocument.IsReadOnly)
{
using (DocumentLock pDocumentLock = objDocument.LockDocument())
{

Database pdb = HostApplicationServices.WorkingDatabase;
if (pdb.TileMode == true)
pdb.TileMode = false;
//Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("ctab", "Floor Plan");//debug only

}

objDocument.CloseAndSave(strPath);
objDocument.Dispose();
}

}

return new ResultBuffer(new TypedValue((int)LispDataType.Nil));
}

</code>

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
Ertqwa
Posts: 99
Registered: ‎10-03-2011
Message 4 of 4 (403 Views)

Re: Active Document - eNotFromThisDocument error

01-16-2012 12:29 PM in reply to: Hallex
Hello Hallex, with your code I no longer get the "eNotFromThisDocument" error, but that is because "HostApplicationServices.WorkingDatabase" returns the database of the drawing from which I run the lisp function, and not the database from the drawing that I open with "DocumentManager.Open". Thank you for the response.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!