Slow and jerky VB performance on AutoCAD 2015

Slow and jerky VB performance on AutoCAD 2015

dnl999
Advocate Advocate
736 Views
5 Replies
Message 1 of 6

Slow and jerky VB performance on AutoCAD 2015

dnl999
Advocate
Advocate

I have a some old vb projects which work fine in all versions except 2015.

 

In a very simple vb routine below, I tried to get all the layers by the following code in a form with a listbox box when it loads :

 

 

Public Class Form1

Dim oAcad As AutoCAD.AcadApplication

Dim oAcadDoc As AutoCAD.AcadDocument

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Try

 oAcad = GetObject(, "Autocad.Application.20")

 If oAcad.Documents.Count > 0 Then

   oAcadDoc = oAcad.ActiveDocument

    Try

      For Each oLayer As AutoCAD.AcadLayer In oAcadDoc.Layers

         Me.lstLayer.Items.Add(oLayer.Name)

      Next

    Catch ex1 As System.Exception

      Debug.WriteLine("1:" + ex1.Message)

    End Try

Else

    MsgBox("No Document Opened.")

End If

Catch ex2 As Exception

MsgBox("2:" + ex2.Message)

End Try

End Sub

End Class

'

'

'

Strangely, it does not return the complete list of layers but only some of the layers ( the number of layers varies every time I run it).

 

I tried to troubleshoot and it is returning the following error message:

 

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in GetAllLayers2015.exe

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in CustomMarshalers.dll

first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)

 

On one computer it seems to work fine without any problem.

But it is definitely slow on all other computers I've tested on.

 

Any idea what could be causing this problem ?

I am using VS2012.

 

TIA.

 

Andrew,

 

 

 

 

0 Likes
737 Views
5 Replies
Replies (5)
Message 2 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I have a some old vb projects which work fine in all versions except 2015.

So 2016 is fast?

 

>> On one computer it seems to work fine without any problem.

>> But it is definitely slow on all other computers I've tested on.

Find out the differences, either what's installed on the system or if there are different service packs of AutoCAD installed or there are any applications on top of AutoCAD (or plugins, tools, ...) and at least if the AutoCAD profile and workspaces are equal or different.

My favorite: on this one system the layermanager-dialog is not started, so this does not need to be updated every time a layer is added.

 

>> occurred in GetAllLayers2015.exe

Running the app in an external EXE is always slower than in-process. By any chance create a DLL that can be loaded into AutoCAD's memory using command _NETLOAD gives you other methods, the option to run with transactions an so maybe 1000 times faster compared to your COM-based out-of-process situation.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 6

dnl999
Advocate
Advocate

As a follow-up, I am attaching an example of compiled routine which lists all the layers (as shown on the above code) from the active autocad 2015 drawing via COM interface.

It works fine on only one computer with 64bit Windows 7, but does not work on other computers with AutoCAD 2015 I've tested (both with Windows 7 & Windows 8).  It is returning only a partial list of layers.

 

It is very strange and I've never seen this problem in the previous versions of AutoCAD including AutoCAD 2014.  But for 2015 & 2016 it is not working !

 

Anyone has any idea ? 

 

Since it is working at least on one computer there must be a solution.

 

TIA.

0 Likes
Message 4 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> It works fine on only one computer

Now you have found a second workstation with correct results, I tried your exe (after ILSPY'ing it out of security reasones, I guess starting an unknown EXE is a bit sensitive 😉 ), I tried it with 2015 and 2016 on Win8.1. All drawings I tested (also with a lot of layers) your exe show the correct number on your first line (I have not counted the items in listview manually).

 

So I guess you have to search for "what is wrong with the workstations you tested and which failed, repair AutoCAD, repair FrameWork, check if there are any plugins/apps/tools. Maybe just creating a new AutoCAD profile that does not contain any customizations, could be helpful.

 

What you can try: in your code, before starting the loop through the layer, let report the count of layers

   Call MsgBox(oAcadDoc.Layers.Count)

Does this report the correct number?

 

I'm not sure if it's ILSPY that converts during uncompile, I see that it's using an Enumerator to scan through the layers, maybe (not as fast, but just to try) you can run your loop through an index-counter, like

   Dim i as Integer

   For i = 0 to oAcadDoc.Layers.Count-1

      Dim oLayer as AcadLayer = oAcadDoc.Layers.Item(i)

      '... now add this to your listbox

   Next

This is just a test, it has nothing to to with correct  or incorrect code.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 6

dnl999
Advocate
Advocate

Thanks again for your reply.

I've tried your code but the result was same, but layers.count was correct.  It looks like Acad is having problem via COM before getting the entire list of layers in the loop.

 

I've just installed AutoCAD 2015 (student version) on a new laptop with Window 8.1 and tested the same exe file posted, and it still didn't work.

 

I am glad that it was working on your computer because that tells me there is nothing wrong with the compiled exe file created.

Thanks again.

 

 

0 Likes
Message 6 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

Another idea: download the VBA-Enabler and run that loop within VBA ... do you have then the same issue?

 

>> I've tried your code but the result was same, but layers.count was correct.

Wow, that's strange, because that means that my for-next-loop runs e.g. 100 passes and without any exception layers are lost to add to the list?

Maybe it's more a problem with adding the items to the list? When you output the layers to an ascii-file or a collection ...same issue then?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes