# Input float value from csv in Hypershade utility via mel/python script

**URL:** https://forum.highend3d.com/t/input-float-value-from-csv-in-hypershade-utility-via-mel-python-script/154952
**Category:** Maya
**Tags:** mel, python
**Created:** [February 8, 2018, 9:08am UTC](https://forum.highend3d.com/t/input-float-value-from-csv-in-hypershade-utility-via-mel-python-script/154952 "2018-02-08T09:08:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kanoute](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/k/90db22/32.png) [@kanoute](https://forum.highend3d.com/u/kanoute)
#### Post date: [February 8, 2018, 9:08am UTC](https://forum.highend3d.com/t/input-float-value-from-csv-in-hypershade-utility-via-mel-python-script/154952/1 "2018-02-08T09:08:59Z")

</div>

Hi,

My problem is that I want to take a float value from a csv file. I want to put this float value, in the hypershade utility “floatConstant”. Especially in the “float” box. I want to do this by Mel/ Python.

The first part , how i can take the value from the csv I think that i am near. I think the MEl code is

//  
string $fileName = “c:/temp/test.csv”;  
int $fileId = `fopen $fileName "r"`;  
//

. Do anybody know how i can do that?

---

<div class="post-metadata">

### Author: ![bfx](https://forum.highend3d.com/user_avatar/forum.highend3d.com/bfx/32/3_2.png) [@bfx](https://forum.highend3d.com/u/bfx)
#### Post date: [February 8, 2018, 3:39pm UTC](https://forum.highend3d.com/t/input-float-value-from-csv-in-hypershade-utility-via-mel-python-script/154952/2 "2018-02-08T15:39:30Z")

</div>

Interesting question. Most definetly you want to do this with python. I’ll ha e a look tomorrow if someone else doesn’t have the answer readily available.

---

<div class="post-metadata">

### Author: ![nnnight](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/c2a13f/32.png) [@nnnight](https://forum.highend3d.com/u/nnnight)
#### Post date: [February 8, 2018, 6:05pm UTC](https://forum.highend3d.com/t/input-float-value-from-csv-in-hypershade-utility-via-mel-python-script/154952/3 "2018-02-08T18:05:54Z")

</div>

Hi

Below is my code  
/////////////////////////////////////////////////////////////////////////  
global proc float[] get\_float\_from\_csv(string $csv)  
{  
if (!`file -q -ex $csv`)  
{  
error ("File is not found : " + $csv);  
return {};  
}

```
float $float_values[];

string $lines[] = `freadAllLines $csv`;
for ($line in $lines)
{
    string $elements[] = `stringToStringArray $line ","`;
    for ($elem in $elements)
    {

        string $match_float = `match "[0-9]+.[0-9]+" $elem`;
        if (`size $match_float` == 0)
        {
            continue;
        }
        $float_values[size($float_values)] = (float)$elem;
    }
}
return $float_values;

```

}  
string $csv = “D:/Temp/floatvalue.csv”;  
float $float\_values[] = `get_float_from_csv $csv`;  
print $float\_values;  
/////////////////////////////////////////////////////////////////////////  
Chiaxin
