Batch Script - Meshing

Share your scripts with other members
User avatar
stascrash
Posts: 65
Joined: Tue Sep 18, 2012 8:21 pm
Location: World Wide Web
Contact:

Batch Script - Meshing

Postby stascrash » Wed Sep 26, 2012 8:16 pm

here is finished version, i am still tweaking it here and there,and thinking of additional functionality, if you have any ideas - shoot them here, i would love to experiment.

Code: Select all

# Batch Mesher v 1.0
# Author: Stas Poritskiy
# September 26, 2012
# This batch script offeres a GUI to select start/end/step
# to create meshes from generated particles. Stepping allows
# you to skip frames and see progression of the mesh over
# entire lengh of animation/simulation.
# Update viewport lets you freeze your view port updated, so
# meshing is done a little faster and it does not kill your machine

#Defining variables
guiList = ["No", "Yes"]
meshList = []
meshes = scene.getStandardMeshes()
for mesh in meshes:
   meshList.append(mesh.getName())
#Append "All" to allow all meshes
meshList.append("All")

meshPos = len(meshList)-1
makeMeshes = []
#Defining GUI form

guiForm = GUIFormDialog.new()
guiForm.setTitle("Batch Meshing by Stas Poritskiy")
guiForm.addListField("Select Mesh", meshList, 0)
guiForm.addIntField("Start Frame", 0)
guiForm.addIntField("End Frame", 200)
guiForm.addIntField("Step Frame", 10)
guiForm.addListField("Update Viewport", guiList, 0)

#If Dialog accepted - populate variables

if (guiForm.show() == GUI_DIALOG_ACCEPTED):

   #get meshes
   meshNodes = guiForm.getFieldValue("Select Mesh")
   startFrame = guiForm.getFieldValue("Start Frame")
   endFrame = guiForm.getFieldValue("End Frame")
   stepFrame = guiForm.getFieldValue("Step Frame")
   guiUpdate = guiForm.getFieldValue("Update Viewport")

   meshName = meshList[meshNodes]
   #If ALL meshes are selected
   if (meshNodes == meshPos):
      scene.message("You choose to make "+str(meshName)+ " meshes")
      for mNode in meshes:
         if (mNode.getType() == TYPE_STANDARD_MESH
                  or mNode.getType() == TYPE_RENDERKIT_MESH
                  or mNode.getType() == TYPE_GRID_MESH ):
            makeMeshes.append(mNode)
      scene.message("Selected meshes are correct")
   #If single mesh is selected
   else:
      scene.message("You choosen to make " +str(meshName)+ ".")
      makeSingleMesh = meshes[meshNodes]
      if (makeSingleMesh.getType() == TYPE_STANDARD_MESH
                  or makeSingleMesh.getType() == TYPE_RENDERKIT_MESH
                  or makeSingleMesh.getType() == TYPE_GRID_MESH ):
         makeMeshes.append(makeSingleMesh)
         scene.message("Selected mesh is correct")
   #Disable GUI update
   if (guiUpdate == 0):
      scene.enable_GUI_updates(False)

   #Setup Range and Step frame
   frameRange = endFrame - startFrame
   scene.setCurrentFrame(startFrame)
   curFrame = scene.getCurrentFrame()

   while (curFrame != endFrame + stepFrame):
      #build meshes
      for makeMesh in makeMeshes:
         scene.setCurrentFrame(curFrame)
         makeMesh.build()
         makeMesh.export()
      #set next frame
      curFrame += stepFrame

#Enable GUI update
scene.enable_GUI_updates(True)
scene.message("Mesh generation has been completed")
dialog = GUIMessageDialog.new()
dialog.show( ALERT_TYPE_INFORMATION, "Mesh generation has been completed" )


Return to “User Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest