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

Opening Document

32 REPLIES 32
Reply
Message 1 of 33
Anonymous
1564 Views, 32 Replies

Opening Document

I thought opening a list drawings from a user form was just matter of calling DocumentManager.Open method, but I can't make it work. Can someone please give a hand on how to do it properly. TIA
32 REPLIES 32
Message 2 of 33
Anonymous
in reply to: Anonymous

Here is how I do it.

(defun MyOpen (FileName ReadOnly / )

(vla-Open
(vla-get-Documents
(vlax-get-Acad-Object)
)
FileName
(if ReadOnly
:vlax-true
:vlax-false
)
)
)

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5668021@discussion.autodesk.com...
I thought opening a list drawings from a user form was just matter of
calling DocumentManager.Open method, but I can't make it work. Can someone
please give a hand on how to do it properly. TIA
Message 3 of 33
Anonymous
in reply to: Anonymous

Oops. Wrong forum, but is still the same.

DocumentManager.Open(< DrawingPath >, < ReadOnly >);

At least that is how I do it in my C# app, and it works. But you could also
leave out the readonly options.

DocumentManager.Open(< DrawingPath >);

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5668029@discussion.autodesk.com...
Here is how I do it.

(defun MyOpen (FileName ReadOnly / )

(vla-Open
(vla-get-Documents
(vlax-get-Acad-Object)
)
FileName
(if ReadOnly
:vlax-true
:vlax-false
)
)
)

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5668021@discussion.autodesk.com...
I thought opening a list drawings from a user form was just matter of
calling DocumentManager.Open method, but I can't make it work. Can someone
please give a hand on how to do it properly. TIA
Message 4 of 33
Anonymous
in reply to: Anonymous

Thank you Willey for replying but I still stuck on this issue. Here is the line of code I am having trouble with:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(FilePath, False) FilePath is a valid IO file path, but I am getting this error msg "Invalid execution context" , I think it has something to do with the ApplicationExecutionContext, but I am not clear on how this works. I trying to open the drawings from a user form opened by the Application.ShowModalDialog method. Any help will be greatly appreciated.
Message 5 of 33
Anonymous
in reply to: Anonymous

That explains it: unlike the VB modal user form, when a modal form is open
in .NET API, you cannot use DocumentCollection object to open a drawing.

Workaround would be either open the drawing prior to the modal dialog's
openning, or open the dialog as modeless.


wrote in message news:5668604@discussion.autodesk.com...
Thank you Willey for replying but I still stuck on this issue. Here is the
line of code I am having trouble with:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(FilePath,
False) FilePath is a valid IO file path, but I am getting this error msg
"Invalid execution context" , I think it has something to do with the
ApplicationExecutionContext, but I am not clear on how this works. I trying
to open the drawings from a user form opened by the
Application.ShowModalDialog method. Any help will be greatly appreciated.
Message 6 of 33
Anonymous
in reply to: Anonymous

If your modal dialog is started from a command handler,
register the command with CommandFlags.Session, and
set your Form's Visible property to false before you call
Open(), and back to true after Open() returns.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5668604@discussion.autodesk.com...
Thank you Willey for replying but I still stuck on this issue. Here is the line of code I am having trouble with:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(FilePath, False) FilePath is a valid IO file path, but I am getting this error msg "Invalid execution context" , I think it has something to do with the ApplicationExecutionContext, but I am not clear on how this works. I trying to open the drawings from a user form opened by the Application.ShowModalDialog method. Any help will be greatly appreciated.
Message 7 of 33
Anonymous
in reply to: Anonymous

Tony,

Question one what you said.

Can this method be used on any dialog box? I have routines where I use
dialog boxes, and the information is stored within them. Once the okay
button is pressed I close the dialog, and fill an array with the contents of
the dialog I want to store. Could I just turn the dialog invisible instead,
use the contents, then close the dialog? Is this a good way, or just a work
around?

Thanks in advance.

Sorry for the highjack.

--

Tim
"A blind man lets nothing block his vision."


"Tony Tanzillo" wrote in message
news:5669200@discussion.autodesk.com...
If your modal dialog is started from a command handler,
register the command with CommandFlags.Session, and
set your Form's Visible property to false before you call
Open(), and back to true after Open() returns.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5668604@discussion.autodesk.com...
Thank you Willey for replying but I still stuck on this issue. Here is the
line of code I am having trouble with:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(FilePath,
False) FilePath is a valid IO file path, but I am getting this error msg
"Invalid execution context" , I think it has something to do with the
ApplicationExecutionContext, but I am not clear on how this works. I trying
to open the drawings from a user form opened by the
Application.ShowModalDialog method. Any help will be greatly appreciated.
Message 8 of 33
Anonymous
in reply to: Anonymous

Thank you Tony. Here is how I have made the command declaration:

_
Public Shared Sub UpdateBox()
Dim frm As System.Windows.Forms.Form

frm = New frmUpdateDwgs
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(frm)

frm.Dispose()

End Sub

I still getting the same "Invalid execution context" error message. Could you explain what does hiding the form while opening the drawings do. Any suggestions?
Message 9 of 33
Anonymous
in reply to: Anonymous

Hi Tim.

As long as your code is running in the application
context (e.g., the IsApplicationContext property
of the DocumentManager is true), you should have
no problem.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5669321@discussion.autodesk.com...
Tony,

Question one what you said.

Can this method be used on any dialog box? I have routines where I use
dialog boxes, and the information is stored within them. Once the okay
button is pressed I close the dialog, and fill an array with the contents of
the dialog I want to store. Could I just turn the dialog invisible instead,
use the contents, then close the dialog? Is this a good way, or just a work
around?

Thanks in advance.

Sorry for the highjack.

--

Tim
"A blind man lets nothing block his vision."


"Tony Tanzillo" wrote in message
news:5669200@discussion.autodesk.com...
If your modal dialog is started from a command handler,
register the command with CommandFlags.Session, and
set your Form's Visible property to false before you call
Open(), and back to true after Open() returns.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5668604@discussion.autodesk.com...
Thank you Willey for replying but I still stuck on this issue. Here is the
line of code I am having trouble with:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(FilePath,
False) FilePath is a valid IO file path, but I am getting this error msg
"Invalid execution context" , I think it has something to do with the
ApplicationExecutionContext, but I am not clear on how this works. I trying
to open the drawings from a user form opened by the
Application.ShowModalDialog method. Any help will be greatly appreciated.
Message 10 of 33
Anonymous
in reply to: Anonymous

If that's happening then rather than hiding
the form, in your command method, call
ShowModalDialog() inside of a loop, and each
time it returns DialogResult.Ok, open the
drawing files. When ShowModalDialog() returns
something other than DialogResult.Ok, exit
the loop.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5669392@discussion.autodesk.com...
Thank you Tony. Here is how I have made the command declaration:

_
Public Shared Sub UpdateBox()
Dim frm As System.Windows.Forms.Form

frm = New frmUpdateDwgs
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(frm)

frm.Dispose()

End Sub

I still getting the same "Invalid execution context" error message. Could you explain what does hiding the form while opening the drawings do. Any suggestions?
Message 11 of 33
Anonymous
in reply to: Anonymous

Thanks Tony.

--

Tim
"A blind man lets nothing block his vision."


"Tony Tanzillo" wrote in message
news:5669567@discussion.autodesk.com...
Hi Tim.

As long as your code is running in the application
context (e.g., the IsApplicationContext property
of the DocumentManager is true), you should have
no problem.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5669321@discussion.autodesk.com...
Tony,

Question one what you said.

Can this method be used on any dialog box? I have routines where I use
dialog boxes, and the information is stored within them. Once the okay
button is pressed I close the dialog, and fill an array with the contents of
the dialog I want to store. Could I just turn the dialog invisible instead,
use the contents, then close the dialog? Is this a good way, or just a work
around?

Thanks in advance.

Sorry for the highjack.

--

Tim
"A blind man lets nothing block his vision."


