Inventor Engineer-to-Order

Reply
Distinguished Contributor
ludesroc
Posts: 155
Registered: ‎05-03-2005
Message 1 of 7 (135 Views)
Accepted Solution

Sort using 4th element?

135 Views, 6 Replies
11-08-2012 06:08 AM

Hi,

 

Is there a way to sort a list using the 4th element? 

 

sort(iList, :Ascending, key := :first)

sort(iList, :Ascending, key := :second)

sort(iList, :Ascending, key := :third)

sort(iList, :Ascending, key := :fourth)

 

Regards,

Luc

Ludesroc
Mentor
FarrenYoung
Posts: 262
Registered: ‎07-13-2009
Message 2 of 7 (133 Views)

Re: Sort using 4th element?

11-08-2012 07:19 AM in reply to: ludesroc

The key parameter takes any function.  So to sort the fourth you need to create a function that gets the fourth element.

 

For example:

sort(iList, :Ascending, key := :fourth)

 

Function fourth(inList As List) As Any
    Return nth(4, inList)
End Function

 

This will also work in other functions, such as Find

Find(myValue, iList, key:=:fourth)

--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Distinguished Contributor
ludesroc
Posts: 155
Registered: ‎05-03-2005
Message 3 of 7 (128 Views)

Re: Sort using 4th element?

11-08-2012 07:58 AM in reply to: FarrenYoung

Thanks Farren! That's exactly was I was looking for! 

 

Now, I can I get this new function to remain in the functions list permanently? 

 

Functions.jpg

 

Regards,

Luc

 

Ludesroc
Mentor
FarrenYoung
Posts: 262
Registered: ‎07-13-2009
Message 4 of 7 (125 Views)

Re: Sort using 4th element?

11-08-2012 08:18 AM in reply to: ludesroc

You're welcome.

 

To make the function system wide, place it in "C:\Program Files\Autodesk\Inventor ETO Components 2012\Library\UserLib" (adjust for your version of eto)

 

Also, if you found my solution helpful I would appreciate any kudos you would like to give (Accept as Solution is great too).  The two of these are used as a part of the formula to determine a users' "Ranking" and I'd like to increase mine :-p

 

http://forums.autodesk.com/t5/FAQ-How-To-Using-Autodesk/Kudos-New-April-18/m-p/2993368/highlight/tru...

 

http://forums.autodesk.com/t5/Autodesk-Discussion-Groups/How-Postings-Kudos-and-correct-answers-Equa...

 

--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Distinguished Contributor
ludesroc
Posts: 155
Registered: ‎05-03-2005
Message 5 of 7 (120 Views)

Re: Sort using 4th element?

11-08-2012 08:23 AM in reply to: FarrenYoung

Great! Thanks again!

 

Maybe one day I'll be a mentor as well :smileywink:

 

Luc

Ludesroc
Employee
Posts: 44
Registered: ‎09-11-2007
Message 6 of 7 (112 Views)

Re: Sort using 4th element?

11-08-2012 02:52 PM in reply to: FarrenYoung

Farren's answer is correct.

 

Keep in mind though that the fourth function he wrote , using nth(4, mylist) does not work in the same way that first,second and third do, nth(4,{3,2,1}) returns 1 (i.e. the last element of the list), thirst({3,2}) returns novalue.  No difference if your lists have the correct number of entities of course.

 

Elly


--
Autodesk
Elly Bachrach
Solutions Architect
Autodesk Global Services
Direct +1 (847) 676-2880
elly.bachrach@autodesk.com

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Active Contributor
Chris_Rogers
Posts: 44
Registered: ‎06-22-2009
Message 7 of 7 (100 Views)

Re: Sort using 4th element?

11-09-2012 10:44 AM in reply to: ebachrach

The function below will cause it to work the same as :first, :second, and :third.

 

Function fourth(inList As List) As Any

    If length(inlist) < 4 then

         Return NoValue

    Else
        Return nth(4, inList)

    End If
End Function

-Chris Rogers
Inventor Certified Professional
________________________________________________________
If this post helps, please click the "Thumbs up"/"Kudos"
If this post gives the solution, please click "Accept as Solution"

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
Manufacturing Community
The Manufacturing Community provides additional access to tips, tutorials, blogs and networking with peers.

Need installation help?

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

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube