Alcapone001 Posted November 13, 2016 Posted November 13, 2016 Hello everyone. I recently started using lisp and I have found your these forumns real useful. I am just one month into lisp. I am currently stuck on how to have a single pop up with several buttons each that invokes a particular lisp function. Such that if the user clicks on a given button a particular lisp is invoked. This is really useful where there are many lisp functions that help a user to carry out particular tasks. For instance I have a lisp for creating grids, labelling coordinates and calculating the total lengths of lines and polylines. To make it user friendly I have created an alert dialog that tells a user what particular function is used to invoke what. But this happens to not be that user friendly, particularly where many lisps are involved. That is why I am looking at knowing how I can make use of buttons that when a user clicks a particular function is invoked. I have read similar threads on this and other forums but haven't succeeded. I have even tried using Open Dcl Studio, but since I happen to be a novice, I have not gone far. Attached is my lisp. Any help will be highly appreciated. Thank you Lisps.lsp Quote
halam Posted November 13, 2016 Posted November 13, 2016 I'm not yet familiar with Opendcl but this has a great deal of possibilities. But why don't you use a toolbar for your lisp for starters? It's very easy to copy modify so existing AutoCAD buttons to suite your needs.. Quote
Alcapone001 Posted November 13, 2016 Author Posted November 13, 2016 I'm not yet familiar with Opendcl but this has a great deal of possibilities. But why don't you use a toolbar for your lisp for starters? It's very easy to copy modify so existing AutoCAD buttons to suite your needs.. Yes I know that is possible, and convenient for an individual. But the challenge is I share the lisps with my colleagues and so you get asked a lot what is the function that calls up a particular lisp. And that is why I used the alert function that acts as a reminder of what is what. That way people don't have to come to me all the time. Then I thought instead of the alert pop up, I Could make the lisps better with a single pop up that contains buttons that if a user clicks on one, a particular lisp function is activated Quote
Alcapone001 Posted November 13, 2016 Author Posted November 13, 2016 And the pop up does not need to be using Open Dcl, it can be using Dcl or just visual lisp. Open Dcl is just one of the approaches I have tried using. If one can help me come up with a lisp code that does what I need, then the happier I will be Here is a sample of a pop up that I am trying to have, but done using OpenDcl. For instance to activate the coordinate lisp, the user just needs to click on the coordinates button, he or she does not need to remember and type the command for that particular lisp.. Just as shown in the image attached Quote
marko_ribar Posted November 13, 2016 Posted November 13, 2016 (edited) Hi there... You gave me an idea and I want to share how I managed this task... Sideway I'll explain how I install and automate my base lisp library that I automatically load at startup of AutoCAD session... First of all to explain how my main support folder looks like : - acaddoc.lsp - mylisps.lsp - lisp1.lsp - lisp2.lsp - ... - lispn.lsp - dll1.dll - dll2.dll - ... - dlln.dll - DOSLibXX (XXx64).arx Now to explain how I managed to install new application (lisp, dll)... Firstly you should install DOSLib from https://wiki.mcneel.com/doslib/home Once you installed DOSLib, copy adequate *.arx from installed folder to your support main folder (last file from my previously explained folder structure)... Then you should create acaddoc.lsp - I used this structure : ;;;(setvar 'startmode 0) (if (getvar 'secureload) (setvar 'secureload 0)) (if (getvar 'startup) (setvar 'startup 0)) (if (getvar '3dosmode) (setvar '3dosmode 0)) (setvar 'ucsdetect 0) (setvar 'pickbox 4) (setvar 'osmode 0) (setvar 'cmdecho 0) (setvar 'pdmode 35) (setvar 'pdsize -1.5) (setvar 'plinegen 1) (setvar 'delobj 1) (setvar 'ucsicon 3) (setvar 'qaflags 0) (if (vl-position "VLAX-GET-ACAD-OBJECT" (atoms-family 1)) (vlr-remove-all)) (if (findfile "DosLib20x64.arx") (arxload "DosLib20x64.arx") (arxload (getfiled "Select DosLib20x64.arx file" "c:/Program Files/DosLib 9.0/" "arx" 16))) (if (findfile "lisp1.lsp") (load "lisp1.lsp") (load (getfiled "Select lisp1.lsp file" "\\" "lsp" 16))) (if (findfile "lisp2.lsp") (load "lisp2.lsp") (load (getfiled "Select lisp2.lsp file" "\\" "lsp" 16))) ... (if (findfile "lispn.lsp") (load "lispn.lsp") (load (getfiled "Select lispn.lsp file" "\\" "lsp" 16))) (if (findfile "dll1.dll") (command "_.NETLOAD" "dll1.dll") (command "_.NETLOAD" (getfiled "Select dll1.dll file" "\\" "dll" 16))) (if (findfile "dll2.dll") (command "_.NETLOAD" "dll2.dll") (command "_.NETLOAD" (getfiled "Select dll2.dll file" "\\" "dll" 16))) ... (if (findfile "dlln.dll") (command "_.NETLOAD" "dlln.dll") (command "_.NETLOAD" (getfiled "Select dlln.dll file" "\\" "dll" 16))) (if (findfile "mylisps.lsp") (load "mylisps.lsp") (load (getfiled "Select mylisps.lsp file" "\\" "lsp" 16))) (alert "Type \"mylisps\" at command prompt to choose lisp to run from those that are automatically loaded...") (_vl-balance-parenthesis 1 666) (setq *atoms* (atoms-family 1)) (princ) Then you should create mylisps.lsp - its content : (defun c:mylisps ( / fn f l st en str strl lisp ) (setq fn (getfiled "Select \"acaddoc-20XX-xXX.lsp\"" "\\" "lsp" 16)) (setq f (open fn "r")) (while (setq l (read-line f)) (if (and (not (eq (substr l 1 1) ";")) (vl-string-search "(if (findfile " l)) (progn (setq st (vl-string-search "\"" l)) (setq en (vl-string-search "\"" (substr l (+ st 2)))) (setq str (substr l (+ st 2) en)) (setq strl (cons str strl)) ) ) ) (close f) (setq lisp (dos_listbox "LISPS" "Select LISP to run..." strl)) (if lisp (progn (setq fn (findfile lisp)) (if (vl-position (strcase (strcat "C:" (vl-filename-base lisp))) (atoms-family 1)) (eval (read (strcat "(c:" (vl-filename-base lisp) ")"))) (startapp "EXPLORER" fn) ) ) (prompt "\nYou pressed Cancel button...") ) (princ) ) Now to make it all findfile operative, you start AutoCAD and add this folder to Support File Search Path under OPTIONS dialog box and first TAB - Files : for ex. - click add -> browse -> c:\acad support\ After this is done, to explain how do you add new application (lsp, dll)... Till now AutoCAD should correctly find acaddoc.lsp from your SFSP you previously specified (c:\acad support\) and all appplications that are inside acaddoc.lsp should automatically load... So to add now one, just add this line : (if (findfile "lisp-new.lsp") (load "lisp-new.lsp") (load (getfiled "Select lisp-new.lsp file" "\\" "lsp" 16))) or if it's dll (if (findfile "dll-new.dll") (command "_.NETLOAD" "dll-new.dll") (command "_.NETLOAD" (getfiled "Select dll-new.dll file" "\\" "dll" 16))) Make sure that your newly created lisp-new.lsp or dll-new.dll is placed in (c:\acad support\)... That's it - now your new application should be automatically recognized by AutoCAD and new routine could be executed by calling command function name which is placed as (defun c:lisp-new ( / ... ))... When you create new applications always have in mind that the best naming of applications is to actually name it by command with it's executed (lisp-new.lsp - executing command : lisp-new)... This way after you automatically loaded mylisps.lsp and alert message prompts when AutoCAD is launched, you'll have your dialog box started with executing mylisps command after which you'll first point to acaddoc.lsp from first dialog box (lisp will detect all applications that are stored inside adaddoc.lsp - that are automatically loaded) and then DOSLib's pop up will show up with all applications listed in selection box... If name of application doesn't match with automatically loaded SUBR ("C:LISP-NEW") stored in CAD memory - you call it with (atoms-family 1), then selecting that kind of routine will tell AutoCAD to launch "notepad.exe" with supplied adequate lisp-bad.lsp opened, so that you can see with which (defun c:invokename ( / ... )) command name you can start that lisp if lisp application is your object of interest... So you'll then start that application by typing at command prompt "invokename" - wihout quotes... If matching of application name and command name is exact - match is met then when clicked OK from DOSLib's dialog box will tell AutoCAD to automatically launch that lisp with correct command name... So this is how I solved this task without need to dive in programming *.dcl and so on... I only used installed DOSLib for AutoCAD... Edited November 14, 2016 by marko_ribar Quote
BIGAL Posted November 14, 2016 Posted November 14, 2016 The old fashioned way. This is my menu and I have customised toolbars as well. Regarding giving to others its not a problem you can have "Partial menus" these are menus/toolbars that contain your lisps etc they can contain images as well. They are loaded individually by using the command "Menuload". They have the advantage of being version independant and are created just using notepad, plus some cutting and pasting from the CUI. If you want help for each then I would add a extra line to the menu marked "Help" this would open say a word file that could be very extensive and include images about the commands. I have a DOC called "How to use lisp files" its saved on our server in a directory we call "How to manuals" were we all save little hints about all sorts of stuff. The menu can have sub sub menus etc. The menu source code is kept on the server so as each user starts Autocad they get the latest version. All very simple Quote
Roy_043 Posted November 14, 2016 Posted November 14, 2016 If the OP wants to know more about DCL: http://web2.airmail.net/terrycad/Tutorials/MyDialogs.htm Quote
pBe Posted November 14, 2016 Posted November 14, 2016 ...But the challenge is I share the lisps with my colleagues and so you get asked a lot what is the function that calls up a particular lisp... ...Regarding giving to others its not a problem you can have "Partial menus" these are menus/toolbars that contain your lisps etc they can contain images as well. They are loaded individually by using the command "Menuload". They have the advantage of being version independant and are created just using notepad, plus some cutting and pasting from the CUI. .. The menu source code is kept on the server so as each user starts Autocad they get the latest version. All very simple +1 or even Ribbons... Partial Customization Files --> Ribbons --> Panels.. [ Easy to share and simple indeed ] I like that slide thingy, nice Quote
BIGAL Posted November 15, 2016 Posted November 15, 2016 The slide thingy goes way back in time now most would look at palettes, if you know your way around scripts you can make 100+ slides at a time etc in our case most are seperate dwgs of objects in our block library. For anyone interested sample code in mnu [->IDM dwgs] [TRENCH]$I=GGSTDS.IDMTRENCH $I=* [PIPES]$I=GGSTDS.IDMPIPES $I=* [PITS]$I=GGSTDS.IDMPITS $I=* [KERBS]$I=GGSTDS.IDMKERBS $I=* [<-] ***image **KERBS [KERBS] [GGSLD(SD401,B1 KERB)]^C^C(openblk "P:/ACADSTDS/CIVIL STANDARDS/CGG401") [GGSLD(SD402,B2 KERB)]^C^C(openblk "P:/ACADSTDS/CIVIL STANDARDS/CGG402") Quote
Alcapone001 Posted November 15, 2016 Author Posted November 15, 2016 Hey. I found a way that uses Dcl, but I am not sure why it is not working (defun C:test( / id i ok) (setq id (load_dialog "test.DCL")) ;load DCL (if (new_dialog "dcl_test" id) (progn (setq i 1) (repeat 6 (init_image i) ;assign an action to the image_button ;(action_image i) (setq i (1+ I)) ) (action_tile "C1" "(action_command 1)") ;assign an action to the button 1 (action_tile "C2" "(action_command 2)") ;assign an action to the button 2 (action_tile "C3" "(action_command 3)") ;assign an action to the button 3 (action_tile "C4" "(action_command 4)") ;assign an action to the button 4 (action_tile "C5" "(action_command 5)") ;assign an action to the button 5 (action_tile "C6" "(action_command 6)") ;assign an action to the button 6 ;;of course ,you can do it by (repeat) (setq ok (start_dialog)) ) (alert "Can't load the dialoag!") ) (unload_dialog ID) (princ) ) ;;; initializate the image_button. ;;; and assign an action to an image_button (defun init_image (key / k tile) (setq k (itoa key)) (setq tile (strcat "I" k)) ;tile (start_image tile) (fill_image 0 0 (dimx_tile tile) (dimy_tile tile) key ) (end_image) ;fill tile with different color (set_tile tile (strcat "Fun" k)) ;set the text of tile (action_tile tile (strcat "(action_command " k ")")) ;action ) ;;; assign an action to an command_button (defun action_command (key) (cond ((= key 1) (alert "Please enter your command1:") ;;add your code in here ) ((= key 2) (alert "Please enter your command2:") ;;add your code in here ) ((= key 3) (alert "Please enter your command3:") ;;add your code in here ) ((= key 4) (alert "Please enter your command4:") ;;add your code in here ) ((= key 5) (alert "Please enter your command5:") ;;add your code in here ) ((= key 6) (alert "Please enter your command6:") ;;add your code in here ) ) ) //--------------------------------------------------------------------------------------------------------- // Test //--------------------------------------------------------------------------------------------------------- dcl_test : dialog { key = "Title"; label = "Test commands dialog"; spacer; : column { : button { key = "C1"; label = "Command1"; } spacer; : button { key = "C2"; label = "Command2"; } spacer; : button { key = "C3"; label = "Command3"; } spacer; : button { key = "C4"; label = "Command4"; } spacer; : button { key = "C5"; label = "Command5"; } } spacer; ok_only; }//Test I am not sure on how to assign an action that calls my functions Quote
Roy_043 Posted November 16, 2016 Posted November 16, 2016 Maybe this helps: LSP: (defun C:test( / cmd dcl ret) (setq dcl (load_dialog "test.DCL")) ; Load DCL. (if (new_dialog "dcl_test" dcl) (progn (action_tile "C1" "(setq cmd \"C1\") (done_dialog 1)") (action_tile "C2" "(setq cmd \"C2\") (done_dialog 1)") (action_tile "C3" "(setq cmd \"C3\") (done_dialog 1)") (setq ret (start_dialog)) ; If Cancel is pressed ret will be 0. (unload_dialog dcl) ) (alert "Can't load the dialog!") ) (if (= 1 ret) (cond ((= "C1" cmd) (alert "Please enter your Command 1:") ) ((= "C2" cmd) (alert "Please enter your Command 2:") ) ((= "C3" cmd) (alert "Please enter your Command 3:") ) ) ) (princ) ) DCL: dcl_test : dialog { label = "Test commands dialog"; spacer; : button { key = "C1"; label = "Command1"; } spacer; : button { key = "C2"; label = "Command2"; } spacer; : button { key = "C3"; label = "Command3"; } spacer; cancel_button; } Quote
Grrr Posted November 16, 2016 Posted November 16, 2016 I like your suggestion Roy, I've put the DCL into the lsp file for easier use, if you don't mind: [b][color=BLACK]([/color][/b]defun C:test [b][color=FUCHSIA]([/color][/b] / *error* fp fdcl dcl_id ret cmd [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]defun *error* [b][color=NAVY]([/color][/b]m[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and dcl_id [b][color=MAROON]([/color][/b]unload_dialog dcl_id[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and fp [b][color=MAROON]([/color][/b]vl-file-delete fp[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and m [b][color=MAROON]([/color][/b]print m[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ[b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b][color=#8b4513]; defun *error*[/color] [b][color=FUCHSIA]([/color][/b]setq fp [b][color=NAVY]([/color][/b]vl-filename-mktemp [color=#2f4f4f]"tempfile.dcl"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq fdcl [b][color=NAVY]([/color][/b]open fp [color=#2f4f4f]"w"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]write-line [color=#2f4f4f]" dcl_test : dialog { label = \"[/color]Test commands dialog\[color=#2f4f4f]"; spacer; : button { key = \"[/color]C1\[color=#2f4f4f]"; label = \"[/color]Command1\[color=#2f4f4f]"; } spacer; : button { key = \"[/color]C2\[color=#2f4f4f]"; label = \"[/color]Command2\[color=#2f4f4f]"; } spacer; : button { key = \"[/color]C3\[color=#2f4f4f]"; label = \"[/color]Command3\[color=#2f4f4f]"; } spacer; cancel_button; } "[/color] fdcl [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]close fdcl[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq dcl_id [b][color=NAVY]([/color][/b]load_dialog fp[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]new_dialog [color=#2f4f4f]"dcl_test"[/color] dcl_id[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]action_tile [color=#2f4f4f]"C1"[/color] [color=#2f4f4f]"[b][color=GREEN]([/color][/b]setq cmd \"[/color]C1\[color=#2f4f4f]"[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]done_dialog 1[b][color=GREEN])[/color][/b]"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]action_tile [color=#2f4f4f]"C2"[/color] [color=#2f4f4f]"[b][color=GREEN]([/color][/b]setq cmd \"[/color]C2\[color=#2f4f4f]"[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]done_dialog 1[b][color=GREEN])[/color][/b]"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]action_tile [color=#2f4f4f]"C3"[/color] [color=#2f4f4f]"[b][color=GREEN]([/color][/b]setq cmd \"[/color]C3\[color=#2f4f4f]"[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]done_dialog 1[b][color=GREEN])[/color][/b]"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ret [b][color=GREEN]([/color][/b]start_dialog[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513]; If Cancel is pressed ret will be 0.[/color] [b][color=MAROON]([/color][/b]unload_dialog dcl_id[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]and fp [b][color=GREEN]([/color][/b]vl-file-delete fp[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513]; unload and delete the tempfile[/color] [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]alert [color=#2f4f4f]"Can't load the dialog!"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]and fp [b][color=GREEN]([/color][/b]vl-file-delete fp[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]= 1 ret[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]cond [b][color=MAROON]([/color][/b] [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"C1"[/color] cmd[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]alert [color=#2f4f4f]"Please enter your Command 1:"[/color][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b] [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"C2"[/color] cmd[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]alert [color=#2f4f4f]"Please enter your Command 2:"[/color][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b] [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"C3"[/color] cmd[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]alert [color=#2f4f4f]"Please enter your Command 3:"[/color][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] Quote
Grrr Posted November 16, 2016 Posted November 16, 2016 I was too excited about Roy's suggestion, so I wrote a subfunciton out of it: [b][color=BLACK]([/color][/b]defun ButtonPromptBOX [b][color=FUCHSIA]([/color][/b] dlglabel StrCommandsLst / *error* fp fdcl dcl_id dlgRtn rtn [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]defun *error* [b][color=NAVY]([/color][/b]m[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and dcl_id [b][color=MAROON]([/color][/b]unload_dialog dcl_id[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and fp [b][color=MAROON]([/color][/b]vl-file-delete fp[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and m [b][color=MAROON]([/color][/b]print m[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ[b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b][color=#8b4513]; defun *error*[/color] [b][color=FUCHSIA]([/color][/b]setq fp [b][color=NAVY]([/color][/b]vl-filename-mktemp [color=#2f4f4f]"tempfile.dcl"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq fdcl [b][color=NAVY]([/color][/b]open fp [color=#2f4f4f]"w"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]write-line [b][color=NAVY]([/color][/b]strcat [color=#2f4f4f]" dcl_test : dialog { label = \"[/color][color=#2f4f4f]" dlglabel "[/color]\[color=#2f4f4f]"; "[/color] [b][color=MAROON]([/color][/b]apply 'strcat [b][color=GREEN]([/color][/b]mapcar '[b][color=BLUE]([/color][/b]lambda [b][color=RED]([/color][/b]x[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]strcat [color=#2f4f4f]" spacer; : button { key = \"[/color][color=#2f4f4f]" [b][color=PURPLE]([/color][/b]car x[b][color=PURPLE])[/color][/b] "[/color]\[color=#2f4f4f]"; label = \"[/color][color=#2f4f4f]" [b][color=PURPLE]([/color][/b]cdr x[b][color=PURPLE])[/color][/b] "[/color]\[color=#2f4f4f]"; } "[/color] [b][color=RED])[/color][/b] [b][color=BLUE])[/color][/b] StrCommandsLst [b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [color=#2f4f4f]" spacer; cancel_button; } "[/color] [b][color=NAVY])[/color][/b][color=#8b4513]; strcat[/color] fdcl [b][color=FUCHSIA])[/color][/b][color=#8b4513]; write-line[/color] [b][color=FUCHSIA]([/color][/b]close fdcl[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq dcl_id [b][color=NAVY]([/color][/b]load_dialog fp[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]new_dialog [color=#2f4f4f]"dcl_test"[/color] dcl_id[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]foreach x [b][color=GREEN]([/color][/b]mapcar 'car StrCommandsLst[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]action_tile x [b][color=BLUE]([/color][/b]strcat [color=#2f4f4f]"[b][color=RED]([/color][/b]setq rtn \"[/color][color=#2f4f4f]" x "[/color]\[color=#2f4f4f]"[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]done_dialog 1[b][color=RED])[/color][/b]"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq dlgRtn [b][color=GREEN]([/color][/b]start_dialog[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513]; If Cancel is pressed dlgRtn will be 0.[/color] [b][color=MAROON]([/color][/b]unload_dialog dcl_id[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]and fp [b][color=GREEN]([/color][/b]vl-file-delete fp[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513]; unload and delete the tempfile[/color] [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]alert [color=#2f4f4f]"Can't load the dialog!"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]and fp [b][color=GREEN]([/color][/b]vl-file-delete fp[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]= 1 dlgRtn[b][color=NAVY])[/color][/b] rtn[b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b][color=#8b4513];| defun ButtonPromptBOX |; [b][color=BLACK]([/color][/b]or vlax-get-acad-object [b][color=FUCHSIA]([/color][/b]vl-load-com[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]princ[b][color=BLACK])[/color][/b][/color] Usage: [color=#8b4513]; Test function of [color=#2f4f4f]"ButtonPromptBOX"[/color][/color] [b][color=BLACK]([/color][/b]defun C:test [b][color=FUCHSIA]([/color][/b] / StrCommandsLst r [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq StrCommandsLst [color=#8b4513]; assoc List of [b][color=NAVY]([/color][/b] <key> . <label> [b][color=NAVY])[/color][/b][/color] [b][color=NAVY]([/color][/b]list [b][color=MAROON]([/color][/b]cons [color=#2f4f4f]"key1"[/color] [color=#2f4f4f]"Command1"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons [color=#2f4f4f]"key2"[/color] [color=#2f4f4f]"Command2"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons [color=#2f4f4f]"key3"[/color] [color=#2f4f4f]"Command3"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons [color=#2f4f4f]"key4"[/color] [color=#2f4f4f]"Command4"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons [color=#2f4f4f]"key5"[/color] [color=#2f4f4f]"Command5"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons [color=#2f4f4f]"key6"[/color] [color=#2f4f4f]"Command6"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons [color=#2f4f4f]"key7"[/color] [color=#2f4f4f]"Command7"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons [color=#2f4f4f]"key8"[/color] [color=#2f4f4f]"Command8"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons [color=#2f4f4f]"key9"[/color] [color=#2f4f4f]"Command9"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cons [color=#2f4f4f]"key10"[/color] [color=#2f4f4f]"Command10"[/color][b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]setq r [b][color=MAROON]([/color][/b]ButtonPromptBOX [color=#2f4f4f]"Prompt for a command dialog"[/color] StrCommandsLst[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]alert [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"Please enter your "[/color] [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc r StrCommandsLst[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [color=#2f4f4f]""[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b][color=#8b4513]; defun C:test[/color] And sorry for the double post. Quote
BIGAL Posted November 17, 2016 Posted November 17, 2016 You can have a sub function that creates as many rows of dcl as you need wether it be 1 line or 10. Just start with a simple list (setq lst (list "Item 1" "Item2")) this would be a 2 line dcl example. This is an older post about the same thing http://www.cadtutor.net/forum/showthread.php?92520-Multi-line-DCL-auto-code-generator&highlight=multi There is a newer post will try to find it pretty sure David Bethel posted a complete routine. Quote
pBe Posted November 17, 2016 Posted November 17, 2016 (defun C:test( / cmd dcl ret) (setq dcl (load_dialog "test.DCL")) ; Load DCL. (if (new_dialog "dcl_test" dcl) (progn [color="blue"] (action_tile "C1" "(done_dialog 1)") (action_tile "C2" "(done_dialog 2)") (action_tile "C3" "(done_dialog 3)")[/color] (setq ret (start_dialog)) ; If Cancel is pressed ret will be 0. (unload_dialog dcl) ) (alert "Can't load the dialog!") ) (cond [color="blue"] ( (zerop ret)(alert "\nFunction CANCELLED by user")) ( (eval (cadr (assoc ret '( ( 1 (_func1 "Hey Dude")) ( 2 (_func2 "What?")) ( 3 (_func3 "Seriously")) ) ) ) ) )[/color] ) (princ) ) [color="blue"](defun _func1 (m) (alert (strcat m " The Earth is FLAT"))) (defun _func2 (m) (alert (strcat m " No its NOT, The Earth is round"))) (defun _func3 (m) (alert (strcat m " Its actually a bumpy spheroid")))[/color] Quote
Alcapone001 Posted November 17, 2016 Author Posted November 17, 2016 I like your suggestion Roy,I've put the DCL into the lsp file for easier use, if you don't mind: [b][color=BLACK]([/color][/b]defun C:test [b][color=FUCHSIA]([/color][/b] / *error* fp fdcl dcl_id ret cmd [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]defun *error* [b][color=NAVY]([/color][/b]m[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and dcl_id [b][color=MAROON]([/color][/b]unload_dialog dcl_id[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and fp [b][color=MAROON]([/color][/b]vl-file-delete fp[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]and m [b][color=MAROON]([/color][/b]print m[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ[b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b][color=#8b4513]; defun *error*[/color] [b][color=FUCHSIA]([/color][/b]setq fp [b][color=NAVY]([/color][/b]vl-filename-mktemp [color=#2f4f4f]"tempfile.dcl"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq fdcl [b][color=NAVY]([/color][/b]open fp [color=#2f4f4f]"w"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]write-line [color=#2f4f4f]" dcl_test : dialog { label = \"[/color]Test commands dialog\[color=#2f4f4f]"; spacer; : button { key = \"[/color]C1\[color=#2f4f4f]"; label = \"[/color]Command1\[color=#2f4f4f]"; } spacer; : button { key = \"[/color]C2\[color=#2f4f4f]"; label = \"[/color]Command2\[color=#2f4f4f]"; } spacer; : button { key = \"[/color]C3\[color=#2f4f4f]"; label = \"[/color]Command3\[color=#2f4f4f]"; } spacer; cancel_button; } "[/color] fdcl [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]close fdcl[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq dcl_id [b][color=NAVY]([/color][/b]load_dialog fp[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]new_dialog [color=#2f4f4f]"dcl_test"[/color] dcl_id[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]action_tile [color=#2f4f4f]"C1"[/color] [color=#2f4f4f]"[b][color=GREEN]([/color][/b]setq cmd \"[/color]C1\[color=#2f4f4f]"[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]done_dialog 1[b][color=GREEN])[/color][/b]"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]action_tile [color=#2f4f4f]"C2"[/color] [color=#2f4f4f]"[b][color=GREEN]([/color][/b]setq cmd \"[/color]C2\[color=#2f4f4f]"[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]done_dialog 1[b][color=GREEN])[/color][/b]"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]action_tile [color=#2f4f4f]"C3"[/color] [color=#2f4f4f]"[b][color=GREEN]([/color][/b]setq cmd \"[/color]C3\[color=#2f4f4f]"[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]done_dialog 1[b][color=GREEN])[/color][/b]"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ret [b][color=GREEN]([/color][/b]start_dialog[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513]; If Cancel is pressed ret will be 0.[/color] [b][color=MAROON]([/color][/b]unload_dialog dcl_id[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]and fp [b][color=GREEN]([/color][/b]vl-file-delete fp[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513]; unload and delete the tempfile[/color] [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]alert [color=#2f4f4f]"Can't load the dialog!"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]and fp [b][color=GREEN]([/color][/b]vl-file-delete fp[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]= 1 ret[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]cond [b][color=MAROON]([/color][/b] [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"C1"[/color] cmd[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]alert [color=#2f4f4f]"Please enter your Command 1:"[/color][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b] [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"C2"[/color] cmd[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]alert [color=#2f4f4f]"Please enter your Command 2:"[/color][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b] [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"C3"[/color] cmd[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]alert [color=#2f4f4f]"Please enter your Command 3:"[/color][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b] Wow..! This is what I have been looking for. But why is clicking the button not automatically picking the lisp associated with the button..... For instance clicking on button 1 should activate the addition lisp (defun C:test ( / *error* fp fdcl dcl_id ret cmd ) (defun *error* (m) (and dcl_id (unload_dialog dcl_id)) (and fp (vl-file-delete fp)) (and m (print m)) (princ) ); defun *error* (setq fp (vl-filename-mktemp "tempfile.dcl")) (setq fdcl (open fp "w")) (write-line " dcl_test : dialog { label = \"Test commands dialog\"; spacer; : button { key = \"C1\"; label = \"Command1\"; } spacer; : button { key = \"C2\"; label = \"Command2\"; } spacer; : button { key = \"C3\"; label = \"Command3\"; } spacer; cancel_button; } " fdcl ) (close fdcl) (setq dcl_id (load_dialog fp)) (if (new_dialog "dcl_test" dcl_id) (progn (action_tile "C1" "(setq cmd \"C1\") (done_dialog 1)") (action_tile "C2" "(setq cmd \"C2\") (done_dialog 1)") (action_tile "C3" "(setq cmd \"C3\") (done_dialog 1)") (setq ret (start_dialog)) ; If Cancel is pressed ret will be 0. (unload_dialog dcl_id) (and fp (vl-file-delete fp)) ; unload and delete the tempfile ) (progn (alert "Can't load the dialog!") (and fp (vl-file-delete fp))) ) (if (= 1 ret) (cond ( (= "C1" cmd) (alert "ADDJ:") ) ( (= "C2" cmd) (alert "CJ:") ) ( (= "C3" cmd) (alert "Please enter your Command 3:") ) ) ) (princ) ) (defun c:CJ (/ p x y z ptcoord textloc) (while (setq p (getpoint " Pick Point: ")) (setq textloc (getpoint " Pick Label Location: ")) (setq x (rtos (car p))) (setq y (rtos (cadr p))) (setq x (strcat "E " x)) (setq y (strcat "N " y)) (command "_LEADER" p textloc "" x y "") ; ) ) ****************************************************************************************************** ; To add a given value to numbers and also to add decimal places (defun c:ADDJ ( / ss) (vl-load-com) (if (and (setq ss (ssget (list (cons 0 "*text")))) (setq amt (getreal "\nPlease type the amount you would like to add: "))) (progn (mapcar '(lambda (z) (vla-put-textstring z (rtos (+ (atof (vla-get-textstring z)) amt) 2 ))) (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))) ) ) (princ) ) Quote
Grrr Posted November 17, 2016 Posted November 17, 2016 You can have a sub function that creates as many rows of dcl as you need wether it be 1 line or 10. Just start with a simple list (setq lst (list "Item 1" "Item2")) this would be a 2 line dcl example. This is an older post about the same thing http://www.cadtutor.net/forum/showthread.php?92520-Multi-line-DCL-auto-code-generator&highlight=multi There is a newer post will try to find it pretty sure David Bethel posted a complete routine. This is awesome, BIGAL. Either I didn't knew about it, or I may have seen it before and completely forgot about it. I will try to revise/analyse it. Wow..! This is what I have been looking for. But why is clicking the button not automatically picking the lisp associated with the button..... For instance clicking on button 1 should activate the addition lisp Try changing this: (if (= 1 ret) (cond ( (= "C1" cmd) (alert "ADDJ:") ) ( (= "C2" cmd) (alert "CJ:") ) ( (= "C3" cmd) (alert "Please enter your Command 3:") ) ) ) Into this: (if (= 1 ret) (cond ( (= "C1" cmd) (if C:ADDJ (C:ADDJ) (alert "\nFunction \"C:ADDJ\" not loaded, or not defined!")) ) ( (= "C2" cmd) (if C:CJ (C:CJ) (alert "\nFunction \"C:CJ\" not loaded, or not defined!")) ) ( (= "C3" cmd) (if C:test (C:test) (alert "\nFunction \"C:test\" not loaded, or not defined!")) ) ) ) If you recieve the alert error, it simply means that you don't have such command ADDJ / CJ / test. And its not important to define the functions in the same file, they can be loaded from separate .lsp file(s) as usual: (defun c:CJ (/ p x y z ptcoord textloc) ... ) (defun c:ADDJ ( / ss) ... ) Quote
Alcapone001 Posted November 17, 2016 Author Posted November 17, 2016 Great. Works. Thanks a lot everyone. . . . This forum is really useful......... :thumbsup: Quote
BIGAL Posted November 18, 2016 Posted November 18, 2016 For Grr,I apologise but pretty sure code basic came from David Bethel. ; run this (if (not AH:getkeys)(load "getvals2")) (AH:getkeys (list "Line 1" 5 4 "line 2" 2 4 "line 3" 8 7)) (alert (strcat "1st line val is " key1 "\n\n2nd line val is " key2 "\n\n3rd Line val is " key3)) ; multi line dcl ; with help from the guys at Cadtutor ; sample code a 3 line example ; (if (not AH:getkeys)(load "getvals2")) ;(AH:getkeys (list "Line 1" 5 4 "line 2" 2 4 "line 3" 8 7)) (princ "Getvals2 loaded") (defun AH:getkeys (INFO / fo fname newlst num x y klist) ; you can hard code a directory if you like for dcl file (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w")) ;(setq fo (open (setq fname "c:\\acadtemp\\getkeys.dcl") "w")) (write-line "ddgetkey : dialog {" fo) (write-line " : column {" fo) (setq num (/ (length info) 3)) (setq x 1) (repeat num (setq klist (cons (strcat "key" (rtos x 2 0)) klist)) (setq x (+ 1 x)) ) (setq x 1) (setq y 1) (repeat num (write-line ": edit_box {" fo) (write-line (strcat " key = " (chr 34) (strcat "key" (rtos y 2 0)) (chr 34) ";") fo) (write-line (strcat " label = " (chr 34) (nth (- x 1) info) (chr 34) ";" ) fo) (write-line (strcat " edit_width = " (rtos (nth x info) 2 0) ";" ) fo) (write-line (strcat " edit_limit = " (rtos (nth (+ x 1) info) 2 0) ";" ) fo) (write-line " is_enabled = true;" fo) (write-line " }" fo) (write-line "spacer_1 ;" fo) (setq x (+ x 3)) (setq y (+ y 1)) ) (write-line " }" fo) (write-line "ok_only;}" fo) (close fo) (setq x 1) (setq outlst '()) (setq dcl_id (load_dialog fname)) (if (not (new_dialog "ddgetkey" dcl_id)) (exit)) (foreach k klist (action_tile k (strcat "(setq " k " (get_tile \"" k "\"))")) ) (action_tile "accept" "(done_dialog 1)") (action_tile "cancel" "(done_dialog 0)") (setq action (start_dialog)) (unload_dialog dcl_id) ) ; defun Quote
Grrr Posted November 18, 2016 Posted November 18, 2016 For Grr,I apologise but pretty sure code basic came from David Bethel. I don't question this, just liked the idea of "list - prompt with dcl - maketemp dcl file" wiring/combo. I even have "favourite" subfunction (LM:Listbox) which is the same technique, although since I started with LISP It took me long time to figure out how to properly use it, and even more to "create" something similair. 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.