PHP script to sort the duplicated material in Rhino MTL file

Rhino 3D (Export script developed by SamPage; Integrated Plugin developed by Paul Kinnane)

Moderator: face_off

Post Reply
tom_holly
Licensed Customer
Posts: 24
Joined: Thu Feb 24, 2011 2:41 pm

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
Last edited by tom_holly on Thu Jun 23, 2011 8:48 am, edited 1 time in total.
AMD Athlon(tm) II X4 640 @ 3.0 HGz | 4.00 GB | Octane beta 2.44 | Rhino V4 SR9 | Windows Vista x64 | GTX 570
User avatar
Daniel79
Licensed Customer
Posts: 451
Joined: Tue Jan 26, 2010 3:53 pm
Location: Italy

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
SORRY, MY ENGLISH IS BAD!
2 Xeon quad core E5440_8gb Ram_Nvidia GeForce 2GTX 780ti 3Gb/Nvidia Quadro K2000_Win10 64bit_Octane 3.02_Rhinoceros3D
tom_holly
Licensed Customer
Posts: 24
Joined: Thu Feb 24, 2011 2:41 pm

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
AMD Athlon(tm) II X4 640 @ 3.0 HGz | 4.00 GB | Octane beta 2.44 | Rhino V4 SR9 | Windows Vista x64 | GTX 570
tom_holly
Licensed Customer
Posts: 24
Joined: Thu Feb 24, 2011 2:41 pm

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
AMD Athlon(tm) II X4 640 @ 3.0 HGz | 4.00 GB | Octane beta 2.44 | Rhino V4 SR9 | Windows Vista x64 | GTX 570
Post Reply

Return to “Rhinoceros 3D”