FEW SCRIPTS

Share your scripts with other members
User avatar
bolek
Posts: 121
Joined: Thu Nov 27, 2008 10:24 am
Contact:

FEW SCRIPTS

Postby bolek » Fri Jul 30, 2010 11:23 pm

Hello

I made few scripts just for fun and to learn some python conversations :}

First one is simple distance finder based on "float distance( Vector )" function



Code: Select all

# Name         : distanceFinder
# Icon         : distFind.png
# Author      : Marcin KÅ‚usek `BOLEK`
# Website      : http://bolekcg.blogspot.com/
# Date         : 2009
# Version:      : 1.0

def main():

#var   
   sel = scene.getSelectedNodes()
   selCount = len(sel)


# count of selected object testing

   if (selCount != 2):
      scene.message("Selection must appear with two nodes")
      return()
      
   else:
      objOne = sel[0]
      objTwo = sel[1]
      posObjOne = objOne.getParameter("Position")
      posObjTwo = objTwo.getParameter("Position")
      dist = posObjOne.distance(posObjTwo)
      
      if(dist != 0):
         scene.message(str(dist))
         return()
         
      else:
         scene.message("Position is the same")
main()

Next script will set yours export directories on a basis of scene name (if you set useSceneName to YES) node name and exported object type. There is possibility to set export folders for all scene nodes or just for few selected.

Code: Select all

# Name         : setProjectFolders
# Icon         : setProjectFolders.png
# Author      : Marcin KÅ‚usek `BOLEK`
# Website      : http://bolekcg.blogspot.com/
# Date         : 2010_07
# Version:      : 1.1

def main():

#variables
   sel = scene.getSelectedNodes()
   selCount = len(sel)
   scn = scene.getNodes()
   scnCount = len(scn)
   scnName =scene.getFileName()
   objS = []
   alert = GUIMessageDialog.new()
   fileName = scnName.rsplit(".",1)
   setFolder = ""

#checking for any object in the scene
   if(scnCount == 0 ):
      alert.show(ALERT_TYPE_INFORMATION, "No objects in the scene" )
      scene.message(str("No objects in the scene"))
      return()

#GUI
   gFD = GUIFormDialog.new()
   options = ["Selected", All]
   gFD.addListField("SetFolderFor", options, 1)
   gFD.addBoolField("UseSceneName", False)

   if(gFD.show() == GUI_DIALOG_ACCEPTED):
      sFFOpt = options[gFD.getFieldValue(SetFolderFor)]
      uSNOpt = gFD.getFieldValue("UseSceneName")
   else:
      scene.message("Cancel by user")
      return()
#sFFOpt testing / All scene nodes or just selected one(else)
   if(sFFOpt == "All"):
      objS = scn
   else:
#checking selected nodes count
      if(selCount != 0):
         objS = sel
      else:
         alert.show(ALERT_TYPE_INFORMATION, "No objects selected")
         scene.message(str("No objects selected"))
         return()

#checking if use or do not use scene name in export path
   if(uSNOpt):
      setFolder = fileName[0] +"/"
   else:
      setFolder = setFolder
         

#object filtering
   camList = filter(lambda x: x.getType()== TYPE_CAMERA, objS)
   camOpt = [EXPORT_CAMERA_ANIMATION]
   objList = filter(lambda x: x.getType()== TYPE_OBJECT, objS)
   objOpt = ["EXPORT_ANIMATION_SD", EXPORT_WETMAP, '2' ]#2 = obj
   emiList = filter(lambda x: x.getType()== TYPE_EMITTER, objS)
   emiOpt = ["EXPORT_PARTICLES_BIN", "EXPORT_PARTICLES_ASC", "EXPORT_PARTICLES_PDC", EXPORT_PARTICLES_PD]
   daeList = filter(lambda x: x.getType()== TYPE_DAEMON, objS)
   daeOpt = ["EXPORT_TEXTURE", EXPORT_DATA]
   mesList = filter(lambda x: x.getType()== TYPE_MESH, objS)
   mesOpt = ["EXPORT_MESHES_BIN", "EXPORT_MESHES_LWO", EXPORT_MESHES_OBJ, '2' ]#2 = md
   rwaList = filter(lambda x: x.getType()== TYPE_REALWAVE, objS)
   rwaOpt = ["EXPORT_SURFACE_DEFORMATION_SD", "EXPORT_SURFACE_DEFORMATION_LW", "EXPORT_SURFACE_DEFORMATION_BIN", EXPORT_FOAM_TEXTURE]
   #scnOpt = [1: EXPORT_SCENE_ANIMATION_SD ,2 :EXPORT_PREVIEW] /


