![]() |
|
|||||||
| AutoLISP Ask questions, give examples or troubleshoot your lisp programs. Feel free to post your code here (NO commercial adversiting). |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Junior Member
Join Date: Feb 2010
Posts: 14
|
Hi Carl,
thanks for the suggestions. Assuming that each pair lines are the same length, and all the other pair are of different lengths. Is it possible for you to write a program that compares all the length of all the lines selected and pair off the lines of the same length and draw a line in between of the same length? If its ok with you. I am still new to this area. Thanks and Best Regards. kel be. |
|
|
|
|
|
#22 |
|
Senior Member
Join Date: Jan 2009
Location: Anchorage, Alaska
Posts: 203
|
Ok that approach is a little easier, to pair lines of the same length. Well I ended up writing something a little different, creating a list of line names from shortest to longest, then grouping lines 2 at a time from that list. In this example a line is just drawn from endpoint to endpoint. If this works for you, you can incorporate your midpoint drawing code.
Code:
(princ "Type LSORT to start")
(defun c:lsort ()
(vl-load-com)
(setq Ent_LengthSet nil)
(princ "\nSelect lines: ")
(setq Lset (ssget '((0 . "LINE"))))
(setq i 0)
;;create list of pairs, length & entity name
(repeat (sslength Lset)
(setq Ename (ssname Lset i))
(setq ED (entget Ename))
(setq Pt1 (cdr (assoc 10 ED)))
(setq Pt2 (cdr (assoc 11 ED)))
(setq L_Len (distance Pt1 Pt2))
(setq Ent_LengthSet (cons (list L_Len Ename) Ent_LengthSet))
(setq i (1+ i))
)
;; sort list shorter to longer lines
(setq Length_Sort (vl-sort Ent_LengthSet;;list of
'(lambda (x1 x2) (< (car x1) (car x2)))))
;; remove line legth from list, leaving entity names
(setq Line_Sort (mapcar 'cadr Length_Sort));
;;------draw line loop---------
;;connect endpoint of pairs
(setq ecount 0)
(repeat (/ (length Line_Sort) 2)
(setq L1 (nth ecount Line_Sort))
(setq L2 (nth (+ ecount 1) Line_Sort))
(setq endpt1 (cdr (assoc 10 (entget L1))))
(setq endpt2 (cdr (assoc 10 (entget L2))))
(command "line" endpt1 endpt2 "")
(setq ecount (+ ecount 2))
)
)
|
|
|
|
|
|
#23 |
|
Junior Member
Join Date: Feb 2010
Posts: 14
|
Hi Carl,
thanks for the idea, will test it out and see how it goes. Regards kel be |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|