Jump to content

get TEXT content????


ktbjx

Recommended Posts

how do i get the TEXT content and put it as elevation on objects i'll be slecting?

 

(defun c:q1 (/ txt1 q1 ss)
(setq ss (ssget "_C" '((0 . "*TEXT"))))
   (cdr (assoc 1 (entget (ssname ss (setq txt1 0)))))

(prompt "\nSELECT OBJECTS")
(setq sss (ssget "_:L"))
(command"_.CHANGE" sss "" "_P" "_E" txt1)
)

Link to comment
Share on other sites

Some guessing:

(defun c:q1 ( / LeaveNumbersAndDots txt enx n SS )
 (defun LeaveNumbersAndDots (str)
   (if (and (eq 'STR (type str)) (setq str (vl-remove-if-not '(lambda (c) (<= 46 c 57)) (vl-string->list str))) )
     (vl-list->string str)
   )
 ); defun LeaveNumbersAndDots
 (cond
   ( (not (setq txt (car (entsel "\nPick text with numerical content: "))))
     (alert "\nNothing selected.")
   )
   ( (not (wcmatch (cdr (assoc 0 (setq enx (entget txt)))) "*TEXT"))
     (alert "\nThis is not a text.")
   )
   ( (not (numberp (setq n (read (setq txt (cdr (assoc 1 enx)))))))
     (alert 
       (strcat "\nThis text has no full numerical content: 
         \nCurrently it is: \"" txt "\" 
         \nIt must be in the following format: \"" (cond ((LeaveNumbersAndDots txt)) ("123.4")) "\"."
       )
     )
   )    
   ( (not (and (princ "\nSelect objects to change their elevation: ") (setq SS (ssget "_:L"))))
     (alert "\nNothing selected.")
   )
   (
     (mapcar 
       '(lambda (enx)
         (cond 
           ( (assoc 38 enx) (entmod (append enx (list (cons 38 n)))) )
           ( (entmod (mapcar '(lambda (x) (if (member (car x) '(10 11)) (reverse (cons n (cdr (reverse x)))) x) ) enx)) )
         )
       )
       (mapcar 'entget (apply 'append (mapcar '(lambda (x) (if (= 3 (car x)) (list (cadr x)))) (ssnamex SS))))
     )
   )
 ); cond
 (princ)
); defun

Edited by Grrr
Link to comment
Share on other sites

   ( (not (numberp (setq n (read (cdr (assoc 1 enx))))))
     (alert "\nThis text has no numerical content.")
   )    

 

Hi,

 

Your alert sentence is not that entirely correct since numberp function would return nil for such a string. eg: "abc123"

(defun HasNoNumber-p (str)
 (not (vl-some '(lambda (no) (< 47 no 57)) (vl-string->list str)))
)

Link to comment
Share on other sites

Hi Tharwat,

Yes: my intention was to check only for numerical characters inside the text content (I thought that would be the required format).

And yes, my alert message is not entirely correct (due some lack of english).

 

Anyway, like you said the text content could be re-formatted:

; _$ (LeaveNumbers "Leave 251, 900 and 841 numbers please.") -> "251900841"
(defun LeaveNumbers (str)
 (apply 'strcat (mapcar 'chr (vl-remove-if-not '(lambda (c) (< 47 c 58)) (vl-string->list str))))
)

 

;)

Link to comment
Share on other sites

; _$ (LeaveNumbers "Leave 251, 900 and 841 numbers please.") -> "251900841"
(defun LeaveNumbers (str)
 (apply 'strcat (mapcar 'chr (vl-remove-if-not '(lambda (c) (< 47 c 58)) (vl-string->list str))))
)

 

;)

 

Both are correct but shorter and direct. ;)

(defun LeaveNumbers (str)
 (vl-list->string (vl-remove-if-not '(lambda (c) (< 47 c 58)) (vl-string->list str)))
)

Link to comment
Share on other sites

Some guessing:

(defun c:q1 ( / txt enx n SS )
 (cond
   ( (not (setq txt (car (entsel "\nPick text with numerical content: "))))
     (alert "\nNothing selected.")
   )
   ( (not (wcmatch (cdr (assoc 0 (setq enx (entget txt)))) "*TEXT"))
     (alert "\nThis is not a text.")
   )
   ( (not (numberp (setq n (read (cdr (assoc 1 enx))))))
     (alert "\nThis text has no numerical content.")
   )    
   ( (not (and (princ "\nSelect objects to change their elevation: ") (setq SS (ssget "_:L"))))
     (alert "\nNothing selected.")
   )
   (
     (mapcar 
       '(lambda (x / enx) 
         (cond ( (= 3 (car x)) (setq enx (entget (cadr x))) (entmod (append enx (list (cons 38 n)))) ) ) 
       )
       (ssnamex SS)
     )
   )
 ); cond
 (princ)
); defun

 

 

thank you!.

i tried it, and only polylines elevation is changed, but not LINES (Start z End Z), Leader (Vertex Z), Text (Position Z). how can i add it on your lisp? i dont wanna ruin your code

Link to comment
Share on other sites

i tried it, and only polylines elevation is changed, but not LINES (Start z End Z), Leader (Vertex Z), Text (Position Z). how can i add it on your lisp? i dont wanna ruin your code

 

I've modified the code in post #3, should work better - but I can't guarantee that its flawless.

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