Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import c4d
- import os.path
- class MonDlg(c4d.gui.GeDialog):
- """Dialogue pour le choix de l'image, avec liste dérouante de toutes les images
- utilisées dans les différents matériaux du doc"""
- def __init__(self,lst):
- self.lst = lst
- self.choix = lst[0]
- def CreateLayout(self):
- self.SetTitle("Selecteur de materiau par image ")
- self.GroupBegin(1000,flags=c4d.BFH_SCALEFIT, cols=2, rows=1)
- self.GroupBorderSpace(10, 10, 10, 0)
- self.AddStaticText(1001,name="Image : ", flags=c4d.BFH_MASK, initw=100)
- self.AddComboBox(1002,flags=c4d.BFH_MASK, initw=250)
- self.GroupEnd()
- self.GroupBegin(2000,flags=c4d.BFH_CENTER, cols=2, rows=1)
- self.GroupBorderSpace(10, 10, 10, 0)
- self.AddButton(2001, flags=c4d.BFH_CENTER, initw=100, name="OK")
- self.AddButton(2002, flags=c4d.BFH_CENTER, initw=100, name="Annuler")
- self.GroupEnd()
- return True
- def InitValues(self):
- for i,n in enumerate(self.lst):
- self.AddChild(1002,i,n)
- return True
- def Command(self,id,msg):
- if id==1002 :#choix dans la liste
- self.choix = self.lst[self.GetLong(1002)]
- if id==2001:#bouton ok
- selectMatImg(self.choix)
- self.Close()
- if id==2002:#bouton annuler
- self.Close()
- return True
- def searchBitmap(shd, liste):
- """fonction récursive qui renvoie une liste avec les noms des fichiers images
- utilisés dans le shader"""
- while shd:
- if shd.CheckType(c4d.Xbitmap):
- fn = shd[c4d.BITMAPSHADER_FILENAME]
- name = os.path.basename(fn)
- liste.append(name)
- searchBitmap(shd.GetDown(), liste)
- shd = shd.GetNext()
- def getListImg(docu=doc):
- """renvoie la liste de toutes les images contenue dasn les materiaux du doc"""
- res = []
- mat = docu .GetFirstMaterial()
- while mat:
- shd = mat.GetFirstShader()
- searchBitmap(shd, res)
- mat = mat.GetNext()
- res = list(set(res))
- return res
- def selectMatImg(nom_img, docu=doc):
- """selectionne les materiaux qui utilisent l'image"""
- if not nom_img : return
- mat = docu .GetFirstMaterial()
- while mat:
- lst = []
- shd = mat.GetFirstShader()
- searchBitmap(shd, lst)
- if nom_img in lst :
- mat.SetBit(c4d.BIT_ACTIVE)
- else : mat.DelBit(c4d.BIT_ACTIVE)
- mat = mat.GetNext()
- c4d.EventAdd()
- def main():
- imgs = getListImg(docu=doc)
- if not len(imgs):
- c4d.gui.MessageDialog("Il n'y a aucune image utilisée")
- return
- dlg = MonDlg(imgs)
- dlg.Open(c4d.DLG_TYPE_MODAL)
- c4d.EventAdd()
- return
- if __name__=='__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement