import os
import sys
import c4d

from c4d import plugins, utils, bitmaps, gui
from c4d.plugins import ObjectData

PLUGIN_ID = 1028487

def GetChilds(child):
    		children=[]
    		children.append(child)
    		if child.GetDown() != None:
        		for kid in child.GetChildren():
               			children.extend(GetChilds(kid))
    		return children

class GSGTransform(ObjectData):

	def __init__(self):
		self.SetOptimizeCache(False)
	
	def Init(self, op):
		
		return True		
	def GetVirtualObjects(self, op, hierarchyhelp) :
		ret = c4d.BaseObject(c4d.Onull)
		if op.GetDown() != None and op[c4d.ID_USERDATA,3] == True:
			ObjectType = (op.GetDown()).GetType()
			#if (ObjectType != 1018544 and ObjectType != 1018545 and ObjectType != 1018791 and ObjectType != 1019268 and ObjectType != 440000054 and ObjectType != 1019358 and ObjectType != 1019222):
			op.NewDependenceList()
			ObjList =[]
				
			ObjList.extend(GetChilds(op.GetDown()))
			for x in range(len(ObjList)):
	 			op.AddDependence(hierarchyhelp, ObjList[x])
	 		op.TouchDependenceList()

		return ret

if __name__ == "__main__":
    dir, file = os.path.split(__file__)
    icon = bitmaps.BaseBitmap()
    icon.InitWith(os.path.join(dir, "res", "icon.tif"))
    plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="Z_Plugin_GSG_Transform",
                                g= GSGTransform,
                                description="GSGTransform", icon=icon,
                                info=c4d.OBJECT_GENERATOR|c4d.PLUGINFLAG_HIDEPLUGINMENU)
