Author Topic: Out of Memory Exception defining AcadDocument  (Read 4841 times)

0 Members and 1 Guest are viewing this topic.

slappy

  • Guest
Out of Memory Exception defining AcadDocument
« on: May 25, 2010, 05:06:45 PM »
New to the forum and new to .NET.  Done a little VBA, a little LISP, a little asp.net.  So not so much a stranger to programing.  However .NET is a whole new can of woopin-my-a$$.     :ugly:

This is for ACA 2010 using VS Express 2010. I'm accessing the Autodesk version 18 assemblies and .net 3.5 or 2.0 where applicable.

So here's the dilemma.  I'm porting over a VBA project the "Hard way".  Meaning I'm writing it from scratch.  Essentially it's a batch processing dialog that does a number of things.  The problem however is in iterating through my files.  I keep getting an outofmemoryexception on this line:

Code: [Select]
        Dim acadDoc As New Autodesk.AutoCAD.Interop.AcadDocument   ...modified for clarity.

with in the context of:
Code: [Select]
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Interop
Imports acadDocIM = Autodesk.AutoCAD.Interop.AcadDocument


...code list of file names and process procedure


    Public Sub ProcessDwg(ByVal ThisDwg As String, ByVal processedFile As String, ByVal processSelection As Integer)
        BatcherMainDialog.ActiveForm.Hide()

        Dim acadDoc As New acadDocIM
        acadDoc.Application.Documents.Open(ThisDwg)
        acadDoc = AcadApp.ActiveDocument
        Select Case processSelection
            Case 0
                PurgeBlockMethod("border")  ...do something
        End Select
        acadDoc.SaveAs(processedFile, False, False)
        acadDoc.Close(False, processedFile)

    End Sub

Anyway I know it's something really simple, it's just beyond me at the moment.

Thanks

Slap

Glenn R

  • Guest
Re: Out of Memory Exception defining AcadDocument
« Reply #1 on: May 25, 2010, 06:28:10 PM »
I'm not surprised.

Although I don't speak VB.NET, it's time for a little lesson:

Q. What does this line return:
Code: [Select]
acadDoc.Application.Documents.Open(ThisDwg)

Glenn R

  • Guest
Re: Out of Memory Exception defining AcadDocument
« Reply #2 on: May 25, 2010, 06:31:05 PM »
Also, in future, post the context of the called function (ProcessDwg in this case) - I, for one, don't like to guess the calling context and it's more often than not, the cause of the problem.

jgr

  • Guest
Re: Out of Memory Exception defining AcadDocument
« Reply #3 on: May 25, 2010, 09:30:11 PM »
slappy, sorry, but your code is very confusing

With COM +.NET (i think) this is the way:

Code: [Select]
Dim acadApp As AcadApplication = DirectCast(Application.AcadApplication, AcadApplication)
Dim acadDoc As AcadDocument = acadApp.Documents.Open(ThisDwg)
....
acadDoc.Close

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Out of Memory Exception defining AcadDocument
« Reply #4 on: May 25, 2010, 10:31:22 PM »
Also, in future, post the context of the called function (ProcessDwg in this case) - I, for one, don't like to guess the calling context and it's more often than not, the cause of the problem.

In addition :
generally,
in my experience,
insufficient or incomplete information related to problems is the biggest obstacle to producing a solution,

and consequently an incredible time waster for anyone trying to resolve someone elses problem.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

slappy

  • Guest
Re: Out of Memory Exception defining AcadDocument
« Reply #5 on: May 26, 2010, 10:29:46 AM »
Well thanks for the replies and the public correction of my posting procedure...  Did I mention I was new to the forum.  I realize I don't have the experience and/or vocabulary to properly convey the problem I'm experiencing so I will stumble along, and attempt to ignore the Newbie hazing.  :|

I have searched for solutions before stumbling onto this forum, and the provided code is what I found.

In regards to the calling procedure, I created an isolated class and replaced ALL of the variables with specific information and the error still persisted.  So that lead me to conclude the information I provided was sufficent to identify the problem.

Q. What does this line return:
Code: [Select]
acadDoc.Application.Documents.Open(ThisDwg)

Not sure what your asking.  Do you want a return from VS or is the a syntax incorrect?

slappy, sorry, but your code is very confusing

With COM +.NET (i think) this is the way:

Code: [Select]
Dim acadApp As AcadApplication = DirectCast(Application.AcadApplication, AcadApplication)
Dim acadDoc As AcadDocument = acadApp.Documents.Open(ThisDwg)
....
acadDoc.Close

Thanks for the snippet and apologize for my lack of proper syntax.  Your response will give me some direction.  I will see if I can integrate this code and post back my result

Regards
Slap


Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Out of Memory Exception defining AcadDocument
« Reply #6 on: May 26, 2010, 11:28:24 AM »
Well thanks for the replies and the public correction of my posting procedure...  Did I mention I was new to the forum.  I realize I don't have the experience and/or vocabulary to properly convey the problem I'm experiencing so I will stumble along, and attempt to ignore the Newbie hazing.  :|
Meh don't worry about!  We all have our turn(s) in the fire.   :-)

BTW; Welcome to The Swamp!  I will now leave you in capable hands.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

slappy

  • Guest
Re: Out of Memory Exception defining AcadDocument
« Reply #7 on: May 26, 2010, 11:31:23 AM »
Thanks Krushert, I'm feeling the love. :-D

Glenn R

  • Guest
Re: Out of Memory Exception defining AcadDocument
« Reply #8 on: May 26, 2010, 05:34:20 PM »
Q. What does this line return:
Code: [Select]
acadDoc.Application.Documents.Open(ThisDwg)

Not sure what your asking.  Do you want a return from VS or is the a syntax incorrect?

Neither.

Every line in a computer program is essentially an expression and will evaluate, or return, something. It depends on whether you ignore or assign the 'return' value of the expression.

So, with respect to the above, I was asking if you knew what that line returned, or evaluated to. In this case, it's a chained expression, so looking at the right most method/function, I was actually asking what the 'Open' method/function returned.

This is your clue as to why you're getting the specific error you mentioned.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Out of Memory Exception defining AcadDocument
« Reply #9 on: May 26, 2010, 09:19:57 PM »
acadDoc.Application.Documents.Open(ThisDwg)
place your cursor after Open and hit F1,
this brings up the help menu and you will find under description
"Opens the specified drawing and returns a Document object representing the opened drawing. "
So you need to capture the returned doc.
Dim acadDoc As AcadDocument = acadApp.Documents.Open(ThisDwg)
Here acadDoc is the returned Doc.
Do your mojo on acadDoc.

While net is very frustrating at the beginning, it doesn't get much better. :-)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8715
  • AKA Daniel
Re: Out of Memory Exception defining AcadDocument
« Reply #10 on: May 26, 2010, 10:33:36 PM »
While net is very frustrating at the beginning, it doesn't get much better. :-)


 :-D

Chuck Gabriel

  • Guest
Re: Out of Memory Exception defining AcadDocument
« Reply #11 on: May 26, 2010, 10:57:37 PM »
That reminds me of something an old boss used to say.

We're slow, and we make a lot of mistakes, but we're expensive. :-)

slappy

  • Guest
Re: Out of Memory Exception defining AcadDocument
« Reply #12 on: May 27, 2010, 10:10:28 AM »
Code: [Select]
Dim acadDoc As AcadDocument = acadApp.Documents.Open(ThisDwg)

Thanks Bryco, that was the trick...  I knew it was simple.

While net is very frustrating at the beginning, it doesn't get much better. :-)

That's encouraging.  :-o