dwatters24 Posted July 3, 2018 Share Posted July 3, 2018 for some reason initget and getkword are not playing nice together in this lisp i am working on. the first (initget 1 "main titleblock") and getkword ("modify layers for main or titleblock viewports: (main/titleblock) " ) works great and brings up the prompt for "freeze or thaw viewport layers : (f/t) ") this is where things start acting up, the lisp doesnt want to recognize any values for the second getkword. Ive tried rearanging code changing variable names, cant get anywhere can anyone read through this and catch what i am missing? Thanks! (vl-load-com) (initget 1 "main titleblock") (setq layers "" dsc1 '("testlayer" "testlayer2") ;layers to freeze in main viewport dsc2 '("testlayer" "testlayer2") ;layers to exclude from freezing in titleblock viewport prmt1 (getkword "Modify Layers For Main or Titleblock Viewports: (Main/Titleblock) ") prmt2 (getkword "Freeze or Thaw Viewport Layers: (F/T) ") str1 (strcat "Lisp is Complete : All Unwanted Layers have been Frozen in" viewport "viewport") str2 (strcat "Lisp is Complete : All Unwanted Layers have been Thawed in" viewport "viewport") ) (cond ((= prmt1 (setq viewport "main")) (initget 1 "f t") (cond ((= prmt2 "f") (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (member (Strcase (vla-get-description layer)) dsc1) (setq layers (strcat (vla-get-name layer) "," layers)) ) ) (foreach lay (layoutlist) (if (and layers* (setq ss (ssget "X" (list '(0 . "VIEWPORT")'(8 . "viewport-main") (cons 410 lay)))) ) (progn (setvar 'ctab lay) (repeat (setq i (sslength ss)) (setq ent (entget (setq e (ssname ss (setq i (1- i)))))) (command "_.VPLAYER" "_Freeze" layers "_S" e "" "") ) ) ) ) (alert str1) ) ((= prmt2 "t") (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (member (Strcase (vla-get-description layer)) ~dsc2) (setq layers (strcat (vla-get-name layer) "," layers)) ) ) (foreach lay (layoutlist) (if (and layers* (setq ss (ssget "X" (list '(0 . "VIEWPORT")'(8 . "viewport-main") (cons 410 lay)))) ) (progn (setvar 'ctab lay) (repeat (setq i (sslength ss)) (setq ent (entget (setq e (ssname ss (setq i (1- i)))))) (command "_.VPLAYER" "_THAW" layers "_S" e "" "") ) ) ) ) (alert str2) ) ) ) ((= prmt1 (setq viewport "titleblock")) (initget 1 "f t") (cond ((= prmt2 "f") (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (member (Strcase (vla-get-description layer)) dsc1) (setq layers (strcat (vla-get-name layer) "," layers)) ) ) (foreach lay (layoutlist) (if (and layers* (setq ss (ssget "X" (list '(0 . "VIEWPORT")'(8 . "viewport-main") (cons 410 lay)))) ) (progn (setvar 'ctab lay) (repeat (setq i (sslength ss)) (setq ent (entget (setq e (ssname ss (setq i (1- i)))))) (command "_.VPLAYER" "_Freeze" layers "_S" e "" "") ) ) ) ) (alert str1) ) ((= prmt2 "t") (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (member (Strcase (vla-get-description layer)) ~dsc2) (setq layers (strcat (vla-get-name layer) "," layers)) ) ) (foreach lay (layoutlist) (if (and layers* (setq ss (ssget "X" (list '(0 . "VIEWPORT")'(8 . "viewport-titleblock") (cons 410 lay)))) ) (progn (setvar 'ctab lay) (repeat (setq i (sslength ss)) (setq ent (entget (setq e (ssname ss (setq i (1- i)))))) (command "_.VPLAYER" "_THAW" layers "_S" e "" "") ) ) ) ) (alert str2) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
Jef! Posted July 9, 2018 Share Posted July 9, 2018 Hi and welcome to the forum. Some thoughts here 1- Initget/getkeyword can be very buggy. I never use it, literally. If I try multiple calls in the command line it just fails on my side, as I get the same behavior as the op in this adesk thread link! 2- If I copy/paste the example from Adesk online help, it doesn't work 3- In their examples, Adesk put choices in between (). It might be how it was originally created, as I found old examples using that approach like Ron Leigh's. If you use square brackets instead of parenthesis in your getkeyword statement it enables to choose by mouse clicking the answer as well. Still it has the same bug. If you wish to continue in that direction, that point that is specifically for you 4- Initget establishes keywords for use by the next user-input function call. Every getkeyword needs to be preceded by an initget call. You have an initget at the beginning, followed by 2 getkeywords in the setq section. Moreover you have more initgets (without getkeywords) in the conditional. So the approach would be initget just before each getkeyword. After that, use if / conditional statements to act depending on the content of the variables in which you stored the result of the getkeyword. (no initget/getkeywords inside conditionnal statements) (defun c:test ( / direc kword colr ) (initget "Left Right") (setq direc (getkword "\nEnter direction [Left/Right]: ")) (initget "Main Titleblock") (setq kword (getkword "\nModify for [Main/Titleblock]: ")) (initget "Yellow Blue") (setq colr (getkword "\nPick one [Yellow/Blue]: ")) (if direc (princ (strcat "\nyou chose " direc)) (princ "direc is nil") ) (if kword (princ (strcat "\nyou chose " kword)) (princ "kword is nil") ) (if colr (princ (strcat "\nyou chose " colr)) (princ "colr is nil") ) (princ) ) As other side notes, in your first condition you use (= prmt1 (setq viewport "main")) and (= prmt1 (setq viewport "titleblock"))... the viewport variable seems useless, as it is not used. Look how your 2nd conditionnal is done (= prmt2 "f") If you need it, the viewport variable is a duplicate of prmt1. Just use prmt1. Just bare in mind that the keywords will have the 1rst letter capitalized, so they must be the same in the initget. Also don'T forget to take that into consideration when looking at the results with your conditional, ie (= "yellow" (strcase colr t)). I found some typos in your code too, dsc2 vs ~dsc2, layers* vs layers... Seems like you are on the right track. Good luck! Quote Link to comment Share on other sites More sharing options...
dwatters24 Posted July 9, 2018 Author Share Posted July 9, 2018 (vl-load-com) (initget 1 "Main Titleblock") (setq layers "" dsc1 '("testlayer" "testlayer2") ;layers to freeze in main viewport dsc2 '("testlayer" "testlayer2") ;layers to exclude from freezing in titleblock viewport prmt1 (getkword "Modify Layers For Main or Titleblock Viewports: (Main/Titleblock) ") ) (cond ((= prmt1 (setq viewport "Main")) (initget 1 "freeze thaw") (setq prmt2 (getkword "Freeze or Thaw: ") str1 (strcat "Lisp is Complete : All Unwanted Layers have been Frozen in " viewport " viewport") str2 (strcat "Lisp is Complete : All Unwanted Layers have been Thawed in " viewport " viewport") ) (cond ((= prmt2 "freeze") (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (member (Strcase (vla-get-description layer)) dsc1) (setq layers (strcat (vla-get-name layer) "," layers)) ) ) (foreach lay (layoutlist) (if (and layers* (setq ss (ssget "X" (list '(0 . "VIEWPORT")'(8 . "viewport-main") (cons 410 lay)))) ) (progn (setvar 'ctab lay) (repeat (setq i (sslength ss)) (setq ent (entget (setq e (ssname ss (setq i (1- i)))))) (command "_.VPLAYER" "_Freeze" layers "_S" e "" "") ) ) ) ) (alert str1) ) ((= prmt2 "thaw") (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (member (Strcase (vla-get-description layer)) ~dsc1) (setq layers (strcat (vla-get-name layer) "," layers)) ) ) (foreach lay (layoutlist) (if (and layers* (setq ss (ssget "X" (list '(0 . "VIEWPORT")'(8 . "viewport-main") (cons 410 lay)))) ) (progn (setvar 'ctab lay) (repeat (setq i (sslength ss)) (setq ent (entget (setq e (ssname ss (setq i (1- i)))))) (command "_.VPLAYER" "_Thaw" layers "_S" e "" "") ) ) ) ) (alert str2) ) )) ((= prmt1 (setq viewport "Titleblock")) (initget 1 "freeze thaw") (setq prmt2 (getkword "Freeze or Thaw: ") str1 (strcat "Lisp is Complete : All Unwanted Layers have been Frozen in " viewport " viewport") str2 (strcat "Lisp is Complete : All Unwanted Layers have been Thawed in " viewport " viewport") ) (cond ((= prmt2 "freeze") (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (member (Strcase (vla-get-description layer)) dsc1) (setq layers (strcat (vla-get-name layer) "," layers)) ) ) (foreach lay (layoutlist) (if (and layers* (setq ss (ssget "X" (list '(0 . "VIEWPORT")'(8 . "viewport-titleblock") (cons 410 lay)))) ) (progn (setvar 'ctab lay) (repeat (setq i (sslength ss)) (setq ent (entget (setq e (ssname ss (setq i (1- i)))))) (command "_.VPLAYER" "_Freeze" layers "_S" e "" "") ) ) ) ) (alert str1) ) ((= prmt2 "thaw") (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (member (Strcase (vla-get-description layer)) ~dsc1) (setq layers (strcat (vla-get-name layer) "," layers)) ) ) (foreach lay (layoutlist) (if (and layers* (setq ss (ssget "X" (list '(0 . "VIEWPORT")'(8 . "viewport-titleblock") (cons 410 lay)))) ) (progn (setvar 'ctab lay) (repeat (setq i (sslength ss)) (setq ent (entget (setq e (ssname ss (setq i (1- i)))))) (command "_.VPLAYER" "_Thaw" layers "_S" e "" "") ) ) ) ) (alert str2) ) ) )) ) this is what i ended up doing to get it to work, there's probably a cleaner way of doing it but i'll probably end up re-writing it in C# to work with some other stuff i am doing so it works for me til then. the viewport variable was simply so i didnt have to have more response variables, it's pulling viewport variable based off the answer to the first getkword, then plugging it in the response so if you select main it will return "layers in main are vpfrozen" or if you select titleblock it will return "layers in titeblock are vpfrozen" or whatever i had it set to. i probably could have taken this a step further and done the same with freeze/thaw Thank you for the input! i was really trying to only call getkword and initget twice and reuse them as variables to keep the code cleaner but it appears lisps don't like that Quote Link to comment Share on other sites More sharing options...
Jef! Posted July 9, 2018 Share Posted July 9, 2018 the viewport variable was simply so i didnt have to have more response variables, it's pulling viewport variable based off the answer to the first getkword, then plugging it in the response so if you select main it will return "layers in main are vpfrozen" or if you select titleblock it will return "layers in titeblock are vpfrozen" or whatever i had it set to. i probably could have taken this a step further and done the same with freeze/thaw It is quite the opposite. You say you want to minimize variables. instead of (cond ((= prmt1 (setq viewport "Main")) (initget 1 "freeze thaw") (setq prmt2 (getkword "Freeze or Thaw: ") str1 (strcat "Lisp is Complete : All Unwanted Layers have been Frozen in " viewport " viewport") str2 (strcat "Lisp is Complete : All Unwanted Layers have been Thawed in " viewport " viewport") yadayada ...don't create the viewport variable and use prmt1, like that: (cond ((= prmt1 "Main") (initget 1 "freeze thaw") (setq prmt2 (getkword "Freeze or Thaw: ") str1 (strcat "Lisp is Complete : All Unwanted Layers have been Frozen in " prmt1 " viewport") str2 (strcat "Lisp is Complete : All Unwanted Layers have been Thawed in " prmt1 " viewport") Thank you for the input! i was really trying to only call getkword and initget twice and reuse them as variables to keep the code cleaner but it appears lisps don't like thatYou are welcome. Maybe you tried by putting the initget "inside" the setq? this is what i ended up doing to get it to work(initget 1 "freeze thaw") (setq prmt2 (getkword "Freeze or Thaw: ") ..and it works on your side without capital letters on initget?.... on 2015 it is not working. Try beginning with that (and remove the 2 other initgets from conds) (initget 1 "Main Titleblock") (setq layers "" dsc1 '("testlayer" "testlayer2") ;layers to freeze in main viewport dsc2 '("testlayer" "testlayer2") ;layers to exclude from freezing in titleblock viewport prmt1 (getkword "Modify Layers For Main or Titleblock Viewports: [Main/Titleblock] ") ) (initget 1 "Freeze Thaw") (setq prmt2 (getkword "Freeze or Thaw: [Freeze/Thaw] ")) and you will be in business! Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 10, 2018 Share Posted July 10, 2018 I took the different approach and used radio buttons dcl, as you can only pick 1 option. Example is at home. Also this (SETQ reply (ACET-UI-MESSAGE "Yes for Thaw No for freeze" "Please choose" (+ Acet:YESNOCANCEL Acet:ICONWARNING) ) ) ;; Yes = 6 ;; No = 7 ;; Cancel = 2 (IF (= reply 6) (ALERT "Yep")) (if (= reply 7) (ALERT "Nope")) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted July 11, 2018 Share Posted July 11, 2018 ;;;------------------------------------------------------------------- ;;; ;; This function is freeware courtesy of the author's of "Inside AutoLisp" ;; for rel. 10 published by New Riders Publications. This credit must ;; accompany all copies of this function. ;; ;;* UKWORD User key word. DEF, if any, must match one of the KWD strings ;;* BIT (1 for no null, 0 for none) and KWD key word ("" for none) are same as ;;* for INITGET. MSG is the prompt string, to which a default string is added ;;* as (nil or "" for none), and a : is added. ;;* [color="darkred"]([/color][color="blue"]defun[/color] [b]UKWORD[/b] [color="darkred"]([/color]bit kwd msg def [color="blue"]/[/color] inp[color="darkred"])[/color] ([color="blue"]if[/color] [color="darkred"]([/color][color="blue"]and[/color] def [color="darkred"]([/color][color="blue"]/=[/color] def [color="purple"]""[/color][color="darkred"]))[/color] [color="darkred"]([/color][color="blue"]setq[/color] msg [color="darkred"]([/color][color="blue"]strcat[/color][color="purple"] "\n"[/color] msg [color="purple"]" <" [/color]def [color="purple"]"> : "[/color]) bit [color="darkred"]([/color][color="blue"]*[/color] [color="green"]2[/color] [color="darkred"]([/color][color="blue"]fix[/color] [color="darkred"][color="darkred"]([/color][/color][color="blue"]/ [/color]bit [color="green"]2[/color][color="darkred"])))[/color] [color="darkred"] ) [/color] [color="darkred"]) [/color] [color="darkred"]([/color][color="blue"][b]initget[/b][/color] bit kwd[color="darkred"])[/color] [color="darkred"]([/color][color="blue"]setq[/color] inp [color="darkred"]([/color][color="blue"]getkword[/color] msg[color="darkred"]))[/color] [color="darkred"]([/color][color="blue"]if [/color]inp inp def[color="darkred"])[/color] [color="darkred"])[/color] Quote Link to comment Share on other sites More sharing options...
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.