Author Topic: Need a lisp to sort selection from left to right and bottom to top  (Read 1455 times)

0 Members and 1 Guest are viewing this topic.

Vikram

  • Newt
  • Posts: 50
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.

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Need a lisp to sort selection from left to right and bottom to top
« Reply #1 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)))
    )
  )
)
A man who never made a mistake never made anything

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: Need a lisp to sort selection from left to right and bottom to top
« Reply #2 on: January 24, 2022, 12:55:48 AM »
You can create a selection set, then add entities in the order you want

stevar

  • Mosquito
  • Posts: 2
Re: Need a lisp to sort selection from left to right and bottom to top
« Reply #3 on: April 14, 2022, 07:29:13 PM »
So Vikram, what does your autolisp macro look like?

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Need a lisp to sort selection from left to right and bottom to top
« Reply #4 on: April 14, 2022, 10:14:58 PM »
stevar why comment Vikram has not responded. An example sort code was provided.
A man who never made a mistake never made anything

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Need a lisp to sort selection from left to right and bottom to top
« Reply #5 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.  :?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DEVITG

  • Bull Frog
  • Posts: 479
Re: Need a lisp to sort selection from left to right and bottom to top
« Reply #6 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







Location @ Córdoba Argentina Using ACAD 2019  at Window 10

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: Need a lisp to sort selection from left to right and bottom to top
« Reply #7 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
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.