itacad Posted September 20, 2018 Share Posted September 20, 2018 Excuse me for the title, I hope that "circular" identifies the problem. Some attributes are compiled with alphanumeric values, for example: number.letternumber (es. 18.U7 or 74.R61). The position of the letters in variable, but always there is only one letter in the string. the peculiarity is that the letter can have only 3 possible values: U V W or R S T. I'd like a lisp to change the value of the letter every time I click on the attribute, so the examples after the first click would become 18.V7 and 74.S61, after the second click 18.W7 and 74.T61 and after the third click again 18.U7 and 74.R61. I have not found a discussion from which to take inspiration ... Thank you in advance Quote Link to comment Share on other sites More sharing options...
ronjonp Posted September 20, 2018 Share Posted September 20, 2018 Here's a quick example: (defun _get (k l) ;; Get next item in list or return first (cond ((cadr (member k l))) ((car l)) ) ) (setq str "74.R61") (repeat 2 (foreach a (setq l '("R" "S" "T")) (alert (setq str (vl-string-subst (_get (vl-some '(lambda (x) (if (vl-string-search x str) x ) ) '("R" "S" "T") ) l ) a str ) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 21, 2018 Share Posted September 21, 2018 Another possiblity is a b c d ..... if you use (CHR x) you can get the next character so if you have V (ascii "V")= 86 so (chr 86+1) = W (setq x (ascii (getstring "Enter a single character"))) (alert (strcat "next is " (chr (+ x 1)))) So like Ronjonp just check what character you have in the string a easier way is again check a-z & A - Z but use >65 & <90 & >97 & 122 no need for a list of characters. Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted September 21, 2018 Share Posted September 21, 2018 (defun uvw (x / ) (vl-list->string (mapcar ''((x / i)(cond ((<= 85 x 87)(setq i (1+ x)) (if (<= i 87) i (- x 2))) (x)))(vl-string->list x) )) ) (uvw "74.U61") "74.V61" Quote Link to comment Share on other sites More sharing options...
itacad Posted September 25, 2018 Author Share Posted September 25, 2018 I apologize but these suggestions have not been useful, especially because of my lack of ability to program in lisp. I try to rewrite my needs because I have probably explained myself badly...and perhaps in this way it will be easier for me to associate the necessary lines of code with each passage: 1) I need to click above an attribute (if you wish I could specify block and attribute) and acquire its value (an alphanumeric string). 2) I need to find in the only letter in an alphanumeric string (I don't know the position of the letters but I know that there is only one alphabetic letter) 3) known the value, I need to change it with the next of a cycle of 3 possible values (U V W) 4) I need to replace the content of the attribute with the value of the new string How is possible merge these 4 steps into a single lisp? Thank you in advance Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 26, 2018 Share Posted September 26, 2018 (edited) Try this (defun c:UVWX ( str / ) (setq obj (vlax-ename->vla-object (car (nentsel "\nPick attribute")))) (setq str (vla-get-textstring obj)) (vla-put-textstring obj (UVW str) ) ; use hanhphuc here ) Ps still having lots of problems with the encoding when cutting pasting. Edited September 26, 2018 by BIGAL Quote Link to comment Share on other sites More sharing options...
itacad Posted October 1, 2018 Author Share Posted October 1, 2018 Dear Bigal, pe patient with me, but I do not manage with autolisp, and i don't know why your lisp doesn't work...there is a segnalation about missing arguments... thank you very much in advance Quote Link to comment Share on other sites More sharing options...
dlanorh Posted October 1, 2018 Share Posted October 1, 2018 (edited) 52 minutes ago, itacad said: Dear Bigal, pe patient with me, but I do not manage with autolisp, and i don't know why your lisp doesn't work...there is a segnalation about missing arguments... thank you very much in advance You are supposed to put the two lisps together. Like this (vl-load-com) (defun uvw (x / ) (vl-list->string (mapcar ''((x / i)(cond ((<= 85 x 87)(setq i (1+ x)) (if (<= i 87) i (- x 2))) (x)))(vl-string->list x)) ) ) (defun c:UVWX ( / obj str ) (setq obj (vlax-ename->vla-object (car (nentsel "\nPick attribute")))) (setq str (vla-get-textstring obj)) (vla-put-textstring obj (UVW str)) ; use hanhphuc here ) Copy and paste all the code above into a text editor and save it as "UVWX.lsp". Appload it then type UVWX on the command line to run it. Edited October 1, 2018 by dlanorh See ronjonp's post below Quote Link to comment Share on other sites More sharing options...
ronjonp Posted October 1, 2018 Share Posted October 1, 2018 (edited) 4 minutes ago, dlanorh said: (defun c:UVWX ( str / ) needs to be (defun c:UVWX (/ obj str) Edited October 1, 2018 by ronjonp Quote Link to comment Share on other sites More sharing options...
dlanorh Posted October 1, 2018 Share Posted October 1, 2018 30 minutes ago, ronjonp said: needs to be (defun c:UVWX (/ obj str) Sorted. Not my code, but i should have noticed. Quote Link to comment Share on other sites More sharing options...
itacad Posted October 2, 2018 Author Share Posted October 2, 2018 23 hours ago, dlanorh said: Sorted. Not my code, but i should have noticed. Yes it was this! It works! It works! I already corrected for the RST version! (where can I find the list of characters?) (mapcar ''((x / i)(cond ((<= 82 x 84)(setq i (1+ x)) (if(<= i 84) i (- x 2))) (x)))(vl-string->list x)) Now I I continue the discussion to understand if it is possible to make a single lisp for three different situations As I said at the beginning of the discussion, I have to perform the same circular correction in the following situations (they are the phases of an electrical system): 1) cycle U V W (solved) 2) cycle R S T (solved) 3) cycle L1 L2 L3 (for example 45.L1-1A or TN-S/L3-N...not developed in this discussion) In your opinion it would be possible to unify in a single lisp? Thank you in advance! Quote Link to comment Share on other sites More sharing options...
Jef! Posted October 3, 2018 Share Posted October 3, 2018 3 hours ago, itacad said: In your opinion it would be possible to unify in a single lisp? Yup! Good luck! .... Isn't it not what you asked for? I feel another implicit question. I slightly modified uvxw command, just to prevent it from bombing if someone misclick since selecting attribs can be picky sometimes. Also it will keep running as long as you don't right click to exit. Here's the approach i took; ascii 85/86, increment by one. ascii 87, return 84 (letter U), ascii 82/83, increment by one, ascii 84, return 82 (letter R). 3 hours ago, itacad said: 3) cycle L1 L2 L3 (for example 45.L1-1A or TN-S/L3-N...not developed in this discussion) Maybe you should have developed in the discussion. TN-S/L3-N goes to TN-S/L1-N...or to RN-S/L1-N? ( 'cuz there is also a T...) my feeling is that TN-S/L3-N goes to TN-S/L1-N. (defun c:UVWX ( / obj str nent) (while (or (setq nent (nentsel "\nPick attribute. Right click to exit")) (not (= (getvar 'errno) 52)) ) (if nent (progn (setq obj (vlax-ename->vla-object (car nent))) (setq str (vla-get-textstring obj)) (vla-put-textstring obj (UVW str)) ) ) ) (princ) ) (defun uvw (x / Llst tmp) (setq Llst '("L1" "L2" "L3")) (if (vl-some '(lambda (y) (wcmatch x (strcat "*" (setq tmp y) "*"))) Llst) (vl-string-subst (if (>(vl-position tmp Llst) (- (length Llst)2))(car Llst)(nth (1+(vl-position tmp Llst))Llst))tmp x) (vl-list->string (mapcar ''((x /) (cond ((<= 85 x 86) (1+ x) ) ((= x 87) (- x 2) ) ((<= 82 x 83) (1+ x) ) ((= x 84) (- x 2) ) (t x) ) ) (vl-string->list x) ) ) ) ) Cheers Quote Link to comment Share on other sites More sharing options...
itacad Posted October 3, 2018 Author Share Posted October 3, 2018 Thank you very much! it works perfectly! this lisp saves me a huge amount of operations every day! I hope it can be useful to others too! You understood perfectly the sequence L1 L2 L3 (who knows how to call the electric phases in U.S.A.). Regards... 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.