jamami Posted June 9 Posted June 9 In the script below vl-fle-dialog is not recognised and I get the error:- ; error: no function definition: VL-FILE-DIALOG Is Vl-FILE-DIALOG contained in a library or other resource that I need to load? <(defun c:SelectFolder () (vl-load-com) (setq folder (vl-file-dialog "Select a Folder" nil nil 1)) (if folder (progn ;; Extract the folder name from the full path (setq folder-name (vl-filename-base (vl-filename-directory folder))) (princ (strcat "\nSelected folder: " folder-name)) ) (princ "\nNo folder selected.") ) (princ) )> Quote
Lee Mac Posted June 9 Posted June 9 vl-file-dialog is not a function which exists in the AutoLISP API - I'm guessing this code came from an LLM? Quote
jamami Posted June 9 Author Posted June 9 I am new to lisp and asked chat gpt. I suspected this was not correct as cannot find reference to that function anywhere on the net. rlx kindly gave me the routine below and I have been working on breaking it down to understand the code. there are 3 sub routines allfolders, allfiles and getshellfolder, that dont appear to do anything.... i am trying to update this c:wbf routine to allow selection of a folder to which the blocks are wblocked to, at present they appear in the folder the parent dwg has been opened from and the path users/me/test seems to be irrelevant... < (defun c:wbf ( / symbolpath adoc item oldfiledia name blk blist oldexpert) (setq symbolpath "C:\\Users\\Me\\Test\\") (setq adoc (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-For item (vla-get-Blocks adoc) (if (not (or (eq :vlax-true (vla-get-isXRef item)) (eq :vlax-true (vla-get-isLayout item)))) (progn (setq name (vla-get-Name item)) (if (/= (substr name 1 1) "*")(setq blist (cons name blist)))))) (setq oldfiledia (getvar "FILEDIA")) (setq oldexpert (getvar "FILEDIA")) (setvar "FILEDIA" 0) (foreach item blist (setq blk (strcat symbolpath item)) (command "-wblock" blk "=")) (setvar "FILEDIA" oldfiledia) ) (defun allfolders ( d / sf so fo l) (defun sf (f / s)(if (< 0 (vlax-get (setq s (vlax-get f 'subfolders)) 'count)) (vlax-for x s (setq l (cons (vlax-get x 'path) l))(sf x)))) (setq so (vla-getinterfaceobject (vlax-get-acad-object) "Scripting.FileSystemObject")) (setq fo (vlax-invoke so 'getfolder (vl-string-trim "\\/" d))) (sf fo) (vl-catch-all-apply 'vlax-release-object (list so)) (acad_strlsort (mapcar 'dos_path (cons d l))) ) ;;; (length (allfiles "c:/temp/lisp")) (defun allfiles ( dir / l f r rl ) (setq l (allfolders dir)) (foreach f l (if (vl-consp (setq r (mapcar '(lambda (x) (strcat f x))(vl-directory-files f "*.*" 1)))) (setq rl (append rl r)))) rl) ; generic getfolder routine with possibility to create a new subfolder (GetShellFolder "select path") (defun GetShellFolder ( m / f s) (if (and (setq s (vlax-create-object "Shell.Application")) (setq f (vlax-invoke s 'browseforfolder 0 m 65536 "")))(setq f (vlax-get-property (vlax-get-property f 'self) 'path)) (setq f nil))(vl-catch-all-apply 'vlax-release-object (list s)) (if f (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" f)) "\\"))) > Quote
BIGAL Posted June 9 Posted June 9 Maybe start at Lee-macs "Browse for folder lisp. Lots of errors in that code. If you say want a directory under the current dwg location use this example. Dwgpre is the directory name. ; check that block directory exists (setq dwgpre (strcat (getvar "dwgprefix") "\block")) (if (= (vl-file-directory-p dwgpre) nil) (vl-mkdir dwgpre) ) Quote
SLW210 Posted June 10 Posted June 10 Please use Code Tags (<> in the editor toolbar), I have asked you a few times now. Try using Lee Mac's and AfraLISP sites to learn AutoLISP and VLISP instead of Chat GPT. You can also use the Developers Guide in your AutoCAD help. Quote
jamami Posted June 10 Author Posted June 10 3 minutes ago, SLW210 said: Please use Code Tags (<> in the editor toolbar), I have asked you a few times now. Try using Lee Mac's and AfraLISP sites to learn AutoLISP and VLISP instead of Chat GPT. You can also use the Developers Guide in your AutoCAD help. thanks for the resources. i have a lot of experience with vb but the constructs are very different in lisp. Have Autodesk made a commitment to lisp or will things move towards pyhthon, c etc ?? Quote
rlx Posted June 10 Posted June 10 couldn't be easier : (defun c:t1 ( / folder) (if (setq folder (GetShellFolder "Select the folder of your dreams")) (alert (strcat "The folder you selected was :\n " folder)) (alert "Folder selection aborted") ) ) (defun GetShellFolder ( m / f s) (if (and (setq s (vlax-create-object "Shell.Application")) (setq f (vlax-invoke s 'browseforfolder 0 m 65536 "")))(setq f (vlax-get-property (vlax-get-property f 'self) 'path)) (setq f nil))(vl-catch-all-apply 'vlax-release-object (list s)) (if f (strcat (vl-string-right-trim "\\" (vl-string-translate "/" "\\" f)) "\\")) ) Quote
Lee Mac Posted June 10 Posted June 10 2 hours ago, jamami said: i am using them ? what is the problem? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.