Being an avid NURBS modeler, I find myself running the same commands over and over when importing my models into Cinema 4D to set them up the way I think they ought to be. Simple stuff like, re-center the axis to the individual parts, and reset the phong angle (as the default is 80 degrees which is just silly) to something a little more reasonable (like 20 degrees).

To really make this work without a hitch, first set the Wavefront Import options inside Cinema to ignore the normals tag (since I was a little too lazy to worry about checking and deleting it).

Fire up the Script manager, and start a new script. Copy and paste the following script into the script manager (and save it).

Now, as soon as you open new wavefront/obj file (you can merge your obj file as well, but it better be in a clean document), you can just execute the script and it’ll fix all those little annoyances with the model in a single click.

// GetNextHierarchyObject
//        Loops through all objects, regardless of hierarchy
//        function by Mikael Sterner
GetNextHierarchyObject(obj, stopAt)
{
  if (!obj) return NULL;

  var next;
  if (next = obj->GetDown()) return next;
  if (next = obj->GetNext()) return next;

  var up = obj;
  while (up = up->GetUp())
  {
    if (up == stopAt) return NULL;
    if (next = up->GetNext()) return next;
  } 
}

main(doc,op)
{
    CallCommand(12113);        // Deselect All
    CallCommand(12298);     // Model
    CallCommand(12112);     // Select All
    CallCommand(12148);     // Frame Scene
    CallCommand(1011982); // Center Axis
    CallCommand(12113);     // Deselect ALL

    var obj = doc->GetFirstObject();
    while(obj)
    {
        var tag = obj->GetFirstTag();
        if(!tag) return;
        while(tag->GetType()!=Tphong)
        {
            tag=tag->GetNext();
            if(!tag) return;
        }
        var bc = obj->GetContainer();
        obj->SetContainer(bc);
        tag#PHONGTAG_PHONG_ANGLE=0.34906;
        obj = GetNextHierarchyObject(obj,NULL); 
    }

    CallCommand(12112);     // Select All
    CallCommand(100004772); // Group Objects
   object()#ID_BASELIST_NAME="Assembly";

    CallCommand(12113); // Deselect All
}

I’ll probably continue to develop this script a little further when time allows. I’d like it to track down normal tags if present and delete them and put something in there that will allow it to function with the open command (it flakes out when ya do that now) and a couple of other little things to make it even more handy. For now, it’s a start.

See…eventually I can get back on track!

-AW

One Response to “Cinema 4D – C.O.F.F.E.E. OBJ Cleanup Script”

  1. derekpm says:

    Rather interesting. Has few times re-read for this purpose to remember. Thanks for interesting article. Waiting for trackback