Strydaris Posted October 28, 2023 Posted October 28, 2023 (edited) Hey everyone, Was hoping someone could help me out with this. Here is my scenario. I have a dotted pair list of where the length of the list could vary. The dotted pairs are all like this (( "Alpha" . "Num") ( "Alpha1" . "Num1") ( "Alpha2" . "Num2") etc etc) I dont want to change the "Alpha#", but I want to increase the value of the "Num#" by a user entered value. I am trying to use foreach to do this. I think I am close, but not 100% sure on how to use subst to just update the 2nd value of the pair. Or even if this is the right approach to this problem. (foreach x vals (if (/= x nil) (progn (setq updval (+ (atof (cdr x)) global:updhgt) ed (subst (cdr (rtos updval 2 2)) x vals) );setq ;(entmod ed) );progn );if );foreach From the Acad docs I see that subst is (subst newitem olditem lst) Where it should be show as (subst ( "Alpha" . "NumNEW" ) ( "Alpha" . "Num") vals) Only thing I cant figure out is how to keep the original "Alpha" to use in the subst or if I even need to use subst to do the work I need. Anyone have any thoughts on this? Edited October 28, 2023 by Strydaris Quote
rlx Posted October 28, 2023 Posted October 28, 2023 like this? (setq vals '(( "Alpha" . "1.0") ( "Alpha1" . "2.0") ( "Alpha2" . "3.0")) global:updhgt 2) (foreach x vals (setq vals (subst (cons (car x) (rtos (+ (atof (cdr x)) global:updhgt) 2 2)) x vals))) Quote
Strydaris Posted October 28, 2023 Author Posted October 28, 2023 @rlx Funny enough I was just working towards this exact solution. What was holding me back was the setq vals part within the foreach I thought that subst would actively replace the values that were in the in the main vals list. I didnt think that you would have to essentially redefine the vals list. Thanks. This did the trick. Quote
BIGAL Posted October 29, 2023 Posted October 29, 2023 Why make dotted pairs ? Why not just plain ((A B). Over at the swamp there is this forum and it has a lot of list manipulation examples it can sometimes give an answer to this type of question straight away. http://www.theswamp.org/index.php?board=77.0 Plain list (a b)(c D).... (setq num 2) (foreach x vals (setq vals (subst (list (car x) (rtos (+ (atof (cadr x)) num) 2 2)) x vals))) Quote
Strydaris Posted October 29, 2023 Author Posted October 29, 2023 @BIGAL Thanks for the link. I'll check it out. I am using this in conjunction with Lee Mac's GetAttributes and SetAttributes sub functions. The version of his functions I am using use dotted pairs ( "Tag". "Value"). This bit of code is going to be used to update values in an attributed block all at the same time by whatever the user enters. Quote
BIGAL Posted October 29, 2023 Posted October 29, 2023 No worries, I just write custom block attribute updates to suit the scenario. Quote
Strydaris Posted October 29, 2023 Author Posted October 29, 2023 My idea is to use this one lisp to update any block attribute in our site plans. One has 4 attributes, another has 2 and the last has one. My thought process about using the dotted pairs and Lee's subfunction is to allow the user to use the same Lisp for each scenario instead of hard coding the tags into the lisp. I thought that would be a better approach. Quote
BIGAL Posted October 29, 2023 Posted October 29, 2023 (edited) if your editing block attributes there is another way you can GET Attributes, then update each attribute, you do not need to know the TAG name , rather attribute creation order, that is all, not dwg display order. (setq lst (list "asdf" "BGHJ" "123")) (setq obj (vlax-ename->vla-object (car (entsel "Pick block ")))) (setq atts (vlax-invoke obj 'Getattributes)) (setq x -1) (repeat (length lst) (vlax-put (nth (setq x (1+ x)) atts) 'textstring (nth x lst)) ) Note no check for does attribute number = items in list. You can though do the attributes at start even if more attributes, a more advanced is to do (setq lst (list ("asdf" 2) ("BGHJ" 3) ("123" 5)) which sets the attributes via there creation order. Edited October 29, 2023 by BIGAL 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.