Process large amounts of drawings

Process large amounts of drawings

Anonymous
Not applicable
4,067 Views
19 Replies
Message 1 of 20

Process large amounts of drawings

Anonymous
Not applicable

I am still struggling to come up with an efficient method in VB.NET to process large amounts of drawings.  I am using AutoCAD 2015 and my code is in VB.NET.  I find I can process 20-30 drawings properly, but then the processing slows to a crawl to the point where it just freezes.  I know it is nothing to do with what I am doing in the processing of drawings as I have stripped it down to the app just opening and closing drawings, and it STILL craters on itself in a short amount of time. 

Does anyone have any code examples that shows swift and efficient processing of hundreds of drawing files in VB.NET?

 

Thanks!

Jeff

0 Likes
4,068 Views
19 Replies
Replies (19)
Message 2 of 20

tbrammer
Advisor
Advisor

Have you considered to use the AutoCAD Core Console? You can start multiple instances of it and process drawings parallel. Each instance can end after one drawing is processed.  So you won't get slowdown even with many DWGs. 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 3 of 20

tbrammer
Advisor
Advisor

(Accidentally posted twice)


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 4 of 20

Anonymous
Not applicable

How would I go about calling this?  I need to call it from within my application to process specific code on each drawing.

 

Thanks!

 

0 Likes
Message 5 of 20

dgorsman
Consultant
Consultant

Thats the recommended method of handling large numbers of files, effectively running a single command-line session per DWG file.  It avoids some problems associated with memory management in Windows.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 6 of 20

Anonymous
Not applicable

Ok, but let's say I have hundreds of drawings in a multitude of different directories that the user needs to process, they are running my .NET application, then they will press a button in my application that will launch a function that will process hundreds of drawings.  How would I initiate the process of opening separate windows of AutoCAD, opening each of these hundreds of files then have my code for processing each of these files run?  What would the code look like?

 

Thanks!

 

 

0 Likes
Message 7 of 20

dgorsman
Consultant
Consultant

No windows - remember, the core console is "GUI-less".  Your executeable would manage the calls to start the program with a specific drawing, probably with a very simple script to do [whatever], then save and close.  You could let each one finish in turn, or get a little fancy and specify a maximum number of simultaneous calls, calling the next from the pool of drawings as another finishes.

 

Edit: a quick search turned up some useful info: http://through-the-interface.typepad.com/through_the_interface/2012/02/the-autocad-2013-core-console...

 

You may find other results helpful.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 8 of 20

Anonymous
Not applicable

Ok, sounds like a great way to process mass quantities, and this would mean that you do not have to worry about crashes because of bad drawings.  The only thing is that the processing of each drawing is not a simple script.  I do quite a bit to the drawings as each one is opened.

 

Do you know of a link to this core console details and how it all works?

 

Thanks for your help!

0 Likes
Message 9 of 20

dgorsman
Consultant
Consultant

You still need to worry about corrupt/"bad" drawings but it can be handled within your host application.  Handy for logging which drawings bounce without dropping the remaining files.

 

If you're not able to break the complex operations down into simple operations you'll need to take a different route.  I've used a single AutoCAD session to process groups of around 50 drawings at a time with reasonable times *but* that operated inside AutoCAD.  It would be possible to do something similar to ScriptPro (if not using it outright) to launch sequential sessions to do the same - create list of drawings, open AutoCAD, operate on each drawing, close AutoCAD; create next list; and so on.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 10 of 20

Anonymous
Not applicable

Most of these functions that process mass drawings will be running anywhere from 600-1500 drawings at a time.  Funny thing is that VBA could do this without ANY issues at all in earlier releases of AutoCAD.  I thought .NET would be even better, but it is proving to be a beast.  

 

Script Pro is not an option because this all has to be invisible to the user.  But I like the idea of handling the drawings like script pro like you suggest.  So from my parent app, I would launch separate instances of AutoCAD 2015 that would automatically load the drawing and run a dll that would contain my more intense single file processing code.  How would I go about doing that?  This sounds like probably the most bulletproof option.

 

Thanks!

 

0 Likes
Message 11 of 20

tbrammer
Advisor
Advisor

Refer to the docs of the AutoCAD core console (ACC). You can pass a DWG name and a script file (.scr) name as parameters.

Additionaly it is possible to load .CRX or .Net modules that implement your command.

There are certain restrictions for the modules. They may not reference GUI related stuff.

You have to make sure that the module with the command you need is loaded. It could be loaded by script or via proper registration of the command.

Now for each DWG you need to process, you just call ACC with an appropriate script.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 13 of 20

Anonymous
Not applicable

I am wading my way through this as the core console sounds like exactly what I need.  I need the give the ability for my users to process mass amounts of drawings from within my .NET app.  I am having some issues getting it working though.

 

Basically I followed some of Augusto's code to launch the scr file which then in turn would load the stripped down .NET dll that will process.  I have simplified in the below example to just basically get it working, then will add the actual code.  I am using 2015 AutoCAD.

 

Contents of my main .NET dll to launch the core console:

 

Private Sub Button7_Click_1(sender As Object, e As EventArgs) Handles Button7.Click
Dim process As New Process()
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.CreateNoWindow = True

 

Dim scriptFile As String
Dim fileName As String
scriptFile = "C:\SYSTEM_NO\core_console.scr"
fileName = "C:\PD612-A-JEFF-9009-1.DWG"

 

process.StartInfo.FileName = "C:\Program Files\Autodesk\AutoCAD 2015\accoreconsole.exe"

Dim param As String

 

param = " /s " & scriptFile
param = param & " /i " & fileName
process.StartInfo.Arguments = param
Try

Using (process)

process.Start()
End Using
Catch
MsgBox(Err.Description)
End Try

End Sub

 

So, the contents of the scr file are as follows.  It just loads the dll, the executes a function:

 

(command "_.Netload" "C:\\system_no\\core_console.dll")
Test1

 

And here is the example of the dll that is called:

 

Option Strict Off
Option Explicit On

Imports VB = Microsoft.VisualBasic

Imports System.IO


Public Class Class1
Public Sub Test1()

MsgBox("It ran")


End Sub
End Class

 

 

This is the result of what I get when the core console window comes up:

 


Regenerating model.
Press ENTER to continue:

Command:
Command:

Command:
Command: (command "_.Netload" "C:\\system_no\\core_console.dll")
_.Netload Assembly file name: C:\system_no\core_console.dll
ommand: nil

Command: Test1
Unknown command "TEST1". Press F1 for help.

Command: _quit

Command:
C:\Program Files>

 

Even when I try to run the script and dll directly through the core console, I get the same error:

 

C:\Program Files\Autodesk\AutoCAD 2015\accoreconsole.exe /i C:\PD612-A-JEFF-9009-1.DWG /s C:\SYSTEM_NO\core_console.scr /l en-US

0 Likes
Message 14 of 20

CADbloke
Advocate
Advocate

You misssed the CommandMethod Attribute on Sub Test1. See 

 

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUI...

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
Message 15 of 20

Anonymous
Not applicable

Thanks guys!  This has helped greatly.  Got the core console working well for my processing.  Going to throw some more stuff at it to see where it's breaking points are!

Thanks again.

0 Likes
Message 16 of 20

jeff
Collaborator
Collaborator

Here is an example that might help

 

http://www.theswamp.org/index.php?topic=41948.msg551684#msg551684

 

You can also find your answers @ TheSwamp
0 Likes
Message 17 of 20

Anonymous
Not applicable

If I am firing off a process to run through core console, and if I need to pass arguments to the dll that will be loaded through the script file, is there any possible way of doing this?  I need to specify a database connection string in the dll that is loaded when the drawing through the core console is loaded.  I have the variable value in my core dll that executes the core console call, but I also need it in the dll that is loaded through the script file.

 

Any thoughts?

 

Thanks!

Jeff

 

0 Likes
Message 18 of 20

dgorsman
Consultant
Consultant

DLLs don't take arguments - methods do.  You can do this through a couple of methods.

 

One of the easiest would be to define a command method (or methods, if you need multiple presets) which act as calling wrappers to the methods, provding arguments as needed.  Rather than hard coding that database connection string, create an object to handle the connection, and have that object check for a registry entry, simple data file, or other external source.  Then you can control where it points using an external program ie. the one thats calling the core console controller.

 

You could also build the commands to take arguments, much as LINE and other AutoCAD commands prompt for points.  Then you can build the calling script to provide appropriate input at the command line.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 19 of 20

tbrammer
Advisor
Advisor

This is important information if you want to run mulitple instances of the AutoCAD Core Console (ACC) parallel:

You must to use the  /isolate <regkey> <working_directory>  argument in the command line to avoid stability issues!

 

Balaji Ramamoorthy also reported my findings here in his blog.

I use the ACC for batch plotting multiple DWGs. My application checks the number of processor cores N in the machine and starts N-1 threads.

Each tread basically does this loop:

 

  <J> =  getThreadNumber()    // <J> = 1, 2, ... N-1

  while (<dwg> = getNextDWG())  {

     start accoreconsole /i <dwg> /s c:\script.scr /isolate user<J> c:\temp\acc<J>

     wait until ACC finishes

  }

 

So i.e. I might have these calls running parallel:

 

   accoreconsole /i c:\drwA.dwg /s c:\myscript.scr /isolate user1 c:\temp\acc1

   accoreconsole /i c:\drwB.dwg /s c:\myscript.scr /isolate user2 c:\temp\acc2

   ...

   accoreconsole /i c:\drwX.dwg /s c:\myscript.scr /isolate user7 c:\temp\acc7

 

 

Before I used different working directories c:\temp\acc<J> the ACC sometimes failed in one of these ways:

 

 + ACC crashed

 + ACC ate up more and more memory (1GB, 2GB, ... ) until Windows crashed!!

 + ACC ran forever

 

The shorter the time between two ACC starts was the higher was the probability of an ACC failure.

Using   /isolate user<J> c:\temp\acc<J>   completely fixed the problem. Apparently this avoids access to shared resources.

 

ACC will even create a new working directory  c:\temp\acc<J>   if it doesn't exist.

Note: This directory will contain a lot of stuff: About 150MByte!

 

The <regkey> argument (user<J> in my example) can be any arbitrary name. It doesn't have to be an existing Windows user name or something. ACC will create a temporary registry path with this key.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 20 of 20

BKSpurgeon
Collaborator
Collaborator

Hey Jeff i'm sure heaps of other folks would love to be able to do what you're doing now. 

 

any code that you post will help future readers trouble shoot and will be much appreciated.

 

personally speaking I will be following these threads quite closely.

 

rgds

BK

0 Likes