PHP script to sort the duplicated material in Rhino MTL file
Posted: Thu Jun 23, 2011 7:29 am
Hi Folks,
Here's a quick bit of PHP that processes the contents of an MTL file from Rhino which contains duplicated materials, removes duplicates and sorts alphabetically.
I have only used the script on Linux.
Use it at your own risk! Not tested it much, but on the few MTL files I have used it with, it work.
Cheers, Tom
Here's a quick bit of PHP that processes the contents of an MTL file from Rhino which contains duplicated materials, removes duplicates and sorts alphabetically.
I have only used the script on Linux.
Use it at your own risk! Not tested it much, but on the few MTL files I have used it with, it work.
Code: Select all
<title>Rhino MTL sorter</title>
<h1>Rhino MTL sorter</h1>
<?php
if (isset($_POST['submit'])) {
$name = base64_encode($_POST['name']);
$name = base64_decode($name);
echo "<h2>Duplicates removed and sorted alphabetically</h2>";
$Content = $name;
$Content = str_replace("# Rhino\r\n", "", $Content);
$Content = str_replace("\r\n\r\n", "\n", $Content);
///$Content = nl2br(str_replace("\r\n", "|", $Content));
$Content = str_replace("\r\n", "|", $Content);
$lines = explode(PHP_EOL, $Content);
$uniquelines = (array_unique($lines));
natcasesort($uniquelines);
?>
<textarea rows="30" cols="50">#Rhino.php sorted<?php
foreach ($uniquelines as $key => $val) {
echo(str_replace("|", "\n", $val) . "\n\n");
}
?></textarea><?php
} else {
echo "<h2>Paste contents of unsorted MTL file below</h2>";
?>
<form method="post" action="<?php
echo $_SERVER['PHP_SELF'];
?>">
<textarea rows="30" cols="50" name="name"></textarea><br>
<input type="submit" name="submit" value="Submit Form"><br>
</form>
<?php
}
?>