Yes, the link I provided and the two code versions I wrote use the same ssget method to select ALL instances of the given block name which in your case is called "DWGSTATE" both in Model & all Layouts matching what the Express Tools Gatte function does.
Cadtutor code:
(setq ss (ssget "X" '((0 . "INSERT")(2 . "NP TITLEBLOCK INFO")))) ; block name is "NP TITLEBLOCK INFO"
My Code #1:
(setq blknam "DWGSTATE" ; block name
tagnam "STATE" ; attribute tag name
)
(if (setq ss (ssget "_X" (list '(0 . "INSERT")(cons 2 blknam))))
My Code #2: which defines own gatte function with three arguments: block name, tag name & new attribute value:
; gatte similar to c:gatte function but with following arguments:
; blk-arg = block name
; tag-arg = attribute tag name
; val-arg = attribute value
(defun gatte (blk-arg tag-arg val-arg / ent n ss sslen)
(if (setq ss(ssget "_X" (list '(0 . "INSERT")(cons 2 blk-arg))))
; ....
; then towards the end of code call the new gatte function:
(gatte "DWGSTATE" "STATE" keyword)
As for your new modified code, what you could do is to actually define a default global keyword variable like this:
(or **keyword** (setq **keyword** "RELEASED")) ; setup default
This assume no other code is using **keyword**
Then the following lines of code will respond to the initget
If an enter is press to accept the default **keyword** then keyword will be set equal to the global variable
Else the global variable will be reset using the new selected keyword value:
(initget "PRELIMINARY RELEASED")
(setq keyword (getkword (strcat "Specify keyword [PRELIMINARY/RELEASED] <" **keyword** ">: ")))
(if (not keyword)
(setq keyword **keyword**) ; hit enter to accept default
(setq **keyword** keyword) ; reset default to new entry
) ; if
Then lastly run the vla command but using the version I provided which completes itself without further interaction:
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "gatte B DWGSTATE STATE " keyword "\rYes\r"))
Yes, there are more lines of code...but all automated if you want to run RELEASESTATE again in the same drawing.
; RELEASESTATE
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pass-arguments-to-quot-c-quot-commands/m-p/12781153#M466205
(defun c:RELEASESTATE (/ keyword)
(vl-load-com)
(or **keyword** (setq **keyword** "RELEASED")) ; setup default
(initget "PRELIMINARY RELEASED")
(setq keyword (getkword (strcat "Specify keyword [PRELIMINARY/RELEASED] <" **keyword** ">: ")))
(if (not keyword)
(setq keyword **keyword**) ; hit enter to accept default
(setq **keyword** keyword) ; reset default to new entry
) ; if
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "gatte B DWGSTATE STATE " keyword "\rYes\r"))
(princ) ; clean exit
) ; defun