Visual LISP, AutoLISP and General Customization

Reply
Mentor
southie
Posts: 291
Registered: ‎03-15-2007
Message 1 of 5 (190 Views)

list sorting

190 Views, 4 Replies
10-19-2012 10:39 AM

Hey Gang

 

Is it possible to sort the below list so that it is sequencial i.e.  "ID NO. 1" "ID NO.2" .....

 

("ID No. 1" "ID No. 10" "ID No. 11" "ID No. 12" "ID No. 13" "ID No. 14" "ID No. 5" "ID No. 6" "ID No. 7" "ID No. 8" "ID No. 9" "ID No. 2" "ID No. 3" "ID No. 4")

 

tia

 

Southie

Mentor
southie
Posts: 291
Registered: ‎03-15-2007
Message 2 of 5 (178 Views)

Re: list sorting

10-19-2012 11:38 AM in reply to: southie

Found this on the search board thanks kent Cooper. I made a slight modification

 

(vl-sort

  '("ID No. 1" "ID No. 10" "ID No. 11" "ID No. 12" "ID No. 13" "ID No. 14" "ID No. 5" "ID No. 6" "ID No. 7" "ID No. 8" "ID No. 9" "ID No. 2" "ID No. 3" "ID No. 4")

 

  '(lambda (a b)

    (<

      (atoi (substr a (+ (vl-string-position (ascii " ") a 0 T) 2)))

      (atoi (substr b (+ (vl-string-position (ascii " ") b 0 T) 2)))

    ); <

  ); lambda

); vl-sort

*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 3 of 5 (160 Views)

Re: list sorting

10-19-2012 07:17 PM in reply to: southie

Another

 

(vl-sort lst
 '(lambda (a b / x)
    	(setq x (vl-string-mismatch a b))
    (< (atoi (substr a x))(atoi (substr b x))
     )
  )
)

 

Mentor
southie
Posts: 291
Registered: ‎03-15-2007
Message 4 of 5 (157 Views)

Re: list sorting

10-19-2012 07:35 PM in reply to: southie

pb thanks for the response learning that '(lambda (a b)... is a friend !!

 

Southie

 

Mentor
devitg
Posts: 1,694
Registered: ‎03-14-2004
Message 5 of 5 (121 Views)

Re: list sorting

10-21-2012 08:30 PM in reply to: pbejse

Thanks , nice routine , I had never seen the 

 

vl-string-mismatch

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community