.NET

Reply
Mentor
GeeHaa
Posts: 156
Registered: ‎04-14-2005
Message 1 of 8 (420 Views)
Accepted Solution

Adding a document to documentmanager collection

420 Views, 7 Replies
07-30-2013 10:31 AM

Hi,

 

The code below crashes with an "attempt to write to protected memory"  in debug mode (it crashes when it hits acDocMgr.add)but in the Release version it works fine. Should I be worried? I am using Command Flags.Session

Dim acDocMgr As DocumentCollection = Application.DocumentManager 
Dim pStyle As Integer = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("PSTYLEMODE") 
Dim acDoc As Document = Nothing 
If pStyle = 1 Then 
   acDoc = acDocMgr.Add("acad.dwt") 
Else 
acDoc = acDocMgr.Add("acad -Named Plot Styles.dwt") 
End If

 Thanks in Advance

Nevermind I figured it out. I have a startup sequence in my ACAD.Doc file that makes a call to VBA  to pop up a messagebox if the filename doesn't match the drawing number. I disabled it and it runs fine now in debug mode. I'm still wondering why the release version ran fine though.

 

Thanks Again

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 2 of 8 (411 Views)

Re: Adding a document to documentmanager collection

07-30-2013 11:11 AM in reply to: GeeHaa

try this: acDoc = DocumentCollectionExtension.Add(acDocMgr, "acad.dwt")instead.

Mentor
GeeHaa
Posts: 156
Registered: ‎04-14-2005
Message 3 of 8 (406 Views)

Re: Adding a document to documentmanager collection

07-30-2013 11:29 AM in reply to: GeeHaa

Thanks for the reply,

 

I tried using the documentcollectionextension but it still has the same error.

 

this appears in the imediate window

 

A first chance exception of type 'Autodesk.AutoCAD.Runtime.Exception' occurred in AcdbMgd.dll

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 4 of 8 (378 Views)

Re: Adding a document to documentmanager collection

07-31-2013 03:56 AM in reply to: GeeHaa

It sounds like a multi threading issue but without the whole project attached I can't tell what's going on, sorry.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 8 (359 Views)

Re: Adding a document to documentmanager collection

07-31-2013 11:45 AM in reply to: GeeHaa
Try add to Reference: accoremgd.dll
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
GeeHaa
Posts: 156
Registered: ‎04-14-2005
Message 6 of 8 (349 Views)

Re: Adding a document to documentmanager collection

07-31-2013 12:41 PM in reply to: Hallex

Nevermind I figured it out. I have a startup sequence in my ACAD.Doc file that makes a call to VBA  to pop up a messagebox if the filename doesn't match the drawing number. I disabled it and it runs fine now in debug mode. I'm still wondering why the release version ran fine though.

 

Thanks Again

Valued Contributor
sszabo
Posts: 86
Registered: ‎09-05-2012
Message 7 of 8 (339 Views)

Re: Adding a document to documentmanager collection

07-31-2013 01:49 PM in reply to: GeeHaa

In debug mode you are running under msvsmon and your VBA code is running under acad.  You would probably have to use InvokeRequired around your Document object for this to work, again just guessing here.

Mentor
GeeHaa
Posts: 156
Registered: ‎04-14-2005
Message 8 of 8 (333 Views)

Re: Adding a document to documentmanager collection

07-31-2013 01:57 PM in reply to: sszabo

I'm Sorry I meant AcadDoc.lsp file.

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!