Sort numbers from excel file

Q and A about functionality and how to solve a special task for your application.

Sort numbers from excel file

Postby ahmedahmed1223 » 05 May 2017, 21:17

hi there
Is there any simple way to sort numbers from small to big imported for example from excel sheet or text file?
also how to sort the numbers is there text linked to it? like team A score 50 point. Team B score 20 point etc. :?:
ahmedahmed1223
 
Posts: 43
Joined: 07 Jan 2017, 14:02

Re: Sort numbers from excel file

Postby u-double-u » 06 May 2017, 19:21

u-double-u
 
Posts: 40
Joined: 03 Dec 2014, 15:46

Re: Sort numbers from excel file

Postby ahmedahmed1223 » 06 May 2017, 19:38

I have think about this option ,but I need to sort values in ventuz not office.
So is there any tools in ventuz can do the job ?
ahmedahmed1223
 
Posts: 43
Joined: 07 Jan 2017, 14:02

Re: Sort numbers from excel file

Postby Christian Krix Schmidt » 06 May 2017, 20:18

That is a very specific task and usually needs to be customized to fit a specific need. You can use the C# node, input the values in it in an array and then sort the array there and output the values again. It's only a few lines of code to get it done. There is a C# array sort method for specifically that usage. https://msdn.microsoft.com/en-us/library/system.array.sort(v=vs.110).aspx
Christian Krix Schmidt
 
Posts: 270
Joined: 18 Jan 2012, 11:36
Location: Dubai, United Arab Emirates

Re: Sort numbers from excel file

Postby ahmedahmed1223 » 06 May 2017, 20:39

thanks u-double-u and Christian Krix Schmidt but I am not programmer.
To be honest I need to recreate this scene in ventuz :D
https://youtu.be/RamDBQHU3tU?t=6m26s
It was created in other cg software I think.
So is there any other ideas ? :?:
ahmedahmed1223
 
Posts: 43
Joined: 07 Jan 2017, 14:02

Re: Sort numbers from excel file

Postby Christian Krix Schmidt » 07 May 2017, 03:43

Oh my. That is a really complicated setup in that example for just 5 values. What if you have to sort 10 or 20 values?
So the best way of doing this - and being able to have any number of numbers/names to sort would be to use a little C# script. Would be perfect.
Without a script you could read out every cell and then start sorting them manually using little expressions. A lot of nodes for a very limited number of entries.

I would recommend a really simple alternative. Bind the Excel cells with the names fixed. First row in Excel is first row in Ventuz, 2nd is 2nd, etc. for all your names.
Go into Excel. You will be editing it anyway. Select all your names and values. From the Excel Data menu select Sort. Select which Column you want to sort by and the order of the output. Click OK. Press Save and Ventuz is updated as well.
Attached is a screenshot of Excel with the Sort menu open. Super simple and quick. No logic required in Ventuz.

Hope that helps to solve your problem.
Chris
Attachments
ExcelSort.jpg
Christian Krix Schmidt
 
Posts: 270
Joined: 18 Jan 2012, 11:36
Location: Dubai, United Arab Emirates

Re: Sort numbers from excel file

Postby ahmedahmed1223 » 07 May 2017, 21:58

Thanks Christian ,
but i need to do the sorting thing in ventuz not in excel.
So is there any suggestion about ventuz Tools that can help in doing this scene?
ahmedahmed1223
 
Posts: 43
Joined: 07 Jan 2017, 14:02

Re: Sort numbers from excel file

Postby Christian Krix Schmidt » 07 May 2017, 22:50

Anything besides a script is equally cumbersome and limited like the Expression example in the youtube video. The best way is to open the Excel file in C# and parse it. I can highly recommend you either learn a bit about scripting or find someone who can help you with that. In the meantime, I created a rough solution for you. Attached is an archive with scene and Excel file. The scene reads out 8 rows of values and names from an Excel manually. I never programmed an Excel connection in C# and I didn't want to learn it just for this example. So I used regular nodes to read the data from Excel. That should make things easier for you as well. And there is a little C# script which sorts the data and outputs the result. The script is super basic and probably not very well coded. Doesn't really matter. It gets the job done. With the basic setup done you should be able to extend it if you need more than 8 values.

Hope that helps with your project.
Chris
Attachments
ExcelSort.vza
(18.42 KiB) Downloaded 41 times
Christian Krix Schmidt
 
Posts: 270
Joined: 18 Jan 2012, 11:36
Location: Dubai, United Arab Emirates

Re: Sort numbers from excel file

Postby ahmedahmed1223 » 07 May 2017, 23:11

thanks Chris :D
ahmedahmed1223
 
Posts: 43
Joined: 07 Jan 2017, 14:02

Re: Sort numbers from excel file

Postby Eric_RD » 09 May 2017, 16:24

I haven't read everything but:
you can sort an Array without a script:
macke a new string expression
Edit custom Model->delete all inputs->create a new float array input named "NumbersArray"->create a bool Input named "Reverse".
add the following text as expression (including the brackets)
Code: Select all
{
Array.Sort(NumbersArray);
if(Reverse)Array.Reverse(NumbersArray);
return String.Join("\r\n",NumbersArray);
}

create a string splitter node and connect it to the output of the string expression
connect you array (int or float) to the NumbersArray of the string expression
works as well for string arrays (just change the float array to string array)
done
you now have a sorted array and with the reverse bool you can set it from ascending to descending
User avatar
Eric_RD
 
Posts: 61
Joined: 04 Jun 2014, 14:01

Next

Return to How to

cron