Two useful Blender scripts for those ilegal characters users

Forums: Two useful Blender scripts for those ilegal characters users
Post, discuss and share handy resources like textures, models and HDRI maps in this forum.
Forum rules
Please do not post any material that is copyrighted or restricted from public use in any way. OTOY NZ LTD and it's forum members are not liable for any copyright infringements on material in this forum. Please contact us if this is the case and we will remove the material in question.

Two useful Blender scripts for those ilegal characters users

Postby Curious guy » Wed May 05, 2010 1:56 am

Curious guy Wed May 05, 2010 1:56 am
Hi: Since I'm a Spanish user I use ñ, á,é,í,ó,ú and spaces quite a lot. I'm getting some errors with octane that Im unsure if they are related to characters or someting else.
So the solution is to change the materials and images names, but for +200 materials It's a tedious and inefficient task. So a script is better, even If I fail several times trying to get it work :mrgreen: .

Procedure:
- Copy the script and paste it into your blender text editor
- Fill in variables the characters you want to replace (can be a combination of characters too).
- Hit Alt + p
- (This applies to the texture script) Change the names of your images in your HDD using other batch renaming program. (like Filetools or File Comander)

Here is the material script:
Code: Select all
# Material name changer, useful in case sensitive programs
# Made by CGgap in blendeartist, Curious Guy in Octane forums
#Known issues:
#            - Takes all scene materials (not only the ones from selected objects)

# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

############## Variables #####################
# Tipe the character you want to change (Between the quotemarks)
old = " "
# Tipe the character that will replace the old one (Between the quotemarks)
new = "_"
##############################################

import Blender
from Blender import Material

print "--------------------------------------"
Mat = Material.Get()
leM = len(Mat)
for Cma in range( 0, leM, 1 ):
   Smat = Mat[Cma]
   MatName = Smat.getName()
   NewMat = MatName.replace(old,new)
   Smat.setName(NewMat)
   print "Changed " +MatName+ " -> " + NewMat + "   ...Or didn't?"


And the texture script:
Code: Select all
# Image texture name changer, useful in case sensitive programs
# Made by CGgap in blendeartist, Curious Guy in Octane forums
#Known issues:
#            - Your blender image name must be equal to your HDD image name
#            - Mess with your images names (resets them)
#            - Takes all scene images textures (not only the ones from selected objects)

# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

############## Variables #####################
# Tipe the character you want to change (Between the quotemarks)
old = " "
# Tipe the character that will replace the old one (Between the quotemarks)
new = "_"
##############################################

import Blender
from Blender import Texture,Image,Material

print "--------------------------------------"
Mat = Material.Get()
leM = len(Mat)
for Cma in range( 0, leM, 1 ):
   Smat = Mat[Cma]
   Ltex = Smat.getTextures()
   ET = Smat.enabledTextures
   for Ntex in ET:
      Tsel = Ltex[Ntex]
      if Tsel.tex.type == Texture.Types.IMAGE:
         Img = Tsel.tex.getImage()
         Imgname = Img.getName()
         Imgpath = Img.getFilename()
         Newname = Imgname.replace(old,new)
         Newpath = Imgpath.replace(Imgname,Newname)
         Img.setName(Newname)
         Img.setFilename(Newpath)
         
         print "Changed " +Imgname+ " -> " + Newname + "   ...Or didn't?"


Please note that the image script in order to work properly, the image name in blender must be the same as in the HDD.

Feel free to use and modify.

EDIT: Missed a line in the first code
3 x Geforce GTX470 | i7 960 | MB x58 classified 4 way sli | Win 7 64bit | 6Gb | Driver 257.21
Curious guy
Licensed Customer
Licensed Customer
 
Posts: 33
Joined: Mon Feb 22, 2010 4:19 am

Re: Two useful Blender scripts for those ilegal characters users

Postby kubo » Tue May 18, 2010 8:19 am

kubo Tue May 18, 2010 8:19 am
Thanks mate, that'll come really handy,
Un abrazo
windows 7 x64 | 2xGTX570 (warming up the planet 1ºC at a time) | i7 920 | 12GB
User avatar
kubo
 
Posts: 1377
Joined: Wed Apr 21, 2010 4:11 am
Location: Madrizzzz

Return to Resources and Sharing


Who is online

Users browsing this forum: No registered users and 10 guests

Thu Mar 28, 2024 2:21 pm [ UTC ]