#export cameras
   for i in camList:
      for o in camOpt:
         i.setExportResourcePath(eval(o), '$(SCENEDIR)/cameras')

#objects animation and obj
   for i in objList:
      for o in objOpt:
         i.setExportResourcePath(eval(o), '$(SCENEDIR)/objects/' +setFolder +i.getName())
#export object wetmaps
      i.setExportResourcePath(eval(objOpt[1]), '$(SCENEDIR)/images/' +setFolder +i.getName())
#export softbody particles
      i.setExportResourcePath(3, '$(SCENEDIR)/particles/' +setFolder +i.getName())

#export particles
   for i in emiList:
      for o in emiOpt:
         i.setExportResourcePath(eval(o), '$(SCENEDIR)/particles/' +setFolder +i.getName())
#export meshes
   for i in mesList:
      for o in mesOpt:
         i.setExportResourcePath(eval(o), '$(SCENEDIR)/meshes/' +setFolder +i.getName())
#export realwave particles
   for i in rwaList:
      for o in emiOpt:
         i.setExportResourcePath(eval(o), '$(SCENEDIR)/particles/' +setFolder +i.getName())
#export realwave objects
      for e in rwaOpt:
         i.setExportResourcePath(eval(e), '$(SCENEDIR)/objects/' +setFolder +i.getName())
#export realwave left options
#particle layer
      i.setExportResourcePath(EXPORT_SURFACE_DEFORMATION_BIN, '$(SCENEDIR)/particles/' +setFolder +i.getName())
#foam texture
      i.setExportResourcePath(EXPORT_FOAM_TEXTURE, '$(SCENEDIR)/images/' +setFolder +i.getName())


#optional for color plane DAEMON / just delete three quotation marks
   '''
   for i in daeList:
      for o in daeOpt:
         i.setExportResourcePath(eval(o), '$(SCENEDIR)/daemons/' +setFolder +i.getName())
   '''

main()

Last is simmilar to second one, but you have to show export destination folder and type prefix name. It works only for one selected node.


Code: Select all

# Name         : setSelection
# Icon         : setSelection.png
# Author      : Marcin KÅ‚usek `BOLEK`
# Website      : http://bolekcg.blogspot.com/
# Date         : 2010_07
# Version:      : 1.0

def main():
#get scene's root path
   sceneDir = scene.getRootPath()
# get selected nodes
   selNodes = scene.getSelectedNodes()
#options for "gui" (gui = GUIFormDialog.new())
   curOption = ['']
#gui defining | setFolder gui | alert gui | gFPD = acronym from function save gui
   gui = GUIFormDialog.new()
   alertGui = GUIMessageDialog.new()
   gFPD = GUIFilePickerDialog.new()
#missing export resource path arguments
   EXPORT_MESHES_MD = 2
   EXPORT_GEOMETRY_OBJ = 2

#test for count of selected nodes / there must be one selected instead you will get alert

   if(len(selNodes) == 0):
      alertGui.show( ALERT_TYPE_INFORMATION, "Select one node" )
      return()
   elif(len(selNodes) == 1):
      obj = selNodes[0]

#list of export possibilities on the basis of the gathered information(object type)

      cameraOptions = [EXPORT_CAMERA_ANIMATION]
      daemonOptions = ["EXPORT_TEXTURE", EXPORT_DATA]
      particlesOptions = ["EXPORT_PARTICLES_BIN", "EXPORT_PARTICLES_ASC", "EXPORT_PARTICLES_PDC", EXPORT_PARTICLES_PD]
      meshOptions = ["EXPORT_MESHES_BIN", "EXPORT_MESHES_LWO", "EXPORT_MESHES_OBJ", EXPORT_MESHES_MD]
      objectOptions = ["EXPORT_ANIMATION_SD", "EXPORT_WETMAP", EXPORT_GEOMETRY_OBJ ]
      realWaveOptions = particlesOptions + ["EXPORT_SURFACE_DEFORMATION_SD", "EXPORT_SURFACE_DEFORMATION_LW", "EXPORT_SURFACE_DEFORMATION_BIN", EXPORT_FOAM_TEXTURE]
      sceneOptions = ["EXPORT_SCENE_ANIMATION_SD",EXPORT_PREVIEW]


