i can't find out my problem in this lisp

i can't find out my problem in this lisp

Anonymous
Not applicable
3,113 Views
21 Replies
Message 1 of 22

i can't find out my problem in this lisp

Anonymous
Not applicable

hi everyone

I want to reverse the text by the selected text, but it does not work properly.it's getting error "lentittyp". I tried so many times.kindly help me .its would be really appreciated for the help. kindly mentioned what i did mistake in this lisp

sample text "a" "b" "c" "123"  etc.....

i want to like this - "123" "c" "b" "a" etc.......

 

(defun c:lop ()
(setq ss (ssget '((0 . "text"))))
(setq ab (sslength ss))
(setq i 0)
(repeat ab

(setq ssn (ssname ss i ))
(setq ent (entget ssn))
(setq asso (cdr (assoc 0 ent)))
(setq rev (reverse (list asso)))
;(entmod rev)
(setq i (+ i 1))
)
)

0 Likes
Accepted solutions (1)
3,114 Views
21 Replies
Replies (21)
Message 21 of 22

ronjonp
Mentor
Mentor

@Sea-Haven wrote:

Very nice Ronjonp but look at image I made the numbers out of order, erased some made a new ones as the ssget uses the database its now out of order. so renumber is incorrect. Providing the numbers are done one after another they are ok. 

That's why I hinted some sort of string approach.


@Sea-Haven The code I posted is for a linear sort ( which is what the OP needed ). I try to write code that eliminates the need for single picks as it's time consuming. 8-) 

0 Likes
Message 22 of 22

ronjonp
Mentor
Mentor
Accepted solution

@Anonymous wrote:

hi  R0NJ0NP

your code is really interesting. this is what I was expected from here. i am really grateful to you and everyone who replied to my query.

i have another question here. could i add here for block text?

(ssget ":L" '((0 . "text" "insert")))) "is this correct code for block"

thanks

hussain


When you say 'block text' I assume attribute? If so .. try this mod:

(defun c:foo (/ _foo _daisy p s)
  ;; RJP » 2019-11-06
  (defun _daisy	(pt l / _d tmp r)
    (defun _d (p l)
      (vl-sort l (function (lambda (r j) (< (distance p (last r)) (distance p (last j))))))
    )
    (setq tmp (_d pt l))
    (while (setq tmp (_d (last (car tmp)) tmp)) (setq r (cons (car tmp) r)) (setq tmp (cdr tmp)))
    (reverse r)
  )
  (defun _foo (o / a)
    (cond ((vlax-property-available-p o 'hasattributes)
	   ;; Grab first attribute
	   (setq a (car (vlax-invoke o 'getattributes)))
	   (list a (vla-get-textstring a) (vlax-get o 'insertionpoint))
	  )
	  ((list o (vla-get-textstring o) (vlax-get o 'insertionpoint)))
    )
  )
  (if (and (setq s (ssget ":L"
			  '((-4 . "<OR")
			    (0 . "TEXT")
			    (-4 . "<AND")
			    (0 . "INSERT")
			    (66 . 1)
			    (-4 . "AND>")
			    (-4 . "OR>")
			   )
		   )
	   )
	   (setq p (getpoint "\nPick a point to sort from: "))
	   (setq s (_daisy p
			   (mapcar '(lambda (x) (_foo (vlax-ename->vla-object x)))
				   (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
			   )
		   )
	   )
      )
    ;; Nice reverse @Codeding :)
    (foreach x (mapcar 'cons (mapcar 'car s) (mapcar 'cdr (reverse s)))
      (vla-put-textstring (car x) (cadr x))
    )
  )
  (princ)
)