restructure a projekt

On 21/02/2013 at 06:31, xxxxxxxx wrote:

Hi all,

I try to reduce data in a C4D File by combining Polygon-objects with the same material following in the structure dirctly after another.

I have some code that Works well but now I have a Problem.
Is there anybody who could help me? (for cash)

In my code:
Running thrue the structure works!
Finding materials works.
But when I find two objekts with equal material the plugin stops.
It seams to lose the actual objekt ?!?

Here is my code:

  
def walk(obj) :   
    if not obj: return   
    elif obj.GetDown() :   
        return obj.GetDown()   
    while obj.GetUp() and not obj.GetNext() :   
        obj = obj.GetUp()   
  
    print 'klick'   
    return obj.GetNext()   
  
def walk_thrue_projekt(doc) :   
    print 'walk_thrue_projekt START'      
    obj = doc.GetFirstObject()   
    zaehler = 0   
    c4d.CallCommand(13324)                            # Alles deselektieren   
    material1 = 'Leer'   
    print material1   
    gui.MessageDialog('Stop1')   
    while obj:   
        zaehler = zaehler + 1   
        print zaehler   
        print c4d.BaseObject.GetName(obj)                         # Objektname lesen und ausgeben   
        obj.SetBit(c4d.BIT_ACTIVE)   
        textureTag = obj.GetTag(c4d.Ttexture)                     # Lesen TextureTag des aktuellen Objektes   
        if not textureTag:                                        # wenn Material nicht vorhanden dann   
            print 'Kein Material-Tag gefunden'                    # nix tun   
            obj.DelBit(c4d.BIT_ACTIVE)                            # Wenn kein Material vorhanden dann deaktivieren   
        else:                                                     # wenn Material vorhanden dann   
            material2 = textureTag.GetMaterial()                  # Materialnamen auslesen   
            print material2                                       # Materialnamen ausgeben   
            print material1                                       # Materialnamen ausgeben   
            obj.SetBit(c4d.BIT_ACTIVE)                            # Objekt aktivieren   
            gui.MessageDialog('Stop2')   
            if material1 == material2:                            # Wenn material1 = maderial 2 dann:   
               gui.MessageDialog('zwei gleiche gefunden')   
               c4d.CallCommand(16768)                            # Objekte verbinden + Löschen   
               #return   
            else:                                                 # Wenn material1 != maderial 2 dann:   
#               c4d.CallCommand(13324)                            # Alles deselektieren   
               gui.MessageDialog('zwei ungleiche hintereinander gefunden')                 
               obj.DelBit(c4d.BIT_ACTIVE)                        # aktuelles Objekt aktivieren   
               material1 = material2   
        obj = walk(obj)   

To test the Plugin here is a testfile:
http://www.vision4d.de/downloads/001 Testscene klein.c4d

Thanks a lot