Leaderboard
Popular Content
Showing content with the highest reputation on 01/17/2023 in all areas
-
See my updated code. I only posted the if line so you could replace it in the original code. sorry i didn't make the more clear.1 point
-
This might be your problem: (if Your second line: (if (setq ss (ssget "_X" '((-4 . "<OR") (62 . 5) (62 . 4) (-4 . "OR>"))))) read as "If SS is somethng do... nothing" - you'll maybe be wanting to remove the 'if' or before your closing bracket tell the LISP what to do: (if (setq ss (ssget "_X" '((-4 . "<OR") (62 . 5) (62 . 4) (-4 . "OR>")))) (progn ;; do all your clever stuff here if selection set finds anything blue or cyan ) (progn ;; do all your other clever stuff here if nothing is blue or cyan ) ) often selection set is enclosed with an 'if' so that the LISP doesn't fail if there is nothing valid selected - you can go off and do something like an error message to the user1 point
-
Try this, does what I posted above: (my preference, but I can take this LISP with me anywhere, change companies, computer dies, change installation and you need to set up all the CUI again) Command RunLisp ;;;;c:RunLisp;;;;; ;;Sub Routines: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; ;;;; UPDATE THIS LISP TO YOUR LISP SAVED LOCATION ;;;; ;;;; ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun GetMyLispFolder( / MILFO) (setq MILFO "C:\\Users\\AutoCAD LISPS\\") ;;Edit for laptop: ;;These lines here, in case of using 2 computers with 2 different paths to your 'users' profile and files ;; (if (= (findfile "C:\\Users\\AutoCAD LISPS\\RUNLISP.lsp") nil) ;;change file name to something in your files ;; (setq MILFO "C:\\Users\\AutoCAD LISPS\\") ;; ) ;; (setq MILFO "c:\\") ;; default C drive MILFO ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Browse for Folder - Lee Mac ;; Displays a dialog prompting the user to select a folder. ;; msg - [str] message to display at top of dialog ;; dir - [str] [optional] root directory (or nil) ;; bit - [int] bit-coded flag specifying dialog display settings ;; Returns: [str] Selected folder filepath, else nil. (defun LM:browseforfolder ( msg dir bit / err fld pth shl slf ) (setq err (vl-catch-all-apply (function (lambda ( / app hwd ) (if (setq app (vlax-get-acad-object) shl (vla-getinterfaceobject app "shell.application") hwd (vl-catch-all-apply 'vla-get-hwnd (list app)) fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir) ) (setq slf (vlax-get-property fld 'self) pth (vlax-get-property slf 'path) pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth)) ) ) ) ) ) ) (if slf (vlax-release-object slf)) (if fld (vlax-release-object fld)) (if shl (vlax-release-object shl)) (if (vl-catch-all-error-p err) (prompt (vl-catch-all-error-message err)) pth ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun GetRunLisp(/ RL) (setq RL "No") RL ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun GetMyLispFiles ( / MILF MILFI) (setq MILFI (vl-directory-files (GetMyLispFolder) "*.lsp" nil)) MILFI ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun GetLastListSelection( / LLS) (setq LLS "LH") LLS ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;When a different *.lsp file is selected, changes the lisps;; ;;drop down list contents (defun SP:updatelisps( spLispFolder splispfiles / lispsreturn mylispfiles myfile mylisps lisps ) ;;(defun SP:updatelisps( spLispFolder splispfiles / ) (setq y nil) (setq y (read (get_tile "lispfiles"))) (setq mylispfiles (vl-directory-files mylispfolder "*.lsp" nil)) (setq myfile (strcat mylispfolder (nth y mylispfiles))) (setq mylisps (LM:getsyntax myfile)) (setq mylisps (vl-remove "\"" mylisps)) ;;to remove defined items from the list. Example, it picks up 'defun c:"' in programming as lisp '"' (setq mylisps (vl-sort mylisps '<)) ;;sorts the list (start_list "lisps" 3)(mapcar 'add_list mylisps)(end_list) ;;create Lisps list ;; lisps (setq lispsreturn (list lisps mylispfiles myfile mylisps)) lispsreturn ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun SP:selectfolder( / SFMyDir SFLispFiles) (setq SFMyDir (LM:browseforfolder "Select a folder" "SFMyDir" 0)) (if (/= SFMyDir Nil) ;;if folder selection wasn't cancelled (progn (set_tile "foldertext" SFMyDir) (setq SFMyDir (strcat SFMyDir "\\")) (setq SFLispFiles (vl-directory-files SFMyDir "*.lsp" nil)) ;;runlispfiles is the list of files in runlispdir location (setq lispfiles nil) (start_list "lispfiles" 3)(mapcar 'add_list SFLispFiles)(end_list) ;;create Lisp files list (setq z (read (get_tile "lispfiles"))) (setq myfile (strcat SFMyDir (nth z SFLispFiles))) (setq mylisps (LM:getsyntax myfile)) (SP:lisplist SFMyDir) (start_list "AllLisps" 3)(mapcar 'add_list allthelisps)(end_list);;create Lisp files list (setq mylispfolder SFMyDir) (setq runlispfiles SFLispFiles) );;end progn );; end if ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;creates a text box pop up listing all the lisp routines in;; ;;*.lsp files in the location below ;; (defun SP:lisplist ( lisplistfolder / SortedLisps SortedFiles SortedListLength SortedCount) (setq allthelisps nil) (setq mylispfileslist nil) (setq mylispfileslist "") (setq mylispfiles (vl-directory-files lisplistfolder "*.lsp" nil)) ;;mylispfiles is list of files in mylispfolder location (setq mylistlength (length mylispfiles)) ;;count of number of lsp files (setq acount -1) (setq myroutines "") (repeat mylistlength (setq acount (1+ acount)) (setq myfilename (strcat lisplistfolder (nth acount mylispfiles))) (progn (if (not (mapcar '(lambda ( x ) (princ)) (setq mylisplist (LM:GetSyntax myfilename)))) ;;puts list into an array (princ "\n -None-\n") ) (setq mylisplist (vl-remove "\"" mylisplist)) ;;to remove defined items from the array. (foreach n mylisplist ;;loops through array (progn (setq allthelisps (cons n allthelisps)) ;;All the lisps is a list of all the lisps (setq mylispfileslist (cons myfilename mylispfileslist)) ;;generates a list of files coresponding to the LISPS ) ; end progn ) ; end foreach ) ) (setq SortedLisps (vl-sort allthelisps '<)) ;;sorts the list (setq SortedListLength (vl-list-length SortedLisps)) (setq SortedCount 0) (while (<= (+ SortedCount 1) (vl-list-length SortedLisps)) (setq LLFilePath (nth (vl-position (nth SortedCount SortedLisps) allthelisps) mylispfileslist)) ;;make into a list (setq SortedFiles (cons LLFilePath SortedFiles)) ;;generates a list of files coresponding to the LISPS (setq SortedCount (+ SortedCount 1)) ) (setq allthelisps SortedLisps) (setq mylispfileslist (reverse SortedFiles)) (setq lisplist (list allthelisps mylispfileslist)) lisplist ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;When a lisp routine is selected or OK pressed (defun RL:runlisp () ;;Add in here check if anything was selected (setq runlisp "Yes") (setq popupvalue (read (get_tile "lisps"))) (setq alisp (strcat "c:" (nth popupvalue mylisps))) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;Creates a pop up box listing the *.lsp files and the lips ;; ;;routines within that file ;; ;;Selecting a lisp routine name will run that lisp routine ;; (defun c:RunLisp ( / dcl des dch) ;;Initial values (setq runlisp (GetrunLisp)) (setq mylispfolder (GetMyLispFolder)) (setq mylispfiles (GetMyLispFiles)) ;;list of files in mylispfolder location. (setq lastlistselection (GetLastListSelection)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;create DCL pop up box :: (if (and (setq dcl (strcat (getvar "TEMPPREFIX") "RunLisps.dcl")) ;; make tenporary DCL file in temp folder (setq des (open dcl "w")) (foreach x '( " pass : dialog" " {" " key = \"Lispdialoguebox\";" " label = \"RUN LISP\";" " spacer;" " : boxed_column { label = \"Select LISP Routine\";" " : row { width = 60; alignment = centered;" " : column {width = 20; alignment = centered;" " :row {alignment = bottom;" " : text { key = \"filetext\"; label = \"File Name\"; width = 20; alignment = right;}" " }" " }" " : column {width = 40; alignment = left;" " : popup_list { key = \"lispfiles\"; width = 40; multiple_select = true ; alignment = left; }" " }" " }" " : row { width = 60; alignment = centered;" " : column {width = 20; alignment = centered;" " :row {alignment = bottom;" " : text { key = \"Lisptext\"; label = \"Lisp Name\"; width = 20; alignment = right;}" " }" " }" " : column {width = 40; alignment = left;" " : popup_list { key = \"lisps\"; width = 40; multiple_select = true ; alignment = left; allow_accept = true;}" " }" " }" " : row {" " : button { key = \"folder\"; label = \"Change Lisp Library\"; is_default = false; fixed_width = true; width = 5;}" " : text { key = \"foldertext\"; label = \"Folder Location\"; width = 40; }" " spacer;" " }" " }" " : boxed_column { width = 60; alignment = left;" " : row {" " : column {width = 18; alignment = centered;" " : button { key = \"accept\"; label = \"OK\"; is_default = true; is_cancel = true; fixed_width = true; width = 15; }" " }" " : column {width = 18; alignment = centered;" " : button { key = \"cancel\"; label = \"Cancel\"; is_default = false; is_cancel = true; fixed_width = true; width = 15; }" " }" " }" " }" " }" ) (write-line x des) ) (not (setq des (close des))) (< 0 (setq dch (load_dialog dcl))) (new_dialog "pass" dch) ) (progn ;;End of DCL pop up box ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;makes a pop-up list box (start_list "lispfiles" 3)(mapcar 'add_list mylispfiles)(end_list);;create Lisp files list (set_tile "foldertext" mylispfolder) (action_tile "lispfiles" "(setq lisps (SP:updatelisps mylispfolder (read (get_tile \"lispfiles\"))))") (action_tile "lispfiles" "(setq nthlisps (SP:updatelisps mylispfolder (read (get_tile \"lispfiles\")))) (setq lisps (nth 0 nthlisps)) (setq mylispfiles (nth 1 nthlisps)) (setq myfile (nth 2 nthlisps)) (setq mylisps (nth 3 nthlisps)) " ) ; end action tile (action_tile "folder" "(SP:selectfolder)") ;; RLMyLispFolder RLLastListSelection (setq lastlistselection "Alllisplist") ;;set this to whatever (action_tile "accept" "(RL:runlisp)(done_dialog 1)") (action_tile "cancel" "(done_dialog 0)") (start_dialog) ) ;;end of DCL 'and' above (princ "\nError. Unable to load dialogue box.") ) ;;end of DCL 'if' above (vl-file-delete dcl) ;;delete the temp DCL file (if (= runlisp "Yes") (progn (load myfile) (princ "\n") (princ alisp) (princ ": ") (eval (list (read alisp))) ;;run the lisp ) ) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;RUNLISP Keyboard Command "RunLisp" ;;Gives the user a dialogue box to select and run a lisp ;;Lisps are listed by the file that they are saved in ;;1 point
-
As a start with lots of LISPS, Lee Macs getsyntax will search through the LISP files and return the LISP names in each (if the follow the syntax "(defun c:LISPNAME ...." Options are Tombu and making up a CUI, BigAl might have something up his sleeve with DCL, I have a DCL that returns a list of al the LISPs in a folder (needs a lot to change it about to be an index though). DCL and LISP has a benefit perhaps that the list of LISPs can be made 'on the fly' (and Lee Macs Get Syntax can be modified to do that)1 point
-
(defun c:gtht (/ AllText i) (vl-load-com) (setq TxtHt (cond ((getdist (strcat "\nEnter text height" (if TxtHt (strcat " <" (rtos TxtHt) ">: ") ": " ) ) ) ) (TxtHt) ) ) (if (Setq AllText (ssget "_X" '((0 . "*TEXT")))) (repeat (setq i (sslength AllText)) (vlax-put (vlax-ename->vla-object (ssname AllText (setq i (1- i)))) 'Height TxtHt ) ) )(princ) )1 point