TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CAB on January 28, 2007, 09:12:18 AM
-
To continue a thread here that I started in the net forum, here (http://www.theswamp.org/index.php?topic=14711.0) 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?
(setq shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
(setq folder
(vlax-invoke-method
shell
'BrowseForFolder
0
message
512
path
)
)
<edit: spelling>
-
Hi
Try this
(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>
-
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?
-
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 ..
(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
(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)
(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
)
-
Sorry Keith
But comdlg don't work with Windows XP and A2000 :-(
(setq cdl (vlax-create-object "MSComDlg.CommonDialog")) return nil
@+
-
Shoot, it returns nil here as well. :-(
-
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"
-
OK, found this:
The {xxxx-xxxx-xxx...} are deferent data values.
/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
-
Try changing the creation object to "MSComDlg.CommonDialog.1"
-
No Joy.
_$ (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
_$
-
Alan, agree with you
Tested in A2005 eng
Not works for me also
Maybe need to register this component before?
~'J'~
-
If it is in the registry, then it is already registered.
If you do a search for ComDlg32.ocx do you find anything?
-
Thanks for the help Keith.
This is what I found.
Don't know why I didn't find it on a previous search.
-
Just tried in ACAD2004 & nil was returned. :-(
(setq dialog (vlax-create-object "MSComDlg.CommonDialog"))
(setq dialog (vlax-create-object "MSComDlg.CommonDialog.1"))
-
I cannot fathom why it will not allow you to create the window ... have you tried re-registering the dll or OCX with regsvr32 ?
-
CAB ...
I tried something here in this VLX .. let me know if it works ...
<REMOVED ATTACHMENT -- SEE LATER POST>
-
I regerestered the ocx & then tried this
_$ (setq dialog (vlax-create-object "MSComDlg.CommonDialog"))
nil
_$ (setq dialog (vlax-create-object "MSComDlg.CommonDialog.1"))
nil
_$
I then tried to register the dll & got this
-
Cab, try the VLX in the previous post to see if it provides the window, if it does, then I have a sneaking suspicion that the error is related to the design time license I have with the CommDlg32.ocx. Since I have the developer edition of VB both here and at home that may be the defining factor. Either way, if the above code works, it "should" grant you rights to use the dialog based on my giving you rights through my license ... i.e. the type library is on your computer, but the license to use it must come from a licensed developer .. in otherwords I can distribute an application that uses the comdlg window, but I can't distribute the type library and by my distribution of this application in the compiled format, it should .. theoretically give you permissions enough to create the window ... I don't know if it extends past the compiled code .. for example any code you might write.
-
Loaded it, used Start CommonDialog, Here is what I get:
-
WELL DAGNABIT ... The command is (commondialog) .. forgot to mention that ...
It should work ... back to the drawing board ..
-
Command: (commondialog)
Error: too many arguments
:-o
-
A different error? Now this is really getting intriguing ...
-
Command: (commondialog)
Error: too many arguments
:-o
Alan
I've got the similar one:
Command: (commondialog (getvar "dwgprefix"))
; error: too many arguments
Command: CommonDialog
Unknown command "COMMONDIALOG". Press F1 for help
Command: (CommonDialog)
; error: too many arguments
~'J'~
-
Ok .. try this one then ...
Same scenario ...
(commondialog) to run
-
:-(
Command: (commondialog)
; error: bad argument type: VLA-OBJECT nil
; reset after error
-
well ... darn ... I know I am sending the license through ... I have just never had to do it through lisp before ... I need to do a little more research ...
-
Thnaks for your time Keith.
-
cab i've been watching what's going on in this thread and am wondering is this what you had in mind for the plottabs script we were discussing last week. so the main goal here is to be able to open multiple files from multiple folders? just curious
-
Yes, but a useful tool for other lisp as well.
Here is the alternative routine.
;; Get user pick of files, one at a time
(defun c:test (/ file files)
(if (setq file (getfiled "Select a file to include in Batch" "" "dwg" 128))
(while
(setq files (cons file files)
file (getfiled "Select another file or Cancel to quit" file "dwg" 128)
)
)
(princ "\nNo files were selected.")
)
(and files (princ files))
(princ)
)
-
CAB you could smudge it by using the Browse for folders in your first post...
use the browse for folder to *ahem* browse for folders, then add a listbox to the form that displays all the files in the selected folder, and use that listbox to let the user select multiple files.
fwiw, I have the three controls on my system but still cannot use the commondialog and even stranger, I can bring in a routine from home utilising the common dialog and it works fine, but I cannot copy it across modules.
-
Thanks hendie for the feed back.
I did consider that method but no easy way to get files from two different folders.
I could add a button to get another folder I suppose.
-
CAB you could smudge it by using the Browse for folders in your first post...
use the browse for folder to *ahem* browse for folders, then add a listbox to the form that displays all the files in the selected folder, and use that listbox to let the user select multiple files.
Thanks hendie for the feed back.
I did consider that method but no easy way to get files from two different folders.
I could add a button to get another folder I suppose.
That is how I do it with my plot dialog box. I have a button to open the BrowseForFolder dialog, then I add all the drawings in said folder to a list box, then add the selected ones to a list, path and all.
-
Hi
Try this
(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>
Works for me here. Using windows xp and autocad 2007....but the dialog box is in french.
Gary
-
I was searching on the MSDN site and found this question.
Hey, Scripting Guy! Is there any way I can use a script to present a user with a dialog box and let him or her select a file?
-- BF
And this answer
Hey, BF. If you’re using Windows 2000, we don’t know of a way to do this, at least not a way that’s built into the operating system. That’s not the case with Windows XP, however. On Windows XP, you can use the UserAccounts.CommonDialog object to present users with a standard File Open dialog box. Here’s what the script looks like:
Here (http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan05/hey0128.mspx)
It doesn't look good for use Win2000 people Alan. I will continue to look when I have free time.
-
Oh well, at least I'll quit head butting that wall. :-)
-
I was searching on the MSDN site and found this question.
Hey, Scripting Guy! Is there any way I can use a script to present a user with a dialog box and let him or her select a file?
-- BF
And this answer
Hey, BF. If you’re using Windows 2000, we don’t know of a way to do this, at least not a way that’s built into the operating system. That’s not the case with Windows XP, however. On Windows XP, you can use the UserAccounts.CommonDialog object to present users with a standard File Open dialog box. Here’s what the script looks like:
Here (http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan05/hey0128.mspx)
It doesn't look good for use Win2000 people Alan. I will continue to look when I have free time.
Once again this doesn't Alan, but Tim's previous post was for a single selection Dialog box, HERE (http://www.microsoft.com/technet/scriptcenter/resources/qanda/mar05/hey0301.mspx) is for a multi-select Dialog Box.
Sorry Alan :-(
-
. . . good ole ObjectDCL . . . :lol:
-
. . . good ole ObjectDCL . . . :lol:
Does ObjectDCL has the same limit as regural dcl? Limited by the amout of items you can select, I think it's around 255 (Acads magic number).
-
Is there a flag for the UserAccounts.CommonDialog-Object to get a Filesaveas-dialog ?
-
ok .. found it ... look at the Object "SAFRCFileDlg.FileSave"