.NET

Reply
Distinguished Contributor
eljobe
Posts: 707
Registered: ‎01-24-2003
Message 1 of 8 (135 Views)

error exitign acad

135 Views, 7 Replies
02-07-2007 10:00 PM
I have the following sub that works fine...apparently. However, when you close acad, you get an error, usually that the error handler was re-entered. I've traced it to Autodesk.Autocad.Runtime.RxObject.Dispose. When this method is called during shutodown, there is a system.NullObjectReference error. If I comment out this sub, the error does not occur. I can't figure out what there is about this sub that would cause this.
[code]
Public Sub LogPlot()
'Get the csv log file.
Dim LogFile As StreamWriter = File.AppendText(ca.LogFilePath)
'Append plot info
LogFile.WriteLine(ca.Job & "," & ca.Copies & "," & ca.DocName & "," & TimeString() & "," & DateString)
LogFile.Close()
End Sub[/code]
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 2 of 8 (135 Views)

Re: error exitign acad

02-07-2007 10:08 PM in reply to: eljobe
What is the ca variable.

Regards - Nathan
*Norman Yuan
Message 3 of 8 (135 Views)

Re: error exitign acad

02-08-2007 06:26 AM in reply to: eljobe
I have run into similar situation. By "similar", I mean the process involves
object in System.IO namespace, in your case, it is Stream, in my case it is
File object. The symptom is almost identical.

Here is what I had:

In a CAD process, my code does the following:

1. Open several drawings in Acad (4 for now);
2. Have Acad do something with these drawings: inserting a block at given
point;
3. Save the change to each drawing and close it one by one. After all
processed drawings are closed, only an unnamed drawing (Drawing1.dwg) left
open, which is opened when Acad starts;
4. Use System.IO.File.Copy() to move those processed and closed drawings to
a given folder.

All these steps executed just file: drawings are processed correctly (block
inserted), closed normally, and copied to given location. However, when you
close Acad (whether you close the remaining blank drawing first or not), you
got fatal error message after Acad closed and disappeared from screen. The
error, of course, does not affect anything when you start Acad next time,
just a bit annoying.

I found workaround with my code, but the reason of the issue is still
unknown to me, and not solved. My workaround is in step 3 of above, instead
of save the drawing and close it, now I directly save the drawing "As" to
given location (e.g. call Document.CloseAndSave(fileName), if the block
inserting is OK. Thus, I do not need step 4 (e.g. using File.Copy() to move
the closed drawing to given folder). Since no File.IO object is used, when
closing Acad, the error message is gone.

I now recall another .NET API program I wrote a while ago, in which I also
used System.IO.File to rename, copy and delete some files (they are small
*.txt and *.dbf and *.shp, not *.dwg). Since that program deployed, our
Acads often give error message when closing (randomly, not always). Now I
guess it is the same issue.

It must be related with using System.IO namespace with Acad .NET API.

Do someone else also observe this issue?


wrote in message news:5479209@discussion.autodesk.com...
I have the following sub that works fine...apparently. However, when you
close acad, you get an error, usually that the error handler was re-entered.
I've traced it to Autodesk.Autocad.Runtime.RxObject.Dispose. When this
method is called during shutodown, there is a system.NullObjectReference
error. If I comment out this sub, the error does not occur. I can't figure
out what there is about this sub that would cause this.
[code]
Public Sub LogPlot()
'Get the csv log file.
Dim LogFile As StreamWriter = File.AppendText(ca.LogFilePath)
'Append plot info
LogFile.WriteLine(ca.Job & "," & ca.Copies & "," & ca.DocName & ","
& TimeString() & "," & DateString)
LogFile.Close()
End Sub[/code]
Distinguished Contributor
Mikko
Posts: 212
Registered: ‎10-03-2003
Message 4 of 8 (135 Views)

Re: error exitign acad

02-08-2007 07:04 AM in reply to: eljobe
I think you might have to flush the file before you close it.

LogFile.flush()
LogFile.Close()
Distinguished Contributor
eljobe
Posts: 707
Registered: ‎01-24-2003
Message 5 of 8 (135 Views)

Re: error exitign acad

02-08-2007 08:33 AM in reply to: eljobe
Its a global type that holds the data to be written to file.
Distinguished Contributor
eljobe
Posts: 707
Registered: ‎01-24-2003
Message 6 of 8 (135 Views)

Re: error exitign acad

02-08-2007 08:38 AM in reply to: eljobe
I'll give that a try. I also tried Dispose on the LogFile and that didn't make any difference. If the problem is like Norman's, in that it is simply related to using System.IO, then I'll use some old vb methods to write to a txt file.
Distinguished Contributor
eljobe
Posts: 707
Registered: ‎01-24-2003
Message 7 of 8 (135 Views)

Re: error exitign acad

02-08-2007 02:02 PM in reply to: eljobe
It wasn't the previous sub as I thought. It was in another sub that runs after that one during the plot.EndDocument event. The following line was causing the problem:
Dim db As Database = New Database(False, False)

I had to get rid of it and use straight com interop. This is part of the sub mentioned in this thread: http://discussion.autodesk.com/thread.jspa?threadID=539850.
Distinguished Contributor
eljobe
Posts: 707
Registered: ‎01-24-2003
Message 8 of 8 (135 Views)

Re: error exitign acad

02-09-2007 09:02 AM in reply to: eljobe
Apparently, the cause is because the var pointed to the current doc, when acad disposes of it the var no longer has a valid pointer and thus a Null exception is generated.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.