trying to flip a list of lines inside a block

trying to flip a list of lines inside a block

Anonymous
Not applicable
877 Views
3 Replies
Message 1 of 4

trying to flip a list of lines inside a block

Anonymous
Not applicable

I'm at the very last step of a lengthy LISP for coloring lines in a block.  I need to have the LISP assign lines to layers based on their horizontal position within the whole group of lines, from right-to-left.  I can't get the very last step right, it will only work from left-to-right.  (These blocks will always have their basepoints at the top-right, if that matters...)

 

It has to be something in the vl-sort portion of my code, but I've tried changing the less-than/greater-than back and forth, but no luck, always ends up being left-to-right.  

 

I also tried using that portion of the code right in the ACAD command line with coordinates that correspond to the lines in the block, and when I swap the sign, it cooperates and lists the points in the correct order.  

 

But of course, the LISP itself is not cooperating. Can someone help me get over this hump?  Thanks in advance!

0 Likes
Accepted solutions (2)
878 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

If I understand correctly....

 

This part:

 

(setq vl

  (cons

    (list (cadr (vlax-get b 'startpoint)) (vla-get-length b) b)
    vl
  )
)

 

adds to the front of the vl list a sub-list for the Line, containing its start-point's Y coordinate and length and itself as a VLA object.

 

If they're vertical and you want them sorted by horizontal position, shouldn't that use the startpoint's [or endpoint's] X coordinate? -- (list (car (vlax-get b 'startpoint)) ....

 

Then this part:

 

(setq vl

 (vl-sort
   vl
   (function (lambda (e1 e2) (< (cadr e1) (cadr e2))))
  )
)

 

tries to sort them by their lengths [the second item in each sub-list], rather than by their horizontal position.  Shouldn't that also be looking at the first item in each sub-list [its X coordinate]? -- ... (< (car e1) (car e2)) ....

Kent Cooper, AIA
0 Likes
Message 3 of 4

Ranjit_Singh
Advisor
Advisor
Accepted solution

Change needs to happen here

		   (cond ((and (eq (vla-get-objectname b) "AcDbLine") (vert-p b) (> (vla-get-length b) 14.95))
			  (setq vl (cons (list (car (vlax-get b 'startpoint)) (vla-get-length b) b) vl)))
			 ;;if the object is VERTICAL line MORE THAN 14.95" IN LENGTH then make this vl list
			 ))
		  (setq vl (vl-sort vl (function (lambda (e1 e2) (> (car e1) (car e2))))))

You are catching y co-ordinates which are all the same. You need car to catch x -coordinates. Also, it seems like when you created your block it was located along negative x axis, and all your x-coordinates are negative (check in the block editor), so your sign needs to be flipped to ">"

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Agh, doggone it...the one thing I didn't change myself earlier was the cadr-to-car in the "if" statement about catching the line.  Thanks very much for the replies! Smiley Very Happy

0 Likes