Error when calling SaveCopyAs consecutively?

I'm trying to a batch SaveAs for drafts. I call objDoc.SaveCopyAs(fullname & ".pdf")and it works beautifully. How ever if I call the SaveCopyAs again, trying to save as DWG i get the following error:

 

"System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used."

 

I can do any type of saveas I want, only once. It seems like objDoc is losing it's link, but why? Does a SaveAs no longer makes my current opened file the ActiveDocument? How do I avoid this error?

 

Posted by: David Van Doren
Post date: 8/6/2013 1:18:26 PM

5 REPLIES

Error when calling SaveCopyAs consecutively?

Show us the code in question.

 

Posted by: Terry Tyson
Post date: 8/6/2013 1:24:28 PM

Error when calling SaveCopyAs consecutively?

Please excuse the mess..

[code type=vbnet]

Dim name As String

Dim Filepath As String

Dim TodayDate As String

Dim savingpathname As String

name = objDoc.Name

Filepath = objDoc.Path

TodayDate = Date.Now.ToString("yyyyMMdd")

savingpathname = Filepath & "\" & System.IO.Path.GetFileNameWithoutExtension(name) & " " & TodayDate

objDoc.SaveAs(savingpathname & ".pdf")

objDoc.SaveAs(savingpathname & ".dwg")

[/code]

 

So basically objDoc is passed into this and is m_SEapp.ActiveDocument

 

The first SaveAs works fine, the second is where I get the error. If I comment out the first SaveAs the second completes fine. So it seems as if it does one SaveAs and craps out.

 

EDIT - I've tried SaveAs, SaveCopyAs, time delays, and reversing order. Nothing works...

 

Posted by: David Van Doren
Post date: 8/6/2013 1:29:28 PM

Error when calling SaveCopyAs consecutively?

Ok, here's the weird thing. If I SaveAs DWG first, then as a PDF, it works. It seems like when saving as PDF, breaks something. Thoughts?

 

Posted by: David Van Doren
Post date: 8/6/2013 1:53:12 PM

Error when calling SaveCopyAs consecutively?

I tried your suggestion. Didnt seem to make a difference. Still creates the DWG, then it crashes. I've pulled the OleMessageFilter Class directly from the SE Prog Guide. It's seems as if that and App.DoIdle() are for when SE is busy. My error doesnt seem as if it's busy, it seems as if it looses connection to the document object. While doing as SaveAs, App.ActiveDocument doesnt change to the newly created DWG, does it? I know I've have the code I've updated below.

[code type=vbnet]

Try

OleMessageFilter.Register()

Label1.Text = "Creating 2D DWG"

objDoc.SaveAs(savingpathname & ".dwg")

ObjApp.DoIdle()

Label1.Text = "Creating 2D PDF"

objDoc.SaveAs(savingpathname & ".pdf")

Label1.Text = "Creating 3D STEP"

Assy.SaveAs(assysavingpath & ".stp")

Label1.Text = "Creating 3D PDF"

Assy.SaveAs(assysavingpath & ".pdf", , True)

Catch ex As Exception

 

End Try

OleMessageFilter.Revoke()

[/code]

 

Posted by: David Van Doren
Post date: 8/8/2013 9:10:49 AM

Error when calling SaveCopyAs consecutively?

Actually right as I wrote that last post, I figured out that that was the issue. I just reassigned objDoc and all was good. So I have to make sure after every save as, its reassigned.

 

Thanks!

 

-Dave

 

Posted by: David Van Doren
Post date: 8/8/2013 10:37:13 AM