#switch(case = type object)
      
      if(obj.getType() == TYPE_CAMERA):
         curOption = cameraOptions
      elif(obj.getType() == TYPE_DAEMON):
         curOption = daemonOptions
      elif(obj.getType() == TYPE_EMITTER):
         curOption = particlesOptions
      elif(obj.getType() == TYPE_MESH):
         curOption = meshOptions
      elif(obj.getType() == TYPE_OBJECT):
         curOption = objectOptions
      if(obj.getType() == TYPE_REALWAVE):
         curOption = realWaveOptions
      else:
         curOption = curOption

#selection printing
      scene.message(obj.getName() +" was selected")

#else for testing count of sel. nodes
   else:
      alertGui.show( ALERT_TYPE_INFORMATION, "Selection must appear with only one node")
      return()

#Set Folder For- gui showing | if accepted go to the next line of code otherwise it stops executing script

   gui.addListField("Set Folder For", curOption, 0)
   if(gui.show() == GUI_DIALOG_ACCEPTED):
      res = curOption[gui.getFieldValue(Set Folder For)]
      pass
   else:
      scene.message("Canceled by user")
      return()

#setting destination directory for exporting if = cancel operation else = setName | emResId = Emitter's resource Id.
   savedPath = gFPD.show(FILE_PICKER_SAVE, sceneDir, "fileName", (res) +" FOLDER")
   if(savedPath == ""):
      scene.message("Canceled by user")
      return()
   else:
      (savePath, saveName) = savedPath.rsplit("/",1)
      isTheSame = savedPath.find(sceneDir)
#test for the output path, if you type path that begining is scene root path, you will get savePath variable equal $(SCENEDIR)/xxx instead of sceneDir/xxx
      if(isTheSame != 0):
         savePath = savePath
      else:
         savePath = savePath.replace(sceneDir, "$(SCENEDIR)")

      obj.setExportResourcePath(eval(res), savePath)
      obj.setExportResourceName(saveName)

#printing results
      scene.message("ExportPath for " +obj.getName() +" was set to " +savePath +" with " +saveName +" name")
main()

Download archive from rapidshare- there are also icons.

RAPID


Again- sorry for language :}

CHEERS
____________________________________________
http://vimeo.com/bolekcg
http://bolekcg.blogspot.com/


User avatar
tmdag
Posts: 1023
Joined: Thu Jun 28, 2007 2:22 pm
Location: New Zealand
Contact:

FEW SCRIPTS

Postby tmdag » Fri Jul 30, 2010 11:25 pm

fantastic! thanks for sharing!
"Do not feed the trolls"
Albert 'tmdag' Szostkiewicz
FX Technical Director
Weta Digital

User avatar
Vitor Teixeira
Posts: 312
Joined: Thu Jul 23, 2009 1:47 pm
Location: Porto, Portugal
Contact:

FEW SCRIPTS

Postby Vitor Teixeira » Sat Jul 31, 2010 12:05 am

This is fantastic but yet I'm not able to understand what it does exactly.
Cheers

User avatar
bitSeq
Posts: 1044
Joined: Thu Jul 10, 2008 9:48 am
Location: UK - Stuart Armiger
Contact:

FEW SCRIPTS

Postby bitSeq » Tue Mar 08, 2011 4:45 pm

The versioning script is good, it would be really great if it renamed all of the mesh, particle and realwave nodes also.

User avatar
bolek
Posts: 121
Joined: Thu Nov 27, 2008 10:24 am
Contact:

FEW SCRIPTS

Postby bolek » Wed Mar 09, 2011 3:04 pm

Czesc i czołem ( Hello )

Maybe I will rewrite that script to RF 5 soon. Be patient.

____________________________________________
http://vimeo.com/bolekcg
http://bolekcg.blogspot.com/

User avatar
bolek
Posts: 121
Joined: Thu Nov 27, 2008 10:24 am
Contact:

FEW SCRIPTS

Postby bolek » Sat Apr 16, 2011 10:52 pm

Czołem.

"The versioning script is good, it would be really great if it renamed all of the mesh, particle and realwave nodes also"

Yes... It would be. :) I was thinking about it, but what about crazy scene names ?. I mean that to rename scene nodes you have to work with concrete naming convention. e.g. scene_001 > scene_002 etc. or write "longer" script with "re" module or other posibilites of python.

I think simpler way is to rename nodes by yourself or using Renamer

____________________________________________
http://vimeo.com/bolekcg
http://bolekcg.blogspot.com/


Return to “User Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest