Jump to content

"Circular" values


itacad

Recommended Posts

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

 

 

 

Link to comment
Share on other sites

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
		     )
	   )
    )
  )
)

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

 

(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" 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 by BIGAL
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by dlanorh
See ronjonp's post below
Link to comment
Share on other sites

4 minutes ago, dlanorh said:

(defun c:UVWX ( str / )

needs to be

(defun c:UVWX (/ obj str)

 

Edited by ronjonp
Link to comment
Share on other sites

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!

 

 

 

 

 

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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...

 

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...