Skip to content

Instantly share code, notes, and snippets.

View rondreas's full-sized avatar

Andreas Rånman rondreas

View GitHub Profile
@rondreas
rondreas / cmod_double.py
Created February 14, 2023 13:11
Implemented a channel modifier that accepts a float input and return the value multiplied by two.
"""
Manual implementation of the SDK chanmod double
"""
import lx
import lxifc
@rondreas
rondreas / component_under_mouse.py
Created January 25, 2023 12:01
Example of getting viewport under mouse, and from there hit position and which component was closest to the hit
"""
Command to print the component under the mouse using lx api in Foundry Modo
To try it out, map the command to a hotkey and execute while mouse is over corresponding component.
py.mouse.component type:{vert|edge|poly}
You will likely want to use the already existing method
@rondreas
rondreas / get_active_tool.py
Created January 6, 2023 11:13
functions for gettings the currently active tools in modo
import lx
def get_command(name: str) -> lx.object.Command:
""" Spawn and return the command of given name """
cmd_svc = lx.service.Command()
try:
tag = cmd_svc.Lookup(name)
return cmd_svc.Spawn(tag, name)
except RuntimeError as e:
@rondreas
rondreas / ue_timer.py
Created March 15, 2021 20:14
Example of Timer in Unreal
"""
Start a timer to call the function "hey" every half second.
Have yet to figure out how to kill this...
"""
import unreal
@rondreas
rondreas / selop_random.py
Last active September 23, 2022 09:20
Modo Selection Operation that takes a percent and selects random components,
import random
import lx
import lxu
import lxu.attributes
import lxifc
class SelOp(lxifc.SelectionOperation, lxu.attributes.DynamicAttributes):
def __init__(self):
@rondreas
rondreas / get_server_counts.py
Last active September 22, 2022 08:28
Get count for all "servers"
import lx
host_svc = lx.service.Host()
# look over all lx.symbol.a_* constants,
for k, v in lx.symbol.__dict__.items():
if k.startswith("a_"):
print(f"{k}: {host_svc.NumServers(v)}")
@rondreas
rondreas / sheet_conflict.py
Created May 24, 2021 14:30
Had issue where some artists had copied configs from another machine and ui elements would just be gone or they'd suffer constant crashes. Figured it could be conflicts in their configs so threw this one together and seems to have solved our issues.
import xml.etree.ElementTree as ET
import os
platform = lx.service.Platform()
configs = set() # all unique paths to config files
for i in range(platform.ImportPathCount()):
directory = platform.ImportPathByIndex(i)
for filename in os.listdir(directory):
@rondreas
rondreas / VertexWind.shader
Created October 11, 2018 09:47
Vertex displacement shader to simulate wind.
Shader "Custom/VertexWind" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness("Smoothness", Range(0,1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
_Normal("Normal Map", 2D) = "bump" {}
_CutOff("Alpha Cutoff", Range(0, 1)) = 0.5
@rondreas
rondreas / hlsl.ctag
Created August 4, 2022 09:00
quick ctag option file for unreal shaders
# definitions for hlsl to be used for unreal shaders, usf, ush etc...
--langdef=hlsl
--map-hlsl=+.ush
--map-hlsl=+.usf
# for now just catch all functions,
# [a-zA-Z2-4]+ should match any type identifier,
# [a-zA-Z_]+ should match the function names,
# \((([a-zA-Z2-4]+[[:space:]]+[a-zA-Z]+)([[:space:]]*[,]*[[:space:]]*))*\) should match any inputs to functions,
# \2 means the second group is the name,
import lx
import lxu
# get the current active scene and a channel read object,
scene = lx.object.Scene(lxu.select.SceneSelection().current())
channel_read = lx.object.ChannelRead(scene.Channels(None, 0))
# using the channel read get the workplane position and rotation
workplane_position = scene.WorkPlanePosition(channel_read)
workplane_rotation = scene.WorkPlaneRotation(channel_read)