Skip to content

Instantly share code, notes, and snippets.

Avatar

CG-Lion Studio CGLion

View GitHub Profile
@CGLion
CGLion / ue4_import_assets.py
Last active Aug 17, 2020
Python for UE4 - import assets
View ue4_import_assets.py
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 / max_select_objects_by_type.py
Last active Aug 17, 2020
Python for 3ds max - select object by type
View max_select_objects_by_type.py
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 / max_list_scene_objects.py
Last active Aug 17, 2020
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..)
View max_list_scene_objects.py
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 / ue4_place_actors_at_z.py
Created Aug 17, 2020
Python for UE4 - place actor bottom bounds at 0 on Z axis
View ue4_place_actors_at_z.py
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 Sep 28, 2020
Python for 3ds max - animate vertices
View max_mesh_animation.py
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 / list_files_in_folder.py
Created Sep 28, 2020
Python - Lists all files in folder
View list_files_in_folder.py
from os import listdir
from os.path import isfile, join
dir = "D:\\"
files = [f for f in listdir(dir) if isfile(join(dir, f))]
for f in files:
print join(dir, f)
@CGLion
CGLion / list_files_by_ext_in_folder.py
Created Sep 28, 2020
Python - Lists all files with specific extension in folder
View list_files_by_ext_in_folder.py
from os import listdir
from os.path import isfile, join
dir = "D:\\"
files = [f for f in listdir(dir) if isfile(join(dir, f)) and f[-3:]=='jpg']
for f in files:
print join(dir, f)
@CGLion
CGLion / blender_access_mesh_triangles.py
Last active Oct 4, 2020
Python for Blender - Access mesh triangles
View blender_access_mesh_triangles.py
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 Oct 4, 2020
Python for Blender - access mesh animated vertices location data
View blender_animated_verts_data.py
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 Oct 4, 2020
Python for Blender - Read mesh UVs
View blender_get_vert_uvs.py
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]