how to sort dimension selection set by x-y coord

how to sort dimension selection set by x-y coord

Anonymous
Not applicable
1,381 Views
4 Replies
Message 1 of 5

how to sort dimension selection set by x-y coord

Anonymous
Not applicable

 

sslectionset2.JPG

(defun c:test (/ ss ss3 ss4 k)
(setq ss (ssget '((0 . "DIMENSION"))))
(setq ss4 (list (ssname ss 0)))
(setq k 1)
(repeat (- (sslength ss) 1)
(setq ss3 (list (ssname ss k)))
(setq ss4 (append ss4 ss3))
(setq k (1+ k))
);end repeat
(vl-sort ss4
(function (lambda (a b) (> (cadr (assoc 11 (entget a))) (cadr (assoc 11 (entget b))))))
);end of vl-sort
(princ ss4)
(princ)
)

 

..

..

..

 

not working... help me!!

 

 

 

0 Likes
1,382 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

Welcome to the community forum!

 

Your code is quite well. The only thing wrong is that you have the opposite comparison mark.

If you want to see the result using (princ ss4), you need to save the result of sorting to this variable - (setq ss4 (vl-sort... 

 

My code. I would suggest to use the easier way to make list of entities from selection set and to use different variable names - it's not the ss (= selection set) anymore, it's a list of enames.

 

(vl-load-com)

(defun c:test-dims-by-x ( / ss i lst lst-x)

  (if (setq ss (ssget '((0 . "DIMENSION"))))
    (progn
      (repeat (setq i (sslength ss))
	(setq lst (cons (ssname ss (setq i (1- i)))
			lst)))
      (setq lst-x (vl-sort lst
			   '(lambda (a b)
			      (< (cadr (assoc 11 (entget a)))
				 (cadr (assoc 11 (entget b)))))))))
  (princ)
  )

 

Message 3 of 5

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

 

 

....
(vl-sort ss4
(function (lambda (a b) (> (cadr (assoc 11 (entget a))) (cadr (assoc 11 (entget b))))))
);end of vl-sort
(princ ss4)
....

 

not working... help me!!


Could it be [I haven't experimented] just that you sort the list without changing what's held in the variable?  That (vl-sort) function will return a sorted list, but unlike certain other functions [such as (ssdel)], by itself will not change what the variable ss4 holds, so the (princ) function will still return the old value.  Try this:

 

....
(setq ss4

  (vl-sort ss4
    (function (lambda (a b) (> (cadr (assoc 11 (entget a))) (cadr (assoc 11 (entget b))))))
  );end of vl-sort

); setq
(princ ss4)
....

 

Or perhaps use a different variable name such as ss5, instead of replacing the contents of the same variable name, if you have any reason to want to hold on to the original contents for anything else.

Kent Cooper, AIA
Message 4 of 5

Anonymous
Not applicable

pic.JPG

 

(defun c:bvm (/ k ss en ed dc10 dc11 dc14 dro dro90 po1 po2 po3 dro_ dds po4 osmold a b ss6 lst i lst-x)
(command "._UNDO" "_Begin")
(setq osmold (getvar "osmode"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(defun dtr (c)
(* pi (/ c 180.0)))
(defun rtd (c)
(/ (* c 180.0) pi))
(setq k 0)
(setq i 0)
(Prompt "\n치수선 선택: ")
(if (setq ss (ssget '((0 . "DIMENSION"))))
(progn
(repeat (setq i (sslength ss))
(setq lst (cons (ssname ss (setq i (1- i)))
lst)))
(setq lst-x (vl-sort
(vl-sort lst '(lambda (a b) (< (caddr (assoc 11 (entget a))) (caddr (assoc 11 (entget b))))))
'(lambda (a b) (< (cadr (assoc 11 (entget a))) (cadr (assoc 11 (entget b)))))
)
)
))

(setq ss6 (ssadd))
(foreach ss5 (reverse lst-x)
(setq ss6 (ssadd ss5 ss6)))


(setq a (sslength ss))
(if (= 0 (rem a 2)) (setq b 0))
(if (= 1 (rem a 2)) (setq b 1))
(repeat (sslength ss6)
(setq en (ssname ss6 k))
(setq ed (entget en))
(setq dc10 (cdr (assoc 10 ed)))
(setq dc11 (cdr (assoc 11 ed)))
(setq dc14 (cdr (assoc 14 ed)))
(setq dro (angle dc10 dc14))
(setq dro90 (+ dro (/ pi 2)))
(setq po1 (polar dc10 dro90 100))
(setq po2 (polar dc11 dro 100))
(setq po3 (inters dc10 po1 dc11 po2 nil))
(setq dro_ (angle dc11 po3))
(setq dds (distance dc11 po3))
(setq po4 (polar dc11 (+ dro_ (dtr 0.0)) (* dds 2)))
(if (= b (rem k 2)) (command "dimtedit" en po4))
(setq k (1+ k))
);repeat
(setvar "osmode" osmold)
(command "._UNDO" "_End")
(princ)
)
(defun *error* (msg)
(setvar "osmode" osmold)
(princ msg))

 

 

thank you very so much. thank you for your time. ^^

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thank you for the great advice

0 Likes