Page 1 of 1

PHP script to sort the duplicated material in Rhino MTL file

Posted: Thu Jun 23, 2011 7:29 am
by tom_holly
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.

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
  }
?>
Cheers, Tom

Re: PHP script to sort the duplicated material in Rhino MTL file

Posted: Thu Jun 23, 2011 7:57 am
by Daniel79
hi, if is possible you can tell me how create file .rvb(script) and how load into rhino? Work on rhino 5wip or only for v.4?
you could make a tutorial explaining how to load the script and maybe how it is used?
Thanks a lot

Re: PHP script to sort the duplicated material in Rhino MTL file

Posted: Thu Jun 23, 2011 8:50 am
by tom_holly
Hello,

Sorry, I have no experience of RVB scripts.

The PHP script is only to remove duplicate material nodes when exporting from Rhino 4.0.

Cheers, Tom

Re: PHP script to sort the duplicated material in Rhino MTL file

Posted: Thu Jun 23, 2011 12:36 pm
by tom_holly
I've uploaded a script to remove and sort the duplicate materials in MTL files when exporting OBJ files from Rhino 3D.

It works for Rhino 4. It may or may not work for other versions.

This is not fully tested, so use at your own risk.

You may post any bugs to me here: http://www.refractivesoftware.com/forum ... =41&t=7044

http://rhino-3d-obj-mtl-fix.zzl.org/

Cheers, Tom