Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
openroomxyz / ConvertAllFilesInFolderFromOggToMp3.py
Last active April 13, 2020 17:48
Python : How can i convert all files in folder from ogg to mp3?
import os
from pydub import AudioSegment
def get_list_of_files_only_in_folder(folder_path):
return [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
def convert_from_ogg_to_mp3(path_file_input, path_file_output):
ogg_version = AudioSegment.from_ogg(path_file_input)
ogg_version.export(path_file_output, format="mp3")
@openroomxyz
openroomxyz / RenameAllFilesInFolderToBeNumerical.py
Created April 13, 2020 18:05
Python : How to rename all files in a folder so that their names are ordered numbers?
import os
def get_list_of_files_only_in_folder(folder_path):
return [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
def get_extension(name):
return name.split('.')[-1]
def rename_files_in_folder_to_numerical_order(path, start_index = 0):
n = start_index;
@openroomxyz
openroomxyz / CropSingleImage.py
Created April 14, 2020 09:27
Python : How can i crop single image?
from PIL import Image
def crop(path_input, path_output, left, top, right, bottom):
im = Image.open(path_input)
im1 = im.crop((left, top, right, bottom)) # new cropped image
im1.show() #Display the image if you wan't to
im1 = im1.save(path_output)
name = "somename"
path_in = "C:\\Users\x\\x\\x\\"+name+".png"
@openroomxyz
openroomxyz / CropFolderOfPhotos.py
Created April 14, 2020 09:44
Python : How can i crop folder of photos?
from PIL import Image
import os
def get_list_of_files_only_in_folder(folder_path):
return [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
def get_extension(name):
return name.split('.')[-1]
def crop(path_input, path_output, left, top, right, bottom):
@openroomxyz
openroomxyz / BlenderHowToCreateACube.py
Created April 16, 2020 11:07
Blender Python : How to create a cube at position rotation scale?
import bpy
def create_a_cube(name, position, set_rotation, scale):
# Create a simple cube.
bpy.ops.mesh.primitive_cube_add()
# Get the cube object and rename it.
cube = bpy.context.object
cube.name = name
cube.rotation_euler = set_rotation
@openroomxyz
openroomxyz / run.py
Created April 16, 2020 11:12
Blender Python : How to get Boolean Union of two objects?
import bpy
def Union(name_a, name_b, new_one_name):
# Create a boolean modifier named 'my_bool_mod' for the cube.
mod_bool = bpy.data.objects[name_a].modifiers.new('my_bool_mod', 'BOOLEAN')
# Set the mode of the modifier to DIFFERENCE.
mod_bool.operation = 'UNION' #'DIFFERENCE'
# Set the object to be used by the modifier.
mod_bool.object = bpy.data.objects[name_b]
bpy.context.view_layer.objects.active = bpy.data.objects[name_a]
@openroomxyz
openroomxyz / GenerateUnionOfMultipleObjects.py
Created April 16, 2020 15:05
Blender Python : How do i generate an geometric Union of Multiple Cubes / or others Objects (Union Modifier, efficient way)?
import bpy
import uuid
def create_a_cube(name, position, set_rotation, scale):
# Create a simple cube.
bpy.ops.mesh.primitive_cube_add()
# Get the cube object and rename it.
cube = bpy.context.object
cube.name = name
@openroomxyz
openroomxyz / BooleanWave.py
Created April 16, 2020 15:21
Blender Python : How to create a Wave with Boolean :) ?
import bpy
import uuid
import math
import random
def create_a_cube(name, position, set_rotation, scale):
# Create a simple cube.
bpy.ops.mesh.primitive_cube_add()
# Get the cube object and rename it.
@openroomxyz
openroomxyz / InstanciatingThePrefabFromResouces.cs
Created April 18, 2020 12:14
Unity : How can i Instantiate Prefab by filename from File inside the folder Resources ?
GameObject instanciatedCube = (GameObject)PrefabUtility.InstantiatePrefab(Resources.Load("Cube"));
//Prefab has to be in folder named Resources
@openroomxyz
openroomxyz / RunScriptInEditModeAndReciveInput.cs
Last active July 14, 2020 11:15
Unity : How can i run a script in in edit mode (Not Runtime) when i select some object, and i wish to receive user input (Edit update loop) and Instantiate and object on key-press ?
using UnityEditor;
using UnityEngine;
//How can i run a script in at at edit time (Not Runtime) when object is selected, and recive user input (Edit update loop) ?
//Editor scripts have to be in folder named Editor
//[CustomEditor(typeof(GameObject))] ensures that this peace of code will run only when we have GameObject selected so we are save to cast object to GameObject [selectedTarget = (GameObject)target;]
[CustomEditor(typeof(GameObject))] //This is custom editor for the type GameObject ( This script will kick in when we have game object selected )
public class CubeEditor : Editor
{