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

My .net app depends on the first open drawing

11 REPLIES 11
Reply
Message 1 of 12
rtejada
331 Views, 11 Replies

My .net app depends on the first open drawing

Hi
I have a .net app I am loading using the acaddoc.lsp. It works fine in the mdi enviroment until the initial Drawing1.dwg is automatically close by Autocad (when you open the second drawing). After that, there are script errors on my modalform (I am using a webbrowser control on it). If I modified the Drawing1.dwg such that it does not close automatically, there is no errors at all. I do not know why there is such dependency. Any hints

I will appreciate any help

Thanks
11 REPLIES 11
Message 2 of 12
cgay
in reply to: rtejada

rtejada,

Without seeing code, it will be difficult to diagnose, but it sounds like your managed dll is being loaded in the "Document" context .

Please post some code so we can help to figure this out.

As a side note, I usually load a managed dll with a script instead of a LSP file, not sure if this is the cause of your issue though, seeing as though AutoCAD still uses the same mechanism to load a managed dll, at least I think it does anyway.

C
Message 3 of 12
rtejada
in reply to: rtejada

Thanks Couger
The reason I use acaddoc.lsp it seems to me the easier way to autostart a dll in each document by just adding the application path on the application support paths area. I do not know how to accomplish that with script. Anyways, my acaddoc.lsp looks like this


(defun S::STARTUP()
(command "_NETLOAD" "c:\\My Documents\\Visual Studio Projects\\myfolder\\myproject\\bin\\myproject.dll")
(command "_Init")


Thanks for your help
Message 4 of 12
Anonymous
in reply to: rtejada

If your class is a Form and has a command method
that is non-static, which creates and shows the form,
then AutoCAD will create a separate instance of the
form class for each open document. In that case, the
form and its non-static data is document-specific.

If you want to use the same form in every document,
declare a static (shared in vb) variable to hold the
form instance, and make the command method that
shows it, a static member as well.

The first time your static command method runs,
check the static form variable and see if it is
assigned to a form instance. If not, create the
instance and assign it to the variable, then show
the form:

public class Form1 : System.Windows.Forms.Form
{
public Form1() {}

private static Form1 m_Form = null;

[CommandMethod("SHOWMYFORM")]
public static ShowForm()
{
if( m_Form == null )
m_Form = new Form1();

AcadApp.ShowModalDialog(m_Form);
}
}


--
http://www.caddzone.com

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

wrote in message news:5078266@discussion.autodesk.com...
Hi
I have a .net app I am loading using the acaddoc.lsp. It works fine in the mdi enviroment until the initial Drawing1.dwg is automatically close by Autocad (when you open the second drawing). After that, there are script errors on my modalform (I am using a webbrowser control on it). If I modified the Drawing1.dwg such that it does not close automatically, there is no errors at all. I do not know why there is such dependency. Any hints

I will appreciate any help

Thanks
Message 5 of 12
rtejada
in reply to: rtejada

Hi Tony
I declared my modal form non static, since I do not required to keep its values throughout the diferents documents. I changed it to static just to check if it work, but it still have the problem.

thanks
Message 6 of 12
Anonymous
in reply to: rtejada

You're not going to get help with vague descriptions
of your problem, and no source code.

You were asked to show your code, but you only
showed the LISP code that starts it, and that is not
where the problem is.

If you want help, post the relevant parts of the .NET
code, specifically you must show the method that is
used to display the form.


--
http://www.caddzone.com

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

wrote in message news:5078690@discussion.autodesk.com...
Hi Tony
I declared my modal form non static, since I do not required to keep its values throughout the diferents documents. I changed it to static just to check if it work, but it still have the problem.

thanks
Message 7 of 12
rtejada
in reply to: rtejada

Hi Tony
Sorry about that, I just wanted to show one thing at a time. I open the form using vb.net using this method

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Pubic class Main

_
Private sub OpenForm
Dim modalForm As New MyOpenDialog
Application.ShowModalDialog(modalForm)
If modalForm.DialogResult = Windows.Forms.DialogResult.OK Then
OKtoOpen
end Sub
End class


There is a sub OKtoOpen but the error happens before that.

I am using the regular VBnet disposal methods that Visual Studio 2003 adds to the "Windows form generated code" region, the main code looks in my form like this

Private Sub NavigateTo(ByVal url As String, ByVal flag As Integer)
Try
Dim flags As Object = flag
Dim targetFrameName As Object = String.Empty
Dim postData As Object = String.Empty
Dim headers As Object = String.Empty
AxWebBrowser1.Navigate(url, flags, targetFrameName, postData, headers)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub


AXwebbrowser1 is a webbrowser control added to the form, it seems that the error while navigating, the weird thing is, there is no error if I do not close any AutoCAD drawing file, I looks like there is any interop. problem.

The error happens after the NavigateTo sub, I can give you more code, if you think it can help,

Thanks for your help
Message 8 of 12
Anonymous
in reply to: rtejada

One problem may be that the OpenForm method of your
"Main" class is not shared. If it is not shared, AutoCAD
will create a separate instance of the Main class for each
open document. That's fine, as long as it was not your
intention for the Main class to have application-level
scope (meaning that there is a single instance of it, and
it is used with any document).

If you need to maintain data that is accessed from any
open document, you need to make that data static/shared,
or you must create a single instance of a class when your
app loads, that can be accessed from any context.


--
http://www.caddzone.com

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

wrote in message news:5079155@discussion.autodesk.com...
Hi Tony
Sorry about that, I just wanted to show one thing at a time. I open the form using vb.net using this method

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Pubic class Main

_
Private sub OpenForm
Dim modalForm As New MyOpenDialog
Application.ShowModalDialog(modalForm)
If modalForm.DialogResult = Windows.Forms.DialogResult.OK Then
OKtoOpen
end Sub
End class


There is a sub OKtoOpen but the error happens before that.

I am using the regular VBnet disposal methods that Visual Studio 2003 adds to the "Windows form generated code" region, the main code looks in my form like this

Private Sub NavigateTo(ByVal url As String, ByVal flag As Integer)
Try
Dim flags As Object = flag
Dim targetFrameName As Object = String.Empty
Dim postData As Object = String.Empty
Dim headers As Object = String.Empty
AxWebBrowser1.Navigate(url, flags, targetFrameName, postData, headers)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub


AXwebbrowser1 is a webbrowser control added to the form, it seems that the error while navigating, the weird thing is, there is no error if I do not close any AutoCAD drawing file, I looks like there is any interop. problem.

The error happens after the NavigateTo sub, I can give you more code, if you think it can help,

Thanks for your help
Message 9 of 12
cgay
in reply to: rtejada

rtejada,

1.) As far as using a script instead of a LSP file, see my post in this thread:
http://discussion.autodesk.com/thread.jspa?messageID=5035412

