Skip to content

Instantly share code, notes, and snippets.

Avatar

Andreas Rånman rondreas

View GitHub Profile
@rondreas
rondreas / selop_random.py
Last active Sep 23, 2022
Modo Selection Operation that takes a percent and selects random components,
View selop_random.py
import random
import lx
import lxu
import lxu.attributes
import lxifc
class SelOp(lxifc.SelectionOperation, lxu.attributes.DynamicAttributes):
def __init__(self):
@rondreas
rondreas / get_ifc.py
Created Sep 22, 2022
Often you end up getting a lx.object.Unknown from Modo's API, this will test the object against all "interfaces" and return list of potentially supported types.
View get_ifc.py
import lx
def get_ifc(obj):
""" From a given object in lx sdk, find supported interfaces"""
supported_interfaces = []
for name, ifc in lx.object.__dict__.items():
try:
if isinstance(ifc, type):
o = ifc(obj)
supported_interfaces.append(ifc)
@rondreas
rondreas / get_server_counts.py
Last active Sep 22, 2022
Get count for all "servers"
View get_server_counts.py
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
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.
View sheet_conflict.py
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 Oct 11, 2018
Vertex displacement shader to simulate wind.
View VertexWind.shader
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 Aug 4, 2022
quick ctag option file for unreal shaders
View hlsl.ctag
# 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,
@rondreas
rondreas / unreal_menu.py
Created Apr 1, 2021
Example of extending a menu in Unreal using Python
View unreal_menu.py
"""
Example of extending a menu in Unreal using Python
"""
import unreal
def main():
View workplane_xfrm_inv.py
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)
@rondreas
rondreas / list_notifiers.py
Created Feb 2, 2022
Iterate over all notifiers and get their arguments
View list_notifiers.py
import lx
notify_system = lx.service.NotifySys()
for i in range(notify_system.Count()):
notifier = notify_system.ByIndex(i) # get the lx.object.Notifier
name = notify_system.NameByIndex(i) # get the str name for the Nofifier
# attempt getting arguments for the notifier,
try:
@rondreas
rondreas / build.bat
Created Dec 14, 2021
Thank you handmade hero for making it easier to compile stuff
View build.bat
@echo off
REM adds cl.exe to path
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat" x64
REM Set current dir to folder of this script
pushd %~dp0
REM Then create and cd into build folder
mkdir build