Error "Operation is not valid due to the current state of the object"

Error "Operation is not valid due to the current state of the object"

rtejada
Contributor Contributor
1,644 Views
3 Replies
Message 1 of 4

Error "Operation is not valid due to the current state of the object"

rtejada
Contributor
Contributor
Hi all,

I am getting the "Operation is not valid due to the current state of the object" when doing the following

dim db as New Database (False, True)
db.ReadDwgFile(myfilename,FileOpenMode.OpenforReadAndAllShare,False,Nothing)
db.ResolveXrefs(True,False)
dim tm as Transaction = db.TransactionManager.StartTransaction()

the next line is the one that crashes

dim myDoc as Document = DocumentManager.GetDocument(db)


the line works with the working database, but I need it to work with an unopenned drawing. Is it possible?

Thanks in advance.

Raul
0 Likes
1,645 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
It's my understanding that opening a drawing in the background via ReadDwgFile only opens the drawing's database and doesn't create a document object. In order to access a document you need to open it first.

I would consider whether you really need to open the document into the document collection, and if you do i would open it and set the window.visible property to false.

{code}
Dim doc As Document = Application.DocumentManager.Open(mydrawingfilename, True, "")
doc.Window.Visible = False
{code}

-Mark P.
0 Likes
Message 3 of 4

Anonymous
Not applicable
A Database that's not open in the editor has no associated Document.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:[email protected]...
Hi all,

I am getting the "Operation is not valid due to the current state of the
object" when doing the following

dim db as New Database (False, True)
db.ReadDwgFile(myfilename,FileOpenMode.OpenforReadAndAllShare,False,Nothing)
db.ResolveXrefs(True,False)
dim tm as Transaction = db.TransactionManager.StartTransaction()

the next line is the one that crashes

dim myDoc as Document = DocumentManager.GetDocument(db)


the line works with the working database, but I need it to work with an
unopenned drawing. Is it possible?

Thanks in advance.

Raul
0 Likes
Message 4 of 4

rtejada
Contributor
Contributor
Thanks Mark for the visible trick and thanks Tony, I will look into a "open in the editor" sample, may be more efficient.
0 Likes