AutoLISP.com Forum Index  

Go Back   AutoLISP.com Forum Index > AutoCAD > AutoLISP

AutoLISP Ask questions, give examples or troubleshoot your lisp programs. Feel free to post your code here (NO commercial adversiting).

Reply
 
Thread Tools Display Modes
Old 02-27-2010, 02:56 AM   #21
klb546s
Junior Member
 
Join Date: Feb 2010
Posts: 14
Question Line between lines of equal length

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.
klb546s is offline   Reply With Quote
Old 02-28-2010, 01:20 AM   #22
CarlAK
Senior Member
 
Join Date: Jan 2009
Location: Anchorage, Alaska
Posts: 203
Default

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))
   )
      
)
CarlAK is offline   Reply With Quote
Old 02-28-2010, 08:54 AM   #23
klb546s
Junior Member
 
Join Date: Feb 2010
Posts: 14
Smile Sort By Group

Hi Carl,
thanks for the idea,
will test it out and see how it goes.
Regards
kel be
klb546s is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:51 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright © 2010, AutoLISP.com
All Rights Reserved