CGTalk > Software > Maxon Cinema 4D
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 05-01-2013, 07:21 PM   #1
Aurety
Expert
 
Aurety's Avatar
portfolio
Antoine Aurety
LEV COMMUNICATION
LORIENT, France
 
Join Date: Sep 2002
Posts: 746
SearchBitmap Python script by Oli_D

Hi, a little heads up for a nice script by Oli_D, a well known member in Frenchcinema4D forum...

This python script is really usefull!
You know the name of an image but how to find it among all the materials that you created .. With this script, you give the name of the image, and is ready for selecting all materials / shaders that use this file. Simple as that!

Thanks Oli_D !!
Code:
import c4d import os.path def searchBitmap(shd, liste): 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 main(): nom_img = c4d.gui.InputDialog("Put the name of the pîcture :") mat = doc .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() if __name__=='__main__': main()
__________________
Frenchcinema4D Moderator http://www.frenchcinema4d.fr
my website : http://www.lev-communication.fr
Kamigaz® Project on : Pinterest
 
Old 05-02-2013, 12:46 PM   #2
Jops
hyper nerd
Florian Sepp
Germany
 
Join Date: Mar 2005
Posts: 341
wow thats great for broken links.

thanks a lot.
Jops
 
Old 05-02-2013, 02:04 PM   #3
Aurety
Expert
 
Aurety's Avatar
portfolio
Antoine Aurety
LEV COMMUNICATION
LORIENT, France
 
Join Date: Sep 2002
Posts: 746
exactly ! I hate to check each material/shader to find exactly where i put these f#&cK@ng picture :-)
Thanks for the reply..
__________________
Frenchcinema4D Moderator http://www.frenchcinema4d.fr
my website : http://www.lev-communication.fr
Kamigaz® Project on : Pinterest
 
Old 05-02-2013, 03:47 PM   #4
olid
New Member
portfolio
Olivier Donzé
hepia
Geneva, Switzerland
 
Join Date: Nov 2009
Posts: 2
for broken links it's better to use this method
 
Old 05-02-2013, 03:51 PM   #5
Aurety
Expert
 
Aurety's Avatar
portfolio
Antoine Aurety
LEV COMMUNICATION
LORIENT, France
 
Join Date: Sep 2002
Posts: 746
A nice update from Oli_D
Now the plugin return all the pictures used in the materials inside a menu list.


Code:
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) return if __name__=='__main__': main()
__________________
Frenchcinema4D Moderator http://www.frenchcinema4d.fr
my website : http://www.lev-communication.fr
Kamigaz® Project on : Pinterest
 
Old 05-04-2013, 08:02 AM   #6
ymmij
New Member
portfolio
Russ Maehl
noen
Neutral Bay, AU
 
Join Date: Mar 2010
Posts: 14
I am getting this error:

File "scriptmanager",line 2
import os.path
^
IndentationError:unexpected indent

Any ideas?
 
Old 05-04-2013, 08:08 AM   #7
NiklasR
Expert
 
NiklasR's Avatar
portfolio
Niklas Rosenstein
Germany
 
Join Date: Jan 2011
Posts: 437
The board often messes up the indentation, here's a clean version: http://pastebin.com/n6W6ne9S

Btw, there is missing a line: c4d.EventAdd() at the end of the script. I've added it here: http://pastebin.com/jHqPCFS7
__________________
Cinema 4D Plugin Developer
niklasrosenstein.com/ | Freebies | Plugins

Last edited by NiklasR : 05-04-2013 at 08:19 AM.
 
Old 05-04-2013, 08:24 AM   #8
ymmij
New Member
portfolio
Russ Maehl
noen
Neutral Bay, AU
 
Join Date: Mar 2010
Posts: 14
Thanks for the quick response.

All fixed and working well.

This is a great tool, and just have to wonder why such things are not built in to the software.

Thanks again.
 
Old 05-04-2013, 01:39 PM   #9
Shane W
PRO
 
Shane W's Avatar
Shane Wiersma
oddlyeven
USA
 
Join Date: Nov 2002
Posts: 198
Thanks for sharing this, it works great.
 
Old 05-04-2013, 01:39 PM   #10
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,480
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:02 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.