The title is self explanatory, but I'm trying to convert an entity name to a string to order alphabetically and convert back to the original status. ;(acad_strlsort (nth x alisp))
This is a work around of course.
Any help would be much appreciated. Thanks in advance.
Thanks,
Michael Luckett
Solved! Go to Solution.
(defun sort_ename ()
(setq x 0 strlis '()); Becomes the same as alisp in string format
(repeat (length alisp)
(setq g 0 tmplis '())
(setq itm (nth x alisp))
(repeat (length itm)
(setq val (EntToStr (nth g itm)))
(setq tmplis (append tmplis (list val)))
(setq g (+ g 1))
)
(setq strlis (append strlis (list tmplis)))
(setq x (+ x 1))
)
(setq x 0 sortlis '());Sorts in alphabetical order
(repeat (length strlis)
(setq itm (nth x strlis))
(setq nitm (acad_strlsort itm))
(setq sortlis (append sortlis (list nitm)))
(setq x (+ x 1))
)
(setq x 0 totlis '()); Final list of Entities
(repeat (length strlis)
(setq itm (nth x strlis))
(setq tval (nth x alisp))
(setq itm2 (nth x sortlis))
(setq g 0 nalis '())
(repeat (length itm2)
(setq val (nth g itm2))
(setq h 0)
(repeat (length itm)
(setq val2 (nth h itm))
(setq tval2 (nth h tval))
(if (= val val2)(setq nalis (append nalis (list tval2))))
(setq h (+ h 1))
)
(setq g (+ g 1))
)
(setq totlis (append totlis (list nalis)))
(setq x (+ x 1))
)
(princ)
)
;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/convert-ename-to-string/td-p/795663
(defun EntToStr (ent / curstr opnfil)
(if (and ent (setq opnfil (open "EntToStr.tmp" "w")))
(progn
(princ ent opnfil)
(close opnfil)
(setq opnfil (open "EntToStr.tmp" "r")
curstr (read-line opnfil)
)
(close opnfil)
curstr
)
nil
)
)
Unconventional, but effective. See citation above for the sub "EntToStr ". "Alisp" is the list of entities.
Thanks,
Michael Luckett
Can't find what you're looking for? Ask the community or share your knowledge.