Jump to content

dimension


mousho

Recommended Posts

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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 by ronjonp
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...