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

Opening Document

32 REPLIES 32
Reply
Message 1 of 33
HJohn
1512 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 21 of 33
Mikko
in reply to: HJohn

Just gotta say that I tried your code out and it also works for me.
Message 22 of 33
Anonymous
in reply to: HJohn

Yes, your code works for all version of Acad (on my Acad2006/7, and your
acad2008). However, the difference is how the dialog box is opened:

DialogBoxForm.ShowDialog();

or

Autodesk.AutoCAD.ApplicationServices.Application.ShowModal(Dialog(DialogForm);

With former, it works, while with latter, it does not. According to Acad
documentation, you SHOULD NOT use .NET built-in method Form.ShowDialog() to
open the dialogbox, instead, use
Autodesk.Au.......Application.ShowModalDialog(form) method. It also says,
with former, unexpected effect could happen, because you are not supposed to
do that.

In my developing, I always use
Auto...Application.ShowModalDialog()/ShowModelessDialog() to open the first
form. If I need open another dialog from the opened form, I tend to use
Form.ShowDialog().

So, to the OP, if you want to take unknown risk (or no risk at all, who
knows), against Autodesk's instruction, go ahead to use Form.ShowDialog(),
or you have to find other workaround, such as modeless dialog or
close(unload) and re-open the modal dialog between drawing being opening.


wrote in message news:5670898@discussion.autodesk.com...
2008 and yes this does work for me. Nothing special, that is the whole of
it.
Message 23 of 33
Mikko
in reply to: HJohn

Just for the record, I've never had any errors with the showdialog() and I've never seen or read anything on using it one way or the other. Probably because I don't do alot of reading and it works for me.... and everybody who uses my apps.
Message 24 of 33
Anonymous
in reply to: HJohn

This is quoted from AutoCAD ObjectARX SDK help document ("acad_mgd.chm"):


To implement custom forms in the AutoCAD managed API, applications extend
the .NET System.Windows.Forms classes directly. However, such applications
should not call the Form.ShowDialog method. They should instead use the
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog and
ShowModelessDialog methods to display their custom forms. Using
Form.ShowDialog in an AutoCAD extension application may result in unexpected
behavior.


One unexpected behavior I have seen could just happen on the topic we are
discussing here: opening a drawing from a modal dialog (that is, only the
modal dialog is opened by Form.ShowModalDialog(), otherwise you cannot open
drawing, as we already know). I have seen the opened drawing does not become
active drawing sometimes, that is, if the drawing editor already has one or
more drawing open, when click a button on the modal form to open new
drawing, the newly opened drawing is hidden behind. This does not always
happen in my limited tests, but it does happen from time to time, thus
"unexpected behavior". Of course this may not be killer argument to deny
using Form.ShowDialog(). I am only quoting what Autodesk says, and try to
follow their recommendations whenever possible.


wrote in message news:5670947@discussion.autodesk.com...
Just for the record, I've never had any errors with the showdialog() and
I've never seen or read anything on using it one way or the other. Probably
because I don't do alot of reading and it works for me.... and everybody who
uses my apps.
Message 25 of 33
Mikko
in reply to: HJohn

Lucky for me I never read any of that.

.... and I--
I took the one less traveled by,
And that has made all the difference.
Message 26 of 33
Anonymous
in reply to: HJohn

wrote in message news:5671463@discussion.autodesk.com...
Lucky for me I never read any of that.

>.... and I--
>I took the one less traveled by,
>And that has made all the difference.

Actually you're right on the beaten path by not using the help menu - now
the fact that you choose to ignore the proper way to do this and instead
quote
cute books when told how - is definetly a less traveled road...
Message 27 of 33
Mikko
in reply to: HJohn

Proper? In whose eyes? Who wrote that, are they down in the trenches producing code or are they wondering what to write in the docs for the software they never use? I have a hard time believing the code writers are also the document writers. Two different beasts. Anyhow the bottom line is it works for me, no arm twisting here. Many different ways to do the same thing, pick what works for you and run with it. I've made a very good living off doing it my way and I'm not even Frank Sanatra. Glad you liked the quote. Gotta love this stuff. Is it time to play Forza2 yet....
Message 28 of 33
HJohn
in reply to: HJohn

Well, I did read the help documents. I never thought to use the ShowDialog method or function, because it is mentioned, as quoted above, not to use it. In addition to that, the version of the managed classes on my AutoCAD 2007 don't list it as a member of the Application class. I can't figure out how to make this work and I don't see a solution without resolving the Application/Document context restrictions. If Mr. Tony Tanzillo can not suggest a solution, what is left for me. Well I just hang my hat for now. Thanks to you all.
Message 29 of 33
Mikko
in reply to: HJohn

http://discussion.autodesk.com/thread.jspa?messageID=4900551

About 2/3's down the page. Tony Tanzillo's reply to my question "What are the advantages of using AutoCAD winforms?". I've not found any reason to doubt that answerer yet. Of couse it is a couple years old.
Message 30 of 33
Anonymous
in reply to: HJohn

wrote in message news:5671755@discussion.autodesk.com...
Proper? In whose eyes? Who wrote that, are they down in the trenches
producing code or are they wondering what to write in the docs for the
software they never use? I have a hard time believing the code writers are
also the document writers. Two different beasts. Anyhow the bottom line is
it works for me, no arm twisting here. Many different ways to do the same
thing, pick what works for you and run with it. I've made a very good
living off doing it my way and I'm not even Frank Sanatra. Glad you liked
the quote. Gotta love this stuff. Is it time to play Forza2 yet....


Had to do a report on Road less travelel once.
Question asked what is the author saying - think
I got an A but still not sure what he was saying. `~)
Message 31 of 33
NathTay
in reply to: HJohn

Here is your code modified as per Tony's suggestion.

Imports Autodesk.AutoCAD.Windows
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports System.Windows.Forms
Public Class DrawingProcess

Public Sub UpdateBox()
Dim frm As New frmUpdateDwg
Do Until frm.DialogResult = System.Windows.Forms.DialogResult.Cancel
Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(frm)
If frm.DialogResult = System.Windows.Forms.DialogResult.OK Then
Dim ListItem As ListViewItem
If frm.ListView1.Items.Count > 0 Then
For Each ListItem In frm.ListView1.Items
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(ListItem.SubItems(1).Text, False)
Next
End If
End If
Loop
frm.Dispose()
End Sub

End Class


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
Me.Close()
Me.DialogResult = System.Windows.Forms.DialogResult.OK
End Sub

Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExit.Click
Me.Close()
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
End Sub

End Class
Message 32 of 33
HJohn
in reply to: HJohn

THANK YOU NATHAN & TONY! I tried it and it works, not exactly how I wanted, but definitely a big step in the right direction. I just wish I could understand how the Application/Document context works. Closing the form in order to open a document, although a solution presents other difficulties.
Message 33 of 33
johndonaldson
in reply to: Anonymous

re: Visible to false then visible=true

THANK YOU THANK YOU THANK YOU for solving my problem.

 

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