Author Topic: OpenFileDialog  (Read 15719 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
OpenFileDialog
« on: January 28, 2007, 09:12:18 AM »
To continue a thread here that I started in the net forum, here  I am looking for a was in visual lisp to evoke the windows dialog box below with the ability to select multiple files.
I am not sure of the method needed or how to set it up.
But if you can do this to browse for folders, why can't you Browse for files?
Code: [Select]
(setq shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
(setq folder
(vlax-invoke-method
shell
'BrowseForFolder
0
message
512
path
)
)
<edit: spelling>
« Last Edit: January 29, 2007, 09:10:48 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Patrick_35

  • Guest
Re: OpenFileDialog
« Reply #1 on: January 28, 2007, 03:04:32 PM »
Hi
Try this
Code: [Select]
(defun FileBox(/ cdl f)
;OFN_READONLY &H1       1 La case 'Lecture seule' est cochée à la création de la fenêtre.
;OFN_OVERWRITEPROMPT &H2       2 Afficher un message de confirmation d'écrasement de fichier si celui-ci existe déjà.
;OFN_HIDEREADONLY &H4       4 Case à cocher 'Lecture seule' invisible.
;OFN_NOCHANGEDIR &H8       8 Conserve le répertoire d'origine à la fermeture de la fenêtre.
;OFN_SHOWHELP &H10      16 Afficher le bouton 'Aide' dans la boîte de dialogue.
;OFN_NOVALIDATE &H100     256 Ne vérifie pas la validité de la saisie (validité du nom de fichier).
;OFN_ALLOWMULTISELECT &H200     512 Autoriser la sélection multiple de fichiers.
;OFN_EXTENSIONDIFFERENT &H400    1024 Indique que l'utilisateur a choisi une extension différente de celle par défaut.
;OFN_PATHMUSTEXIST &H800    2048 Les chemins et fichiers saisis doivent exister.
;OFN_FILEMUSTEXIST &H1000    4096 Seuls des fichiers existants peuvent être saisis.
;OFN_CREATEPROMPT &H2000    8192 Afficher une fenêtre de confirmation de création de fichier.
;OFN_SHAREAWARE &H4000   16384 Ignorer les erreurs de partage réseau.
;OFN_NOREADONLYRETURN &H8000   32768 Ne sélectionne pas la case à cocher 'Lecture seule'.
;OFN_NOTESTFILECREATE &H10000   65536 Le fichier ne sera pas créé avant la fermeture de la fenêtre.
;OFN_NONETWORKBUTTON &H20000 131072 Cache (désactive) le bouton 'Réseau'.
;OFN_NOLONGNAMES &H40000 262144 Utilise les noms courts de fichier (sans effet dans le cas des fenêtres du type 'Explorer').

;OFN_EXPLORER &H80000 524288 Donne un style 'Explorer' à la boîte de dialogue (par défaut).
; Qui ne fonctionne apparement pas sous XP

;OFN_LONGNAMES &H200000 2097152 Gestion des noms longs pour les boîtes de dialogue n'ayant pas le style 'Explorer'.
;OFN_NODEREFERENCELINKS &H100000 1048576 La boîte de dialogue prendra le nom et le chemin du raccourci sélectionné.

  (setq cdl (vlax-create-object "userAccounts.CommonDialog"))
  (vlax-put-property cdl 'filter (vlax-make-variant "Fichiers dessins (*.dwg)| *.dwg |Fichiers DXF (*.dwf) |Tous les fichiers (*.*)|*.*"))
  (vlax-put-property cdl 'filterindex 1)
  (vlax-put-property cdl 'flags (+ 4 8 512 2048 4096 131072 2097152))
  (vlax-put-property cdl 'initialdir (getvar "dwgprefix"))
  (if (eq (vlax-invoke cdl 'showopen) -1)
    (setq f (vlax-get-property cdl 'filename))
    (setq f nil)
  )
  (vlax-release-object cdl)
  f
)

ps : sorry for the language. It's in french

@+


<edit: Fixed Code tags>
« Last Edit: January 28, 2007, 03:35:39 PM by CAB »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #2 on: January 28, 2007, 03:39:58 PM »
Yes, I expected that to work but my Windows2000 does not have "comdlg32.dll" or "comdlg.dll"
Is that file only added when you use NET or Visual basic?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: OpenFileDialog
« Reply #3 on: January 28, 2007, 04:15:04 PM »
CAB,
all windows installations have comdlg, but the file may be a different name. To determine if you can create that dialog, try to create it from the class name ..
Code: [Select]
(setq dialog (vlax-create-object "MSComDlg.CommonDialog"))

To determine which values you need to set, you can refer to the constants provided by patrick, but some of the variable names are different depending upon the version of Windows you have.
To get the correct names, just dump the object

Code: [Select]
(vlax-dump-object dialog)

You will now be able to see the values you need to set.

I have revised the code provided by Patrick to work on my system (along with a couple of code corrections)
Code: [Select]
(defun FileBox(/ cdl f)
;OFN_READONLY &H1       1 La case 'Lecture seule' est cochée à la création de la fenêtre.
;OFN_OVERWRITEPROMPT &H2       2 Afficher un message de confirmation d'écrasement de fichier si celui-ci existe déjà.
;OFN_HIDEREADONLY &H4       4 Case à cocher 'Lecture seule' invisible.
;OFN_NOCHANGEDIR &H8       8 Conserve le répertoire d'origine à la fermeture de la fenêtre.
;OFN_SHOWHELP &H10      16 Afficher le bouton 'Aide' dans la boîte de dialogue.
;OFN_NOVALIDATE &H100     256 Ne vérifie pas la validité de la saisie (validité du nom de fichier).
;OFN_ALLOWMULTISELECT &H200     512 Autoriser la sélection multiple de fichiers.
;OFN_EXTENSIONDIFFERENT &H400    1024 Indique que l'utilisateur a choisi une extension différente de celle par défaut.
;OFN_PATHMUSTEXIST &H800    2048 Les chemins et fichiers saisis doivent exister.
;OFN_FILEMUSTEXIST &H1000    4096 Seuls des fichiers existants peuvent être saisis.
;OFN_CREATEPROMPT &H2000    8192 Afficher une fenêtre de confirmation de création de fichier.
;OFN_SHAREAWARE &H4000   16384 Ignorer les erreurs de partage réseau.
;OFN_NOREADONLYRETURN &H8000   32768 Ne sélectionne pas la case à cocher 'Lecture seule'.
;OFN_NOTESTFILECREATE &H10000   65536 Le fichier ne sera pas créé avant la fermeture de la fenêtre.
;OFN_NONETWORKBUTTON &H20000 131072 Cache (désactive) le bouton 'Réseau'.
;OFN_NOLONGNAMES &H40000 262144 Utilise les noms courts de fichier (sans effet dans le cas des fenêtres du type 'Explorer').

;OFN_EXPLORER &H80000 524288 Donne un style 'Explorer' à la boîte de dialogue (par défaut).
; Qui ne fonctionne apparement pas sous XP

;OFN_LONGNAMES &H200000 2097152 Gestion des noms longs pour les boîtes de dialogue n'ayant pas le style 'Explorer'.
;OFN_NODEREFERENCELINKS &H100000 1048576 La boîte de dialogue prendra le nom et le chemin du raccourci sélectionné.

  (setq cdl (vlax-create-object "MSComDlg.CommonDialog"))
  (vlax-put-property cdl 'filter (vlax-make-variant "AutoCAD Drawing (*.dwg)| *.dwg |Drawing eXchange File DXF (*.dwf) |All Files (*.*)|*.*"))
  (vlax-put-property cdl 'filterindex 1)
  (vlax-put-property cdl 'flags (+ 4 8 512 2048 4096 131072 2097152))
  (vlax-put-property cdl 'initdir (getvar "dwgprefix"))
  (vlax-put-property cdl 'maxfilesize 1024)
  (if (eq (vlax-invoke cdl 'showopen) -1)
    (setq f nil)
    (setq f (vlax-get-property cdl 'filename))
  )
  (vlax-release-object cdl)
  f
)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Patrick_35

  • Guest
Re: OpenFileDialog
« Reply #4 on: January 28, 2007, 07:31:54 PM »
Sorry Keith
But comdlg don't work with Windows XP  and A2000 :-(
(setq cdl (vlax-create-object "MSComDlg.CommonDialog")) return nil

@+

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #5 on: January 28, 2007, 08:17:34 PM »
Shoot, it returns nil here as well. :-(
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: OpenFileDialog
« Reply #6 on: January 29, 2007, 08:35:15 AM »
Well ... I have just tried it again, this time on XP SP2 ... so far I have been able to run it on Win98, WinME, WinXP SP1, and WinXP SP2 ... 4 different computers 2 with XP.

There must be something different in your setup preventing it from being created.

Open the registry, select hkey_classes_root then scroll down and see if you can find "MSComDlg.CommonDialog"
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #7 on: January 29, 2007, 08:55:50 AM »
OK, found this:
The {xxxx-xxxx-xxx...} are deferent data values.
Code: [Select]
/CLSID/{XXX-XXX-XXXX...}
/MSComDlg.CommonDialog ->Microsoft ...., version 6.0 (SP6)
.../CLSID  -> {xxx-xxxxx-xxx...}
.../CurVer -> MSComDlg.CommonDialog.1


/MSComDlg.CommonDialog.1 -> {xxx-xxxxx-xxx...}
.../CLSID  -> {xxx-xxxxx-xxx...}

PS I'm runnung Windows 2000
« Last Edit: January 29, 2007, 08:58:25 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: OpenFileDialog
« Reply #8 on: January 29, 2007, 08:59:50 AM »
Try changing the creation object to "MSComDlg.CommonDialog.1"
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #9 on: January 29, 2007, 09:08:22 AM »
No Joy.
Code: [Select]
_$ (setq dialog (vlax-create-object "MSComDlg.CommonDialog"))
nil
_$ (setq dialog (vlax-create-object "MSComDlg.CommonDialog.1"))
nil
_$ (setq dialog (vlax-create-object "MSComDlg.CommonDialog"))
nil
_$
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Fatty

  • Guest
Re: OpenFileDialog
« Reply #10 on: January 29, 2007, 09:46:29 AM »
Alan, agree with you
Tested in A2005 eng
Not works for me also
Maybe need to register this component before?

~'J'~

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: OpenFileDialog
« Reply #11 on: January 29, 2007, 09:57:38 AM »
If it is in the registry, then it is already registered.

If you do a search for ComDlg32.ocx do you find anything?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #12 on: January 29, 2007, 10:28:46 AM »
Thanks for the help Keith.
This is what I found.
Don't know why I didn't find it on a previous search.
« Last Edit: January 29, 2007, 10:30:07 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: OpenFileDialog
« Reply #13 on: January 29, 2007, 10:33:02 AM »
Just tried in ACAD2004 & nil was returned.  :-(
Code: [Select]
(setq dialog (vlax-create-object "MSComDlg.CommonDialog"))
(setq dialog (vlax-create-object "MSComDlg.CommonDialog.1"))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: OpenFileDialog
« Reply #14 on: January 29, 2007, 10:34:09 AM »
I cannot fathom why it will not allow you to create the window ... have you tried re-registering the dll or OCX with regsvr32 ?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie