mousho Posted January 26, 2020 Share Posted January 26, 2020 Hello all need help to fix this lisp im trying to write a lisp that will let me to choose dimensions and depand on the length it will add a letter next to it the problem is that he changing the last dimenssion that draw and not the selection with no succes to change it if anyone can help to give me idea how to do that ill be glad the goal of the lisp is to be able to choose 2 dimenssion and he will compare between them and write a letter between them that fix to the longest dimenssion. if ill be able to choose 10 or more dimenssion at once and he will compare each time between 2 of them that are next to each other that will be perfect DEMO - Copy.lsp Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 26, 2020 Share Posted January 26, 2020 1st step (defun c:demo ( / ) (vl-load-com) (setq ensel (entsel "\nSelect dimension: ")) (setq txtt (fix (cdr (assoc 42 (entget (car ensel)))))) (cond ((<= txtt 200) (setq txttt "A")) ((<= txtt 250) (setq txttt "B")) ((<= txtt 300) (setq txttt "C")) ((<= txtt 350) (setq txttt "D")) ((<= txtt 400) (setq txttt "E")) ((<= txtt 450) (setq txttt "F")) ((<= txtt 500) (setq txttt "G")) ((<= txtt 550) (setq txttt "H")) ((<= txtt 600) (setq txttt "I")) ((<= txtt 650) (setq txttt "J")) ((<= txtt 700) (setq txttt "K")) ((<= txtt 750) (setq txttt "L")) ((<= txtt 800) (setq txttt "M")) ((<= txtt 850) (setq txttt "N")) ((<= txtt 900) (setq txttt "O")) ((<= txtt 950) (setq txttt "P")) ((<= txtt 1000) (setq txttt "Q")) ((<= txtt 1050) (setq txttt "R")) ((<= txtt 1100) (setq txttt "S")) ((=> txtt 1101)(alert "value is to large")) ) (if (=> txtt 1101) (princ) (vla-put-TextOverride (vlax-ename->vla-object(entlast)) (strcat "<> - " txttt)) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
mousho Posted January 26, 2020 Author Share Posted January 26, 2020 hi bigal thx for your help but i have problem with this line (vla-put-TextOverride (vlax-ename->vla-object(entlast)) (strcat "<> - " txttt) its choosing "entlast" and not the dim that i choose Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 26, 2020 Share Posted January 26, 2020 (edited) 1 hour ago, mousho said: hi bigal thx for your help but i have problem with this line (vla-put-TextOverride (vlax-ename->vla-object(entlast)) (strcat "<> - " txttt) its choosing "entlast" and not the dim that i choose Replace the function (entlast) with the variable name: (car ensel) Edited January 26, 2020 by Tharwat Quote Link to comment Share on other sites More sharing options...
mousho Posted January 26, 2020 Author Share Posted January 26, 2020 hi tharwat i try this already and i get "Error: bad function: (<Entity name: 7fffabfe480> (2481.61 500.134 0.0))" Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 26, 2020 Share Posted January 26, 2020 Have a close again. Quote Link to comment Share on other sites More sharing options...
mousho Posted January 26, 2020 Author Share Posted January 26, 2020 THARWAT U GENIUS Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 26, 2020 Share Posted January 26, 2020 (edited) 1 hour ago, mousho said: THARWAT U GENIUS Thank you, that's too kind of you to say. Here is my attempt if I may to rewrite your codes in another way if you don't mind of course and hopefully you like it. (defun c:Test ( / sel val get val rtn div ltr) ;;------------------------------------;; ;; Tharwat - Date: 26.Jan.2020 ;; ;;------------------------------------;; (and (setq sel (car (entsel "\nSelect dimension : "))) (or (= (cdr (assoc 0 (setq get (entget sel)))) "DIMENSION") (alert "Invalid selected object. Try again") ) (setq val (fix (cdr (assoc 42 get)))) (or (<= val 1101) (alert "Value of selected dimesion must be smaller than < 1100 > <!>") ) (setq div (/ val 50) ltr (if (< val 200) "A" (chr (+ 61 div))) ) (entmod (subst (cons 1 (strcat "<> - " ltr)) (assoc 1 get) get)) ) (princ) ) Edited January 26, 2020 by Tharwat Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 26, 2020 Share Posted January 26, 2020 Nice idea Tharwat. For Mousho an explanation, each keyboard character has a Asscii code so in Autocad lisp (chr 65) will return "A", B=66 and so on, a=97 there are 52 characters as you have upper and lower case letters. Quote Link to comment Share on other sites More sharing options...
mousho Posted January 27, 2020 Author Share Posted January 27, 2020 Thank u guys for the cide and the explanation its nice to learn new stuff now i just need to figuare how im choosing 2 dimenssion and the cide will compare betwwen them Quote Link to comment Share on other sites More sharing options...
ronjonp Posted January 27, 2020 Share Posted January 27, 2020 (edited) @BIGAL FWIW .. you don't need to set the variable 'txttt' in each conditional check .. something like this will accomplish the same thing: (if (setq txttt (cond ((<= txtt 200) "A") ((<= txtt 250) "B") ((<= txtt 300) "C") ((<= txtt 350) "D") ((<= txtt 400) "E") ((<= txtt 450) "F") ((<= txtt 500) "G") ((<= txtt 550) "H") ((<= txtt 600) "I") ((<= txtt 650) "J") ((<= txtt 700) "K") ((<= txtt 750) "L") ((<= txtt 800) "M") ((<= txtt 850) "N") ((<= txtt 900) "O") ((<= txtt 950) "P") ((<= txtt 1000) "Q") ((<= txtt 1050) "R") ((<= txtt 1100) "S") ((alert "value is to large")) ) ) ;; Do stuff ) Also '=>' at the end isn't a function. Edited January 27, 2020 by ronjonp 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.