Emmanuel Delay Posted November 10, 2021 Posted November 10, 2021 (edited) Is there a way to pre fill in a part of the value of getstring? (setq new_text (getstring_prefilled "\nNew value: " "new_value_" )) So it already fills in "new_value_", and now I can add a number, "new_value_123", but just as well I can remove that "new_value_"... (is this question clear?) [code] ;; change attribute (defun c:attch ( / blk att tag) (while T (setq att (car (nentsel "\n select attribute to change: "))) (setq blk (cdr (assoc 330 (entget att)))) ;; get parent block of a nentsel (setq tag (cdr (assoc 2 (entget att)))) (princ tag) (LM:vl-setattributevalue (vlax-ename->vla-object blk) tag (getstring T "\nNew value: ")) ) ) [/code] Edited November 10, 2021 by Emmanuel Delay Quote
marko_ribar Posted November 10, 2021 Posted November 10, 2021 (edited) Yes, it's possible : ;; change attribute ;; https://www.cadtutor.net/forum/topic/73972-pre-fill-in-getstring/ (defun c:attch ( / LM:vl-setattributevalue adoc att blk tag ) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ;; Set Attribute Value - Lee Mac ;; Sets the value of the first attribute with the given tag found within the block, if present. ;; blk - [vla] VLA Block Reference Object ;; tag - [str] Attribute TagString ;; val - [str] Attribute Value ;; Returns: [str] Attribute value if successful, else nil. (defun LM:vl-setattributevalue ( blk tag val ) (setq tag (strcase tag)) (vl-some (function (lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (progn (vla-put-textstring att val) val) ) ) ) (vlax-invoke blk 'getattributes) ) ) (while (setq att (car (nentsel "\n select attribute to change: "))) (setq blk (cdr (assoc 330 (entget att)))) ;; get parent block of a nentsel (setq tag (cdr (assoc 2 (entget att)))) (princ tag) (vla-sendcommand adoc "new_value_") ;; this is the trick to add predefined prefix to (getstring) specification that follows... (LM:vl-setattributevalue (vlax-ename->vla-object blk) tag (getstring T "\nNew value : ")) ) (princ) ) HTH. M.R. Edited November 10, 2021 by marko_ribar 2 Quote
Emmanuel Delay Posted November 10, 2021 Author Posted November 10, 2021 Perfect. Thank you very much Quote
Lee Mac Posted November 12, 2021 Posted November 12, 2021 Good solution Marko, using the asynchronous process. 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.