TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Vikram on January 23, 2022, 10:22:30 AM

Title: Need a lisp to sort selection from left to right and bottom to top
Post by: Vikram on January 23, 2022, 10:22:30 AM
Hi guys, I have drawings with design of big sheets in them. I have to DXFOUT them to and have to select each entity manually from left top right and bottom to top to process it in another software. Is there any lisp to sort the selection in this way?
When I try to select all they get selected in the order they were drawn.

Selection should be like from first bottom left entity to first top left entity in right direction

I'm using AutoCAD 2022 and I have attached the image and drawing file of the same. Any help would be appreciated very very much! :-)
PS: I'm newbie in lisp programming.
Title: Re: Need a lisp to sort selection from left to right and bottom to top
Post by: BIGAL on January 23, 2022, 06:55:07 PM
There is the VL-sort function which can sort on X & Y so you would make a list of say ((X Y entityname).....

This should be lower left sort so you should be able to work out which corner you want. Look at the < & = combo may need >

Code: [Select]
; sorts on 1st two items
(vl-sort lst
'(lambda (a b)
    (cond
      ((< (car a) (car b)))
      ((= (car a) (car b)) (< (cadr a) (cadr b)))
    )
  )
)
Title: Re: Need a lisp to sort selection from left to right and bottom to top
Post by: It's Alive! on January 24, 2022, 12:55:48 AM
You can create a selection set, then add entities in the order you want
Title: Re: Need a lisp to sort selection from left to right and bottom to top
Post by: stevar on April 14, 2022, 07:29:13 PM
So Vikram, what does your autolisp macro look like?
Title: Re: Need a lisp to sort selection from left to right and bottom to top
Post by: BIGAL on April 14, 2022, 10:14:58 PM
stevar why comment Vikram has not responded. An example sort code was provided.
Title: Re: Need a lisp to sort selection from left to right and bottom to top
Post by: ronjonp on April 14, 2022, 11:19:29 PM
stevar why comment Vikram has not responded. An example sort code was provided.
You shouldn't be so brash ... many many times you comment on threads already solved.  :?
Title: Re: Need a lisp to sort selection from left to right and bottom to top
Post by: DEVITG on April 19, 2022, 06:53:42 PM
Hi guys, I have drawings with design of big sheets in them. I have to DXFOUT them to and have to select each entity manually from left top right and bottom to top to process it in another software. Is there any lisp to sort the selection in this way?
When I try to select all they get selected in the order they were drawn.

Selection should be like from first bottom left entity to first top left entity in right direction

I'm using AutoCAD 2022 and I have attached the image and drawing file of the same. Any help would be appreciated very very much! :-)
PS: I'm newbie in lisp programming.

   If you do a SSGET "F" by the line or poly points , it select in the order the poly or line was done







Title: Re: Need a lisp to sort selection from left to right and bottom to top
Post by: kdub_nz on April 19, 2022, 07:50:40 PM
< .. >  and have to select each entity manually from left top right and bottom to top to process it in another software. < .. >
Selection should be like from first bottom left entity to first top left entity in right direction

< .. >

Hi Vikram.
A couple things :
Are the entities Lines or Plines ?

Can you be a bit more descriptive regarding the rules for selection ?

Do you require the endpoints change to suit the 'direction' ?

"right direction"  please clarify right

I'm a bit confused about the requirements to "to process it in another software" .

Do you ONLY care about the direction the entity is drawn in . . or do you expect unrelated entities to be in some sort of 'sequence' ??

Regards