Page 1 of 2

Sort numbers from excel file

Posted: 05 May 2017, 21:17
by ahmedahmed1223
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. :?:

Re: Sort numbers from excel file

Posted: 06 May 2017, 19:21
by u-double-u

Re: Sort numbers from excel file

Posted: 06 May 2017, 19:38
by ahmedahmed1223
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 ?

Re: Sort numbers from excel file

Posted: 06 May 2017, 20:18
by Christian Krix Schmidt
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/librar ... .110).aspx

Re: Sort numbers from excel file

Posted: 06 May 2017, 20:39
by ahmedahmed1223
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 ? :?:

Re: Sort numbers from excel file

Posted: 07 May 2017, 03:43
by Christian Krix Schmidt
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

Re: Sort numbers from excel file

Posted: 07 May 2017, 21:58
by ahmedahmed1223
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?

Re: Sort numbers from excel file

Posted: 07 May 2017, 22:50
by Christian Krix Schmidt
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

Re: Sort numbers from excel file

Posted: 07 May 2017, 23:11
by ahmedahmed1223
thanks Chris :D

Re: Sort numbers from excel file

Posted: 09 May 2017, 16:24
by Eric_RD
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