2.) I may be missing something, but your OpenForm method appears to be private? I am assuming, of course, that this is decorated with a commandmethod attribute even though is doesn't show up in the code you posted. Try this code:
[code]
Imports System
Imports System.Windows.Forms
Imports System.Collections
Imports Autodesk.AutoCAD.Runtime
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application

Public Class Main
<CommandMethod("OpenForm", CommandFlags.Session)>
Public Shared Sub OpenForm
Dim modalForm as New MyOpenDialog
Dim modalResult as Windows.Forms.DialogResult=AcadApp.ShowModalDialog(modalForm)

If modalResult = Windows.Forms.DialogResult.OK Then
OKtoOpen
End If
modalForm .dispose
End Sub
End Class
[/code]

Let us know if this helps or not.

C
Message 10 of 12
rtejada
in reply to: rtejada

Hi Couger,
First, yes, I have the sub decorated like this

_
Public Sub OpenFile()
....

end sub

I tried to change it as you suggested, but it did not like the send me the error "identifier expected", looks like CommandFlags.Session need a value instead.

Thanks
Message 11 of 12
rtejada
in reply to: rtejada

Couger,
For some reasons when the last messages did not send correctly
It seems that is cutting the characters between "<" and ">". Anyways I meant the line "_" send me a identifier error
Message 12 of 12
rtejada
in reply to: rtejada

Hi, I manage to make the CommandFlags.Session line and YES it worked, my problem is solved. I am wondering what the CommandFlags.Session means

Thanks for Couger and Tony for your help

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