Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

WTD: routine to sort entities in a Selection set based on its X Value

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
302 Views, 4 Replies

WTD: routine to sort entities in a Selection set based on its X Value

Hi all,

I am try to develop a routine that will sort a selection set of text
entities by there X value (reading the selected text from left edge of
drawing to the right) and arrange the selected text in a column. I am having
trouble writing the code to sort the text.

TIA,

paul
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

See the attached file.

"Paul Graf" wrote in message
news:89B87D9DA8D4EBDA1970AE55B7475A25@in.WebX.maYIadrTaRb...
> Hi all,
>
> I am try to develop a routine that will sort a selection set of text
> entities by there X value (reading the selected text from left edge of
> drawing to the right) and arrange the selected text in a column. I am
having
> trouble writing the code to sort the text.
>
> TIA,
>
> paul
>
>
Message 3 of 5
Anonymous
in reply to: Anonymous

Might also look into the (vl-sort-i) function.

"Tony Tanzillo" wrote in message
news:B7DAE95132CDC46ACD24E0C24FEEF9CD@in.WebX.maYIadrTaRb...
> See the attached file.
>
> "Paul Graf" wrote in message
> news:89B87D9DA8D4EBDA1970AE55B7475A25@in.WebX.maYIadrTaRb...
> > Hi all,
> >
> > I am try to develop a routine that will sort a selection set of text
> > entities by there X value (reading the selected text from left edge of
> > drawing to the right) and arrange the selected text in a column. I am
> having
> > trouble writing the code to sort the text.
> >
> > TIA,
> >
> > paul
> >
> >
>
>


----------------------------------------------------------------------------
----


;; SSINDEX.LSP Copyright 2000 Tony Tanzillo all rights reserved
;;
;; This material may not be reproduced or redistributed
;; without the expressed written consent of the author.
;;
;; (list-index )
;;
;; Sorts and returns a list of
;; integers representing the indices of the
;; elements in in their sorted order,
;; as defined by , a function that
;; takes two elements and returns a value
;; whose logical interpretation indicates the
;; relationship between the two values.

(defun list-index (input func / i)
(setq i -1)
(mapcar 'cdr
(vl-sort
(mapcar
'(lambda (val)
(cons val (setq i (1+ i)))
)
input
)
'(lambda (a b)
(apply func (mapcar 'car (list a b)))
)
)
)
)

;; (ss-index )
;;
;; where:
;;
;; (if (
;; ( )
;; ( )
;; )
;; <<< is less than >>>
;; <<< is less than >>>
;; )
;;
;; Returns a list of integers representing the
;; indices of the elements in the selection set
;; in the sorted order, where the function
;; takes each entity name in the selection set, and
;; returns that entity's sort key, and
;; takes the sort keys of two entities, and returns
;; a value whose logical interpretation indicates
;; the relationship of the two keys.

(defun ss-index (ss _getKey _compareKey / keylist i)
(repeat (setq i (sslength ss))
(setq keylist
(cons
(apply _getKey (list (ssname ss (setq i (1- i)))))
keylist
)
)
)
(list-index keylist _compareKey)
)

;; Test SS-INDEX. Prompts for a selection set of text,
;; and appends an integer to each text's value string,
;; which is the index of the text in the sorted order.

(defun C:TEST ( / ss indices oldtext)
(setq ss (ssget '((0 . "TEXT"))))
(setq indices
(ss-index ss
'(lambda (ename)
(caddr (assoc 10 (entget ename))) ;; sort key = Y-ordinate
)
'> ;; sort comparison function = < (is-greater-than)
)
)
(setq j -1)
(foreach i indices
(setq e (ssname ss i))
(setq oldtext (cdr (assoc 1 (entget e))))
(entmod
(list
(cons -1 e)
(cons 1
(strcat
oldtext
" ( "
(itoa (setq j (1+ j)))
" ) "
)
)
)
)
)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SSINDEX.LSP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Message 4 of 5
Anonymous
in reply to: Anonymous

Hi Tony,

Thank you for the file.. I had a quick look at it during lunch and noticed
it sorted text in the "Y" direction starting from the top (highest value).

I am trying to sort in the "X" direction starting with the lowest value. my
programming skills are not the best and I hoping you could give me a pointer
in which lines of code to change.

I figure this line would be the main one i should change:

(caddr (assoc 10 (entget ename))) ;; sort key = Y-ordinate

I have tried changing the "caddr" to "caar" thinking it would return the
"X-oridinate"

I hope i am not bugging you...

thanks,

paul
Message 5 of 5
Anonymous
in reply to: Anonymous

"Paul Graf" wrote in message
news:67F52EEBD2CAF3A144D1EB3EF8613111@in.WebX.maYIadrTaRb...
> Hi Tony,
>
> Thank you for the file.. I had a quick look at it during lunch and noticed
> it sorted text in the "Y" direction starting from the top (highest value).
>
> I am trying to sort in the "X" direction starting with the lowest value.
my
> programming skills are not the best and I hoping you could give me a
pointer
> in which lines of code to change.
>
> I figure this line would be the main one i should change:
>
> (caddr (assoc 10 (entget ename))) ;; sort key = Y-ordinate
>
> I have tried changing the "caddr" to "caar" thinking it would return the
> "X-oridinate"


Try (cadr (assoc 10 (entget ename)))

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost