Help with lisp that modify dim text

Help with lisp that modify dim text

nam.lethai1995
Enthusiast Enthusiast
598 Views
6 Replies
Message 1 of 7

Help with lisp that modify dim text

nam.lethai1995
Enthusiast
Enthusiast

i run this code to modify my dim text
(defun c:bc ()
(setq dim (car (entsel "\nSelect dimension object: ")))
(setq b (getreal "\nEnter new value for b: "))
(setq a (cdr (assoc 42 (entget dim))))
(setq c (/ a b))
(setq text (strcat "c@b=" (rtos c) " "))
(setq ent (entnext dim))
(while (/= (type ent) 'ENDBLK)
(setq entData (entget ent))
(if (and (eq (cdr (assoc 0 entData)) "TEXT") (equal (cdr (assoc 1 entData)) text))
(setq textEntData entData)
)
(setq ent (entnext ent))
)
(if (not (boundp 'textEntData))
(progn
(princ "\nCould not find associated text entity.")
(exit)
)
(entmod (subst (cons 1 text) (assoc 1 textEntData) textEntData))
)
(princ)
)

i have chose a rotated dimmension and other kind of dim but it keep result
; error: bad argument type: lentityp nil
Pls help me with this error.

0 Likes
Accepted solutions (2)
599 Views
6 Replies
Replies (6)
Message 2 of 7

komondormrex
Mentor
Mentor

hey, no need to dig into dim block. 

(defun c:bc ()
  (setq dim_dxf (entget (car (entsel "\nSelect dimension object: "))))
  (setq b (getreal "\nEnter new value for b: "))
  (setq a (cdr (assoc 42 (entget dim))))
  (setq c (/ a b))
  (setq text (strcat "c@b=" (rtos c) " "))
  (setq ent (entnext dim))
;;;  (while (/= (type ent) 'ENDBLK)
;;;    (setq entData (entget ent))
;;;    (if (and (eq (cdr (assoc 0 entData)) "TEXT") (equal (cdr (assoc 1 entData)) text))
;;;      (setq textEntData entData)
;;;    )
;;;    (setq ent (entnext ent))
;;;  )
;;;  (if (not (boundp 'textEntData))
;;;    (progn
;;;      (princ "\nCould not find associated text entity.")
;;;      (exit)
;;;    )
    (entmod (subst (cons 1 text) (assoc 1 dim_dxf) dim_dxf))
;;;  )
  (princ)
)
0 Likes
Message 3 of 7

nam.lethai1995
Enthusiast
Enthusiast

Thank for your answer but i still encounter "bad argument type: lentityp nil" error when using your code. Do you know how to fix it?

0 Likes
Message 4 of 7

pbejse
Mentor
Mentor
Accepted solution
(defun c:bc ()
  (setq dim_dxf (entget (car (entsel "\nSelect dimension object: "))))
  (setq b (getreal "\nEnter new value for b: "))
  (setq a (cdr (assoc 42 dim_dxf)))
  (setq c (/ a b))
  (setq text (strcat "c@b=" (rtos c) " "))
    (entmod (subst (cons 1 text) (assoc 1 dim_dxf) dim_dxf))
  (princ)
)
0 Likes
Message 5 of 7

komondormrex
Mentor
Mentor
Accepted solution

hey, 

there is the only list in the code corrected and it is dim_dxf, so check if it got the data. the version by @pbejse with commentouts removed should work just fine. 

0 Likes
Message 6 of 7

nam.lethai1995
Enthusiast
Enthusiast
I try with the "1950" dim text and it results c@b=13 text content.
0 Likes
Message 7 of 7

nam.lethai1995
Enthusiast
Enthusiast

With a little bit adjusts the code is now work pretty fine for me. Thank for the idea
(defun c:bc ()
(setq dim_dxf (entget (car (entsel "\nSelect dimension object: "))))
(setq b (getreal "\nEnter new value for b: "))
(setq a (cdr (assoc 42 dim_dxf)))
(setq c (/ a b))
(setq text (strcat (rtos c)"@"(rtos b)"="(rtos a)))
(entmod (subst (cons 1 text) (assoc 1 dim_dxf) dim_dxf))
(princ)
)

0 Likes