"Tony Tanzillo" wrote in message
news:5669200@discussion.autodesk.com...
If your modal dialog is started from a command handler,
register the command with CommandFlags.Session, and
set your Form's Visible property to false before you call
Open(), and back to true after Open() returns.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5668604@discussion.autodesk.com...
Thank you Willey for replying but I still stuck on this issue. Here is the
line of code I am having trouble with:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(FilePath,
False) FilePath is a valid IO file path, but I am getting this error msg
"Invalid execution context" , I think it has something to do with the
ApplicationExecutionContext, but I am not clear on how this works. I trying
to open the drawings from a user form opened by the
Application.ShowModalDialog method. Any help will be greatly appreciated.
Message 12 of 33
Anonymous
in reply to: Anonymous

Tony, maybe I have not being able to explain the situation clearly. The "Invalid execution context" error occurs, when I try to iterate thru the list of drawings opening them. The form frmUpdateDwgs works fine. Once it is displayed the user can select drawings files from the system drives. The problem is, when I try to open each drawing (hiding the form here didn't do anything). In VBA this procedure works fine, but in .NET the Application/Document context restrictions make it difficult to make this code work. Unfortunately, I don't have much documentation and I haven't been able to find anything meaningful on the subject. I am starting to think that perhaps this won’t work. Your help is really appreciated.
Message 13 of 33
Anonymous
in reply to: Anonymous

Did you take this advice of Tony's:

register the command with CommandFlags.Session
Message 14 of 33
Anonymous
in reply to: Anonymous

Simply add CommandFlags.Session does not work. I tested this code:

In command defining class:

[CommandMethod("MyOpen", CommandFlags.Session)]

public static void OpenFile()

{

using (dlgCmdTest dlg = new dlgCmdTest())

{

Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(dlg);

}

}



dlgCmdTest is a win form with a button on it. The Button_Click event handler
looks like:

private void button1_Click(object sender, EventArgs e)

{

string file = "E:\\Work\\Acad\\DataCadTest\\2007\\070202\\070202PC01R0.dwg";

this.Visible = false; //Or this.Hide(); The same effect

try

{

Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(file);

}

catch (Autodesk.AutoCAD.Runtime.Exception ex)

{

MessageBox.Show("Error: " + ex.Message); //I got error "eNoDocument".

}

this.Visible = true;

}



After start Acad, NETLOAD the dll, issue command "MYOPEN", the form shows.
Clicking the button, the MessageBox pops up.



wrote in message news:5669714@discussion.autodesk.com...
Did you take this advice of Tony's:

register the command with CommandFlags.Session
Message 15 of 33
Anonymous
in reply to: Anonymous

Did you see my last reply, and if so, did you try it?

What I said was to place a loop in your command
method function, and in the loop, show your dialog.
After the call to ShowModalDialog() returns, then
open the documents.

Here's the C# code:

public class MyForm : Form
{
// set this to true to terminate looping:

public bool exitloop = false;
}

public class MyCommandClass
{
[CommandMethod("MyCommand")]
public static void MyCommand()
{
MyForm form = new MyForm();
while( ! form.exitloop )
{
AcadApp.ShowModalDialog(form);
if( ! form.exitloop )
AcadApp.DocumentManager.Open(...);
}
}
}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5669645@discussion.autodesk.com...
Tony, maybe I have not being able to explain the situation clearly. The "Invalid execution context" error occurs, when I try to iterate thru the list of drawings opening them. The form frmUpdateDwgs works fine. Once it is displayed the user can select drawings files from the system drives. The problem is, when I try to open each drawing (hiding the form here didn't do anything). In VBA this procedure works fine, but in .NET the Application/Document context restrictions make it difficult to make this code work. Unfortunately, I don't have much documentation and I haven't been able to find anything meaningful on the subject. I am starting to think that perhaps this won’t work. Your help is really appreciated.
Message 16 of 33
Anonymous
in reply to: Anonymous

Tony with all your respects, your suggestion doesn't work or I can't make it work. The process is started from the command declaration and once the form is shown its code takes focus, only to pass it back to the command sub when the form is closed. What I need is a way of making the DocumentManager.Open method work while the form is running. How or under which conditions does this method work? Is it possible at all to have a form running and call this method?
Message 17 of 33
Anonymous
in reply to: Anonymous

Here is the code I am working on or better yet trying to make it work:

1- Command declaration

Imports Autodesk.AutoCAD.Windows
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports System.Windows.Forms
Public Class DrawingProcess
_
Public Shared Sub UpdateBox()

Dim frm As New frmUpdateDwg


Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(frm)

frm.Dispose()

End Sub

End Class

2- Form class, Form + ListView + 3 Buttons

Imports Autodesk.AutoCAD.Windows
Imports Autodesk.AutoCAD.ApplicationServices
Imports System.Windows.Forms
Public Class frmUpdateDwg
Public Function GetDrawings()

Dim opnFiles As Autodesk.AutoCAD.Windows.OpenFileDialog

opnFiles = New Autodesk.AutoCAD.Windows.OpenFileDialog("Select Files", "", "dwg", "Select Drawings", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple)

opnFiles.ShowDialog()

Return opnFiles.GetFilenames

End Function

Public Sub LoadDrawings()
Dim Lst() As String
Dim FilePath As String
Dim ListItem As ListViewItem

Lst = Me.GetDrawings()

If Not Lst Is Nothing Then

If Lst.Length > 0 Then

Me.ListView1.BeginUpdate()

For Each FilePath In Lst

If Me.ListView1.Items.ContainsKey(FilePath) = False Then

ListItem = Me.ListView1.Items.Add(FilePath, System.IO.Path.GetFileName(FilePath), 0)
ListItem.SubItems.Add(FilePath)

End If

Next
Me.ListView1.EndUpdate()
End If
End If
End Sub

Private Sub ButtonAddDrawings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAddDrawings.Click
Call Me.LoadDrawings()
End Sub

Private Sub ButtonUpdateDrawings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdateDrawings.Click
Dim ListItem As ListViewItem

If Me.ListView1.Items.Count > 0 Then
For Each ListItem In Me.ListView1.Items
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(ListItem.SubItems(1).Text, False)
Next
End If
End Sub

Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExit.Click
Me.Close()
End Sub
End Class

Please someone take a look at this code and if you can make work, let me know how. Thanks.
Message 18 of 33
Mikko
in reply to: Anonymous

Maybe something like this?

'=============================================
'THE CLASS CODE:

Imports Autodesk.AutoCAD.Runtime

Public Class Class1

<CommandMethod("HowTo", CommandFlags.Session)> Public Sub HowTo()
Dim exam As New example
exam.ShowDialog()
exam.Dispose()
End Sub

End Class

'=============================================
'THE WINDOWS FORM named example with one button:

Public Class example

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fbd As New Windows.Forms.FolderBrowserDialog
Dim ThisOne As String = ""
If fbd.ShowDialog() = Windows.Forms.DialogResult.OK Then
ThisOne = fbd.SelectedPath
Else
MsgBox("You must select a Folder")
Exit Sub
End If
For Each foundFile As String In My.Computer.FileSystem.GetFiles(ThisOne, FileIO.SearchOption.SearchAllSubDirectories, "*.dwg")
Dim docs As Autodesk.AutoCAD.ApplicationServices.DocumentCollection
docs = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
Try
docs.Open(foundFile, False)
Catch Ex As Exception
End Try
Next
End Sub

End Class
Message 19 of 33
Anonymous
in reply to: Anonymous

Hi Mikko,
I don't know if you have tried to run your code, I will say you did. If you don't get any "Invalid execution context" let me know which version of AutoCAD you are using and any particular settings in your project. I am doing almost the same thing in my code and I get the error message.
Message 20 of 33
Mikko
in reply to: Anonymous

2008 and yes this does work for me. Nothing special, that is the whole of it.

one more thing is, I'm not using:
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(frm)
instead I use:
exam.ShowDialog() Message was edited by: Mikko

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