Jump to content

Recommended Posts

Posted

hello,

 

I wonder how to get only the longest line from a ssget only !

Any suggestion?

Just a start.

(setq ss1 (ssget '((0 . "LINE"))))
(if ss1
 (progn
   (setq i 0
         total 0
         n (sslength ss1))
   (while (< i n)
     (setq e (entget (ssname ss1 (setq i (1+ i)))))
       ) ))

 

Thanks

Posted

If I say :

 

step through the selection set,

save the ename and length of the first entity.

then;

if the next line is longer overwrite the ename and length

repeat

repeat

 

you will be left with the longest length and the ename of the entity so it can be selected.

 

There are several ways to handle this, of varying complexity but this may be an easy way to design a solution.

Posted

Thanks Kerry.

 

I added the following codes to the above selection set, and it gets the longest number but with the following msg.

(setq ename (distance (setq pt1 (cdr (assoc 10 e)))(setq pt2 (cdr(assoc 11 e)))))
(setq longest (entnext (max ename)))

 

Here is the msg .

; error: bad argument type: lentityp 8.57792

 

What's wrong or missing code ?

 

Thanks,

Posted

Before you start running learn to walk.

Are you able to step through the selection set and print eack line length to the commandLine ?

Posted

There a lot of things that can make a this kind of simple sounding routine very tricky:

 

2D or 3D distances?

WSC lines only?

Do you need to filter out paperspace lines?

What happens when you have multiple maximum length lines?

Does the end result need to be a selection set of just a ename?

 

 

 

[b][color=BLACK]([/color][/b]defun c:mxline [b][color=FUCHSIA]([/color][/b]/ i mx ss en ed ld ll[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq i -1
           mx 0
           ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"LINE"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
       [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss [b][color=BLUE]([/color][/b]setq i [b][color=RED]([/color][/b]1+ i[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b]
                    ld [b][color=GREEN]([/color][/b]distance [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 10 ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                                 [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 11 ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]>= ld mx[b][color=GREEN])[/color][/b]
                  [b][color=GREEN]([/color][/b]setq mx ld
                        ll [b][color=BLUE]([/color][/b]cons en ll[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]princ [b][color=NAVY]([/color][/b]strcat [color=#2f4f4f]"\nMax Length = "[/color] [b][color=MAROON]([/color][/b]rtos mx 2 4[b][color=MAROON])[/color][/b] [color=#2f4f4f]" - "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1 ll[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

ll contains a list of enames of the longest lines. -David

Posted
Before you start running learn to walk. :lol: :lol:

Are you able to step through the selection set and print eack line length to the commandLine ?

 

The answer is YES.

Here it is complete but small error at last entity distance ,

(defun c:long (/ ss1 i total n e len)
(setq ss1 (ssget '((0 . "LINE"))))
(if ss1
 (progn
   (setq i -1
         total 0
         n (sslength ss1))
   (while (< i n)
     (setq e (entget (ssname ss1 (setq i (1+ i)))))
       (setq len (distance (setq pt1 (cdr (assoc 10 e)))(setq pt2 (cdr(assoc 11 e)))))
        (print len)
  ))
     )
   (princ)
 )

 

Here is the response of codes,

20.0628

9.89551

17.8955

10.8955 ; error: bad argument type: lentityp nil

 

 

Could you please indicate to the wrong thing in the routine.

 

Great Thanks.

Posted

One too many n's

 

[color=black](defun c:long (/ ss1 i total n e len)[/color]
[color=black] (setq ss1 (ssget '((0 . "LINE"))))[/color]
[color=black] (if ss1[/color]
[color=black]   (progn[/color]
[color=black]     (setq i   -1[/color]
[color=black]    total 0[/color]
[color=black]    n   (sslength ss1)[/color]
[color=black]     )[/color]
[color=black]     (while (< i ([color=red][b]1- n[/b][/color]))[/color]
[color=black]      (setq e (entget (ssname ss1 (setq i (1+ i)))))[/color]
[color=black]      (setq len (distance (setq pt1 (cdr (assoc 10 e)))[/color]
[color=black]      (setq pt2 (cdr (assoc 11 e)))[/color]
[color=black]   )[/color]
[color=black])[/color]
[color=black](print len)[/color]
[color=blue];;; added this for original question[/color]
[color=blue](if (> len total)[/color]
[color=blue]  (setq total len)[/color]
[color=blue])[/color]
[color=blue]     )[/color]
[color=blue]   )[/color]
[color=blue] )[/color]
[color=blue] (princ[/color]
[color=blue]   (strcat "\nLongest line in selection set is " (rtos total))[/color]
[color=blue] )[/color]
[color=black] (princ)[/color]
[color=black])[/color]

Posted

Here is my 2 cents

 

 
(defun C:demo(/ filter_list info_list max_len ss)

(defun ent_length (line)
 (distance (cdr (assoc 10 (entget line)))
    (cdr (assoc 11 (entget line)))
    )
 )

(if (setq ss (ssget '((0 . "LINE"))))
 (progn
(setq info_list
(mapcar (function (lambda(x)
     (cons (ent_length x) x )))
(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
 (setq max_len (apply 'max (mapcar 'car  info_list)))
 (setq filter_list (vl-remove-if (function (lambda(x)
          (not (equal (car x) max_len 0.01))))
       info_list)
)
;; do your things here:
;;/*
 (foreach item filter_list
   (command "._change" (cdr item) "" "_P"  "_Color" "_Red" "")
   )
;;*/
)
 (alert "Nothing selected")
 )
 (princ)
 )

 

~'J'~

Posted

My 'entry'

 

(defun c:GetLongestLine nil ;; © Lee Mac 2010
 (
   (lambda ( ss i / e m d l )
     (and ss        
       (while (setq e (ssname ss (setq i (1+ i))))
         (if (< m (setq d (distance (cdr (assoc 10 (entget e))) (cdr (assoc 11 (entget e))))))
           (setq m d l e) t
         )
       )
       (sssetfirst nil (ssadd l))
     )
   )
   (ssget '((0 . "LINE"))) -1
 )
 (princ)
)

Posted

If the several lines have the same length then...:)

Posted
(defun c:SLL (/ ss)
 ;; Alan J. Thompson, 08.18.10
 (if (setq ss (ssget '((0 . "LINE"))))
   ((lambda (i / e l v d lst)
      (while (setq e (ssname ss (setq i (1+ i))))
        (or (< (setq v (distance (cdr (assoc 10 (setq l (entget e)))) (cdr (assoc 11 l)))) d)
            (setq d v)
        )
        (setq lst (cons (cons v e) lst))
      )
      (sssetfirst
        nil
        ((lambda (add) (foreach x lst (and (equal (car x) v) (ssadd (cdr x) add))) add)
          (ssadd)
        )
      )
    )
     -1
   )
 )
 (princ)
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...