Skip to content

Instantly share code, notes, and snippets.

View CGLion's full-sized avatar

CG-Lion Studio CGLion

View GitHub Profile
@CGLion
CGLion / max_list_scene_objects.py
Last active August 17, 2020 10:14
Python for 3ds max - return a list of scene objects (yes I'm also surprised there seems to be no built-in function for this please update me i you find one..)
def scene_objects():
def list_children(node):
list = []
for c in node.Children:
list.append(c)
list = list + list_children(c)
return list
return list_children(MaxPlus.Core.GetRootNode())
@CGLion
CGLion / max_select_objects_by_type.py
Last active August 17, 2020 10:13
Python for 3ds max - select object by type
from MaxPlus import SuperClassIds
from MaxPlus import SelectionManager
def scene_objects():
def list_children(node):
list = []
for c in node.Children:
list.append(c)
list = list + list_children(c)
return list
@CGLion
CGLion / ue4_import_assets.py
Last active August 17, 2020 10:13
Python for UE4 - import assets
from os import listdir
from os.path import isfile, join
import unreal
dir = "D:\\"
files = [f for f in listdir(dir) if isfile(join(dir, f)) and f[-3:]=='jpg']
AssetTools = unreal.AssetToolsHelpers.get_asset_tools()
import_tasks = []
for f in files:
print join(dir, f)
@CGLion
CGLion / ue4_place_actors_at_z.py
Created August 17, 2020 10:16
Python for UE4 - place actor bottom bounds at 0 on Z axis
import unreal
from unreal import Vector
lst_actors = unreal.EditorLevelLibrary.get_all_level_actors()
print('place actors at 0 z')
for act in lst_actors:
act_label = act.get_actor_label()
if 'Sphere_' in act_label:
print('placing: {}'.format(act_label))
act_location = act.get_actor_location()
@CGLion
CGLion / max_mesh_animation.py
Last active September 28, 2020 12:13
Python for 3ds max - animate vertices
import MaxPlus
import math
from MaxPlus import INode
from MaxPlus import TriObject
from MaxPlus import SelectionManager
from MaxPlus import Factory
from MaxPlus import Animation
from MaxPlus import Point3
from MaxPlus import Control
@CGLion
CGLion / blender_access_mesh_triangles.py
Last active October 4, 2020 13:47
Python for Blender - Access mesh triangles
import bpy
mesh = bpy.context.active_object.data
mesh.calc_loop_triangles()
for tri in mesh.loop_triangles:
tri_center = (mesh.vertices[tri.vertices[0]].co * 0.333) +\
(mesh.vertices[tri.vertices[1]].co * 0.333) +\
(mesh.vertices[tri.vertices[2]].co * 0.333)
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1,enter_editmode=False,location=tri_center)
@CGLion
CGLion / blender_animated_verts_data.py
Last active April 29, 2023 06:04
Python for Blender - access mesh animated vertices location data
import bpy
import bmesh
obj = bpy.context.active_object
frames = range(0,10)
# get the object's evaluated dependency graph:
depgraph = bpy.context.evaluated_depsgraph_get()
# iterate animation frames:
for f in frames:
bpy.context.scene.frame_set(f)
# define new bmesh object:
@CGLion
CGLion / blender_get_vert_uvs.py
Last active October 4, 2020 13:48
Python for Blender - Read mesh UVs
import bpy
# access mesh data:
obj = bpy.context.active_object
mesh_data = obj.data
mesh_loops = mesh_data.loops
uv_index = 0
# iterate teh mesh loops:
for lp in mesh_loops:
# access uv loop:
uv_loop = mesh_data.uv_layers[uv_index].data[lp.index]
@CGLion
CGLion / blender_remove_last_name_chars.py
Last active October 4, 2020 13:48
Python for Blender - Remove last characters from selected object names
import bpy
objects = bpy.context.selected_objects
num_chars = 3
for o in objects:
o.name = o.name[:-num_chars]
@CGLion
CGLion / blender_rename_objects_numbered.py
Last active October 4, 2020 13:48
Python for Blender - Rename all selected objects to a set base name followed by a 3 digit numeric suffix
import bpy
objects = bpy.context.selected_objects
base_name = "new_name"
for (i,o) in enumerate(objects):
o.name = "{}_{:03d}".format(base_name, i)