.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unhandled Exception, Common Language Runtime

9 REPLIES 9
Reply
Message 1 of 10
not.testee
2075 Views, 9 Replies

Unhandled Exception, Common Language Runtime

Hey guys and gals,

acadDoc.SendCommand("Open ")
Dim a As Integer
a = 0
Do Until a = 1
Dim b As Integer = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("FULLOPEN")
a = b
Loop

"Dim b As Integer = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("FULLOPEN")" throws an unhandled exception an it is "Common Language Runtime detected an invalid program".

FULLOPEN returns 0 if the application is not fully open and 1 when the application is fully open.

Should I use this with the Transaction Code Samples in the Developer Guide and commit it. This program I am writing is a standalon EXE.

Any help would be appreciated.

THANKS,
Not testee
9 REPLIES 9
Message 2 of 10
arcticad
in reply to: not.testee

I don't believe you can use .NET code in this stand alone application.
You have to connect through COM Interop.

Public acadApp As Autodesk.AutoCAD.Interop.AcadApplication

' Connect to Autocad.
Dim acadDBX As Object = acadApp.GetInterfaceObject("ObjectDBX.AxDbDocument.17")

' Wait until AutoCAD is ready to accept your command
While Not AcadApp.GetAcadState.IsQuiescent
Thread.Sleep(100)
End While

' Open File when ready.
acadDBX.Open(FileName)
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 3 of 10
not.testee
in reply to: not.testee

I have not yet run the code you sent over but upon build, Thread needs to be declared. Can you give me a declaration for it. I assume it is supposed to be a .NET command, right?

Thread.Sleep(100)

THX,
not testee
Message 4 of 10
arcticad
in reply to: not.testee

You would need to add Imports System.Threading
'The previous code will allow you to open a drawing but not in the editor.

---------------------

'The following code will let you open a drawing in Autocad.
It will wait until Autocad can receive a command and open a new drawing if none are open.

Make sure you add a reference to the AutoCAD 2010 Type Library
and AutoCAD/ObjectDBX Common 18.0 Type Library

or which ever version of Autocad your using.

{code}
Imports System.Threading
Imports Autodesk

Public Class LoadAutoCAD

Public acadApp As Autodesk.AutoCAD.Interop.AcadApplication

Sub OpenDrawing()

Dim acadDoc As AutoCAD.Interop.AcadDocument

' Grab Instance of Autocad
GetApplication(acadApp)
' Wait until AutoCAD is Ready
isQuiescent(acadApp)

Dim dwgName As String = "c:\test1.dwg"

If isFileInUse(dwgName) Then
Try
acadDoc = acadApp.Documents.Open(dwgName, True)
Catch ex As Exception
MessageBox.Show("Unable to open drawing: " & vbCr & vbCr & dwgName, _
"AutoCAD Message", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
Else
Try
acadDoc = acadApp.Documents.Open(dwgName, False)
Catch ex As Exception
MessageBox.Show("Unable to open drawing: " & vbCr & vbCr & dwgName, _
"AutoCAD Message", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
End If

End Sub

Public Function isFileInUse(ByVal sFile As String) As Boolean

If System.IO.File.Exists(sFile) Then
Try
Dim F As Short = FreeFile()
FileOpen(F, sFile, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.LockReadWrite)
FileClose(F)
Catch

Return True
End Try
End If
End Function

' This is for 2010 change AutoCAD.application # as needed
Public Sub GetApplication(ByRef AcadApp As Autodesk.AutoCAD.Interop.AcadApplication)
If Not AcadApp Is Nothing Then
Try
AcadApp = GetObject(, "AutoCAD.Application.18")
Catch ex As Exception
AcadApp = Nothing
End Try
End If

While AcadApp Is Nothing
Try
AcadApp = GetObject(, "AutoCAD.Application.18")
Catch ex As Exception
Try
Thread.Sleep(100)
' Start New Thread so the system doesn't freeze
Dim t As Thread
t = New Thread(AddressOf CreateNewAcad)
t.Start()
While AcadApp Is Nothing
Try
AcadApp = GetObject(, "AutoCAD.Application.18")
Catch ex2 As Exception
AcadApp = Nothing
Thread.Sleep(1000)
End Try
End While
Catch ex2 As Exception
Exit Sub
End Try
End Try
End While

End Sub

Public Sub CreateNewAcad()
Try
acadApp = CreateObject("AutoCAD.Application.18")
Catch ex As Exception
End Try
End Sub

Public Function isQuiescent(ByRef AcadApp As Autodesk.AutoCAD.Interop.AcadApplication) As Boolean
If AcadApp Is Nothing Then
Return True
End If
Try
While Not AcadApp.GetAcadState.IsQuiescent
Thread.Sleep(100)
End While
Catch ex As Exception
Try
' Add a New Document if none are open
' Otherwise we will be waiting until the cows come home
AcadApp.Documents.Add()
Catch ex2 As Exception
End Try
Try
While Not AcadApp.GetAcadState.IsQuiescent
Thread.Sleep(100)
End While
Catch ex2 As Exception
Return False
End Try

End Try

Return True

End Function

End Class
{code}
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 5 of 10
not.testee
in reply to: not.testee

Hello,

Thanks for the help. It seems to be getting me in the right direction. But I can believe this command throws an error because it seems very straight forward. The error is that it cannot find the file.

Dim acadDoc As Autodesk.AutoCAD.Interop.AcadDocument
Dim dwgName As String = "C:\Users\nottestee\Documments\DEVELOPMENT\SCANPOINTSCOM\3D OBJECTS.dwg"

acadDoc = acadApp.Documents.Open(dwgName, True)........This statement throws the error..........

Any advice would be appreciated.

THX,

not testee
Message 6 of 10
not.testee
in reply to: not.testee

I think COM cannot pass this because the path and file name is too long. Maybe that is the problem.

Any comments would be appreciated.

THANKS
Message 7 of 10
arcticad
in reply to: not.testee

I've never seen it. Check the name first.
Make sure you can open the file in AutoCAD first.

If you are saving the file down to an earlier version I've seen this cause problems.

I've had to use ObjectDBX to convert the file into the native format before
I try and open it in the editor.

There was a known bug that is you use a 2004
file it would fail TrueDWG verification and refuse to open.

{code}
Public Function FileExists(ByVal FileFullPath As String) _
As Boolean
Dim f As New IO.FileInfo(FileFullPath)
Return f.Exists

End Function
{code}
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 8 of 10
not.testee
in reply to: not.testee

Hi ArtiCAD,

I really appreciate the input. I finally discovered that the problem was to access the folder I wanted to access involved Administrative Permission.

I will be looking over this myself. With the AutoCAD discussion group I have gotten a lot of comments about asking for help while I am trying to learn a new technology. In the future when you see me post...if you know where to find an answer for me...just give me a little background ( a sentence or two ). Please do not give me answers when it takes up your valuable time.

I am going to visit your web site and see what your services are...because I think you provide a service (your company) that is probably worthwhile.

THX,
Dan
Message 9 of 10
Anonymous
in reply to: not.testee

Don't have time to play, but :

Have you tried to debug that ?
Have a look (in your locals) at the value of dwgName.

are there any '\' characters in the string ?

Have you tried to assign the variable with a string that uses '\\' or '/'
in place of your '\'

.... just a guess.

"not.testee" wrote in message news:6309623@discussion.autodesk.com...
Hello,

Thanks for the help. It seems to be getting me in the right direction. But I
can believe this command throws an error because it seems very straight
forward. The error is that it cannot find the file.

Dim acadDoc As Autodesk.AutoCAD.Interop.AcadDocument
Dim dwgName As String =
"C:\Users\nottestee\Documments\DEVELOPMENT\SCANPOINTSCOM\3D OBJECTS.dwg"

acadDoc = acadApp.Documents.Open(dwgName, True)........This statement
throws the error..........

Any advice would be appreciated.

THX,

not testee
Message 10 of 10
arcticad
in reply to: not.testee

Your welcome,
I don't have a web site with any pricing information. I'm just one person.
If you want to contact me you can sent mail to arcticad (at) metaldust dot com
---------------------------



(defun botsbuildbots() (botsbuildbots))

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost