.NET

Reply
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 11 of 27 (171 Views)

Re: equivalent to arx "acedSetStatusBarProgressMeter" ?

05-23-2006 01:37 AM in reply to: newArch
I tried it now and still got the same error. Is it possible that it does not
work in Acad2007?

--
Roland Feletic
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 12 of 27 (171 Views)

Re: equivalent to arx "acedSetStatusBarProgressMeter" ?

05-23-2006 04:24 AM in reply to: newArch
For AutoCAD 2007:
[code]
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedSetStatusBarProgressMeter@@YAHPB_WHH@Z")]
extern public static int acedSetStatusBarProgressMeter(string msg, int minpos, int maxpos);

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedSetStatusBarProgressMeterPos@@YAHH@Z")]
extern public static int acedSetStatusBarProgressMeterPos(int nPos);

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedRestoreStatusBar@@YAXXZ")]
extern public static void acedRestoreStatusBar();

[/code]
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 13 of 27 (171 Views)

Re: equivalent to arx "acedSetStatusBarProgressMeter" ?

05-23-2006 05:42 AM in reply to: newArch
Thank you, Alexander!
Now it works.

--
Roland Feletic
Ingenieurbuero A. Pauser Ges.m.b.H.
http://www.pauser.at

hp workstation xw4200, 3GB
quadro fx1400
AutoCAD 2007, 3DSMax 8.0 SP 2
*Tony Tanzillo
Message 14 of 27 (171 Views)

Re: equivalent to arx "acedSetStatusBarProgressMeter" ?

05-23-2006 06:42 AM in reply to: newArch
No, it will not work as-is in 2007. Because of how
Autodesk compiles AutoCAD, when the parameter
type of a function changes, so does the exported
signature.

In fully-UNICODE 2007, the first parameter to the
function shown below is wchar_t* (previously it was
char*, in non-unicode builds). Hence, changing the
type of that parameter also caused the mangled
export name to change.

So, for 2007 you must use the following EntryPoint
name for acedSetStatusBarProgressMeter():

"?acedSetStatusBarProgressMeter@@YAHPB_WHH@Z"

The signatures of the other two functions have not
changed, because the parameters haven't changed.

So if you are currently P/Invoking native functions
that have mangled export names, and take strings
as arguments (or return strings) in R16, they will be
similarly affected, and will also require a different
EntryPoint value in R17.

Use Depends.exe to look up the new names.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5182887@discussion.autodesk.com...
I tried it now and still got the same error. Is it possible that it does not
work in Acad2007?

--
Roland Feletic
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 15 of 27 (171 Views)

Re: equivalent to arx "acedSetStatusBarProgressMeter" ?

05-23-2006 07:20 AM in reply to: newArch
Thanks, Tony!

--
Roland Feletic
Ingenieurbuero A. Pauser Ges.m.b.H.
http://www.pauser.at

hp workstation xw4200, 3GB
quadro fx1400
AutoCAD 2007, 3DSMax 8.0 SP 2
Distinguished Contributor
wesbird
Posts: 351
Registered: ‎12-05-2003
Message 16 of 27 (171 Views)

Re: equivalent to arx "acedSetStatusBarProgressMeter" ?

06-28-2006 07:22 PM in reply to: newArch
Hi Tony:
I tried to convert your code to VB.NET. after changing some code, it pass compile but crash when I run it in AutoCAD. Do you know what's wrong in my code ?

Thank you a thousand.


here is the code:
[code]
Imports System
Imports System.Collections
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.Runtime

Namespace CaddZone.AutoCAD.EditorServices

Public Class StatusBarProgressMeter
Implements IDisposable

DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _
EnTryPoint:="?acedSetStatusBarProgressMeter@@YAHPBDHH@Z")> _
Public Shared Function acedSetStatusBarProgressMeter(ByVal msg As String, ByVal minpos As Integer, ByVal maxpos As Integer) As Integer
End Function

DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _
EnTryPoint:="?acedSetStatusBarProgressMeterPos@@YAHH@Z")> _
Public Shared Function acedSetStatusBarProgressMeterPos(ByVal nPos As Integer) As Integer
End Function

DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _
EnTryPoint:="?acedRestoreStatusBar@@YAXXZ")> _
Public Shared Function acedRestoreStatusBar()
End Function

Public Sub New(ByVal msg As String, ByVal count As Integer)
If count > 99 Then
m_step = count / 100
acedSetStatusBarProgressMeter(msg, 0, 100)
End If
End Sub

Protected Overrides Sub Finalize()
Dispose(False)
End Sub

Private m_step As Integer = 0
Private cnt As Integer = 0
Private disposed As Boolean = False

Public Sub ProgressStep()
cnt += 1
If m_step <> 0 And cnt Mod m_step = 0 Then
acedSetStatusBarProgressMeterPos(cnt / m_step)
End If
End Sub

Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
End Sub

Protected Overloads Sub Dispose(ByVal disposing As Boolean)
If Not disposed Then
If m_step <> 0 Then
acedRestoreStatusBar()
End If
disposed = True
GC.SuppressFinalize(Me)
End If
End Sub

End Class

'Error: Converting Casting from C# to VB.Net

Public Class TestProgressMeter
Public Sub New()
End Sub

_
Public Shared Sub Execute()


Dim count As Integer = 10000 ' size of ArrayList (and the number of

Dim myList As ArrayList = New ArrayList(count)

Dim meter1 As New StatusBarProgressMeter("Populating ArrayList...", count)
Dim i As Integer
For i = 0 To count - 1 Step i + 1
myList.Add(i)
' waste some cpu cycles so we
' can see the progress meter:
Dim x As Integer = 0
Dim j As Integer
For j = 0 To 100000 - 1 Step j + 1
x = j + i
Next
' Update progress meter
meter1.ProgressStep()
Next
meter1.Dispose()

Dim meter2 As New StatusBarProgressMeter("Processing ArrayList...", myList.Count)
Try
Dim n As Integer
For Each n In myList

' waste some cpu cycles so we
' can see the progress meter:
Dim x As Integer = n
Dim j As Integer
For j = 0 To 100000 - 1 Step j + 1
x = j + 1
Next

' Update progress meter:
meter2.ProgressStep()
Next
Finally
meter2.Dispose()
End Try
End Sub
End Class


End Namespace


[/code]
*Tony Tanzillo
Message 17 of 27 (171 Views)

Re: equivalent to arx "acedSetStatusBarProgressMeter" ?

06-29-2006 12:27 AM in reply to: newArch
Sorry, I took a quick look at it, but can't see what may be
the problem.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5222434@discussion.autodesk.com...
Hi Tony:
I tried to convert your code to VB.NET. after changing some code, it pass compile but crash when I run it in AutoCAD. Do you know what's wrong in my code ?

Thank you a thousand.


here is the code:
[code]
Imports System
Imports System.Collections
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.Runtime

Namespace CaddZone.AutoCAD.EditorServices

Public Class StatusBarProgressMeter
Implements IDisposable

DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _
EnTryPoint:="?acedSetStatusBarProgressMeter@@YAHPBDHH@Z")> _
Public Shared Function acedSetStatusBarProgressMeter(ByVal msg As String, ByVal minpos As Integer, ByVal maxpos As Integer) As Integer
End Function

DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _
EnTryPoint:="?acedSetStatusBarProgressMeterPos@@YAHH@Z")> _
Public Shared Function acedSetStatusBarProgressMeterPos(ByVal nPos As Integer) As Integer
End Function

DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _
EnTryPoint:="?acedRestoreStatusBar@@YAXXZ")> _
Public Shared Function acedRestoreStatusBar()
End Function

Public Sub New(ByVal msg As String, ByVal count As Integer)
If count > 99 Then
m_step = count / 100
acedSetStatusBarProgressMeter(msg, 0, 100)
End If
End Sub

Protected Overrides Sub Finalize()
Dispose(False)
End Sub

Private m_step As Integer = 0
Private cnt As Integer = 0
Private disposed As Boolean = False

Public Sub ProgressStep()
cnt += 1
If m_step <> 0 And cnt Mod m_step = 0 Then
acedSetStatusBarProgressMeterPos(cnt / m_step)
End If
End Sub

Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
End Sub

Protected Overloads Sub Dispose(ByVal disposing As Boolean)
If Not disposed Then
If m_step <> 0 Then
acedRestoreStatusBar()
End If
disposed = True
GC.SuppressFinalize(Me)
End If
End Sub

End Class

'Error: Converting Casting from C# to VB.Net

Public Class TestProgressMeter
Public Sub New()
End Sub

_
Public Shared Sub Execute()


Dim count As Integer = 10000 ' size of ArrayList (and the number of

Dim myList As ArrayList = New ArrayList(count)

Dim meter1 As New StatusBarProgressMeter("Populating ArrayList...", count)
Dim i As Integer
For i = 0 To count - 1 Step i + 1
myList.Add(i)
' waste some cpu cycles so we
' can see the progress meter:
Dim x As Integer = 0
Dim j As Integer
For j = 0 To 100000 - 1 Step j + 1
x = j + i
Next
' Update progress meter
meter1.ProgressStep()
Next
meter1.Dispose()

Dim meter2 As New StatusBarProgressMeter("Processing ArrayList...", myList.Count)
Try
Dim n As Integer
For Each n In myList

' waste some cpu cycles so we
' can see the progress meter:
Dim x As Integer = n
Dim j As Integer
For j = 0 To 100000 - 1 Step j + 1
x = j + 1
Next

' Update progress meter:
meter2.ProgressStep()
Next
Finally
meter2.Dispose()
End Try
End Sub
End Class


End Namespace


[/code]
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 18 of 27 (171 Views)

Re: equivalent to arx "acedSetStatusBarProgressMeter" ?

06-29-2006 04:54 AM in reply to: newArch
1) Version of AutoCAD? If it is AutoCAD 2007 you have to change:
[code]
EntryPoint:="?acedSetStatusBarProgressMeter@@YAHPBDHH@Z"
with
EntryPoint:="?acedSetStatusBarProgressMeter@@YAHPB_WHH@Z"
[/code]
2) Is it inproces application (DLL)? If no and you start AutoCAD as COM-server through COM/ActiveX model you can not use progressmeter.

3) I've tested that code in AutoCAD 2006 and found problem! :smileyhappy: Problem is declaretion of function acedRestoreStatusBar. As far as this function return nothing it must be declared as SUB not as Function:
[code]
DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, _
EnTryPoint:="?acedRestoreStatusBar@@YAXXZ")> _
Public Shared Sub acedRestoreStatusBar()
End Sub
[/code]
With this change there are no exceptions!
Distinguished Contributor
wesbird
Posts: 351
Registered: ‎12-05-2003
Message 19 of 27 (171 Views)

Re: equivalent to arx "acedSetStatusBarProgressMeter" ?

06-29-2006 11:29 AM in reply to: newArch
Thank you, Alex.
I'm sorry to forget metion my system:
AutoCAD 2006
Visual Studio .Net 2003
.Net Framework 1.1

I change Function to Sub, but still not work

I also tried another solution: use the C# version to create a dll file, create a new VB.NET project with all test code inside.
The VB test code is same as the one in C#, which shouldl run the progressBar twice. but in my VB test code, the 2nd time is fine but the 1st one will go to like 90% very fast and stay there for a while, then start the 2nd one.
What the problem could be ?
Thank you and Tony for your help.


here is the code:
[code]

Imports Autodesk.AutoCAD.Runtime
Imports CaddZone.AutoCAD.EditorServices.StatusBarProgressMeter

Public Class TestProgressMeter

#Region "StatusBarProgressMeter"

_
Public Shared Function Execute()

' setup a bogus collection to be processed,
' where we want to show the progress...

Dim count As Integer = 10000 ' size of ArrayList (and the number of
' times we call Step() when processing it).

Dim myList As New ArrayList(count)

'Dim meter1 As New CaddZone.AutoCAD.EditorServices.StatusBarProgressMeter("Populating ArrayList...", count)

Try

For i As Integer = 0 To count

myList.Add(i)
' waste some cpu cycles so we
' can see the progress meter:
Dim x As Integer = 0
For j As Integer = 0 To 100000

x = j + i
' Update progress meter
'meter1.Step()

Next

Next

Catch ex As Exception

Finally

'meter1.Dispose()

End Try

Dim meter2 As New CaddZone.AutoCAD.EditorServices.StatusBarProgressMeter("Processing ArrayList...", myList.Count)
Try

For Each n As Integer In myList

' waste some cpu cycles so we
' can see the progress meter:
Dim x As Integer = n
For j As Integer = 0 To 100000

x = j + 1

Next

' Update progress meter:
meter2.Step()

Next

Catch ex As Exception

Finally

meter2.Dispose()

End Try


End Function

#End Region

End Class

[/code]
*Alexander Rivilis
Message 20 of 27 (171 Views)

Re: equivalent to arx "acedSetStatusBarProgressMeter" ?

06-29-2006 01:39 PM in reply to: newArch
Hi, weslleywang!

w> I change Function to Sub, but still not work

Very strange. I' tested your's previous code (AutoCAD 2006 SP1/ VS .NET 2002) and it
work without exception on my PC.

w> I also tried another solution: use the C# version to create a dll file, create a
w> new VB.NET project with all test code inside. The VB test code is same as
w> the one in C#, which shouldl run the progressBar twice. but in my VB test
w> code, the 2nd time is fine but the 1st one will go to like 90% very fast
w> and stay there for a while, then start the 2nd one. What the problem
w> could be ?

IMHO, AutoCAD can not update progressbar, because this application is very CPU-intensive.

Best Regards,
Alexander Rivilis.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.