Skip to content

Instantly share code, notes, and snippets.

View JokerMartini's full-sized avatar
😀

John Martini JokerMartini

😀
View GitHub Profile
@JokerMartini
JokerMartini / Randomize Array Items | .ms
Last active July 5, 2017 14:20
Maxscript: Randomize Array returns an array of shuffled items
oldarray=#("One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten")
fn RandomizeArray arr:#() =
(
local list = #()
while arr.count != 0 do
(
id = random 1 arr.count
append list arr[id]
deleteItem arr id
@JokerMartini
JokerMartini / Shuffle Array Indices | .ms
Last active July 5, 2017 14:20
Maxscript: Shuffles the array returning an array of shuffled indices based on the supplied count.
fn ShuffleIndexes count =
(
list = #()
list.count = count
for k = 1 to count do
(
i = random 1 k
list[k] = list[i]
list[i] = k
)
@JokerMartini
JokerMartini / Color Transition | .ms
Last active July 5, 2017 14:20
Maxscript: Color transition from one color to another maintaining specified color gradation.
try(destroyDialog ::progressTest)catch()
rollout progressTest "Progress Test"
(
button doit "Process Scene" -- button to start processing
spinner spnSelectAmount fieldwidth:96 range:[0,512,0] type:#integer
progressbar pb color:red -- a red progress bar
on doit pressed do -- when the button is pressed...
(
objArray = geometry as array -- get all geometry objects into array
@JokerMartini
JokerMartini / Solid Fragment Shader | .gs
Last active May 14, 2021 23:30
GLSL Shader: A simple solid color shader
void main()
{
gl_FragColor = vec4(1.0,0.5,0.5,.5);
}
@JokerMartini
JokerMartini / Set Last In Focus Window To Foreground | .cs
Last active July 5, 2017 14:19
C#: Get last in focus windows application by name and bring to the foreground
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
@JokerMartini
JokerMartini / Desktop Notification | .ms
Last active June 3, 2021 00:11
Maxscript: Send a simple desktop notification similar to skype, from 3ds Max to the desktop. When users click on the balloon notification, in this example, it will open a windows explorer.
fn closeIcon s e = s.dispose()
fn balloonClicked s e = shelllaunch @"c:\windows\" ""
a = dotnetobject "notifyicon"
a.visible = true
a.icon = (dotnetclass "system.drawing.systemIcons").information
dotnet.addEventHandler a "BalloonTipClosed" closeIcon
dotnet.addEventHandler a "BalloonTipClicked" balloonClicked
a.showballoontip 1000 "test" "test2" (dotnetclass "tooltipicon").info
@JokerMartini
JokerMartini / Offset object along vector | .ms
Last active July 5, 2017 14:19
Maxscript: Places object along vector at specified distance
fn GenPos posA posB offset: = (posB-(normalize (posB-posA))*offset)
delete objects
inset = 10
ptStart = [100,75,0]
ptEnd = [250,175,10]
p1 = point pos:ptStart size:5 wirecolor:green cross:true box:false
p2 = point pos:ptEnd size:5 wirecolor:green cross:true box:false
@JokerMartini
JokerMartini / Resize Images and Save New Format | .py
Last active July 5, 2017 14:19
Nuke: This snippet of code takes all read nodes within a given Nuke comp and resizes the images and then saves them out to either png or jpeg.
#import a python module so we can do the search&replace stuff
import re
import os
#select all nodes in the root graph
nuke.selectAll()
############# variables
writeNodeList = [];
imgType = "png" # use either 'png' / 'jpeg'
@JokerMartini
JokerMartini / Random Value Distribution To Array | .ms
Last active July 5, 2017 14:19
Maxscript: This function will randomly generate an array of values which added together equal the difference between he min and max values supplied. For example if you need 5 random values which added together equal 100, this function would return: #(20,18,15,30,17)
fn GenRandomSumValuesArray numParts:4 minVal:0 maxVal:100 =
(
local parts = #(minVal,maxVal)
/* generate random numbers */
while parts.count < numParts+1 do
(
appendIfUnique parts (random minVal maxVal)
)
sort parts
@JokerMartini
JokerMartini / Offset Corner Point | .ms
Created July 29, 2015 14:39
Maxscript: This example demonstrates how to calculate the offset for a corner point. It allows users to define how far to offset the new point from it's original location.
/* Test Scene Setup */
clearlistener()
delete objects
/* generate an array of random points */
randomPts = for i = 1 to 3 collect (random [-30,-30,0] [30,30,0])
/* Requires 3 point3 values */
fn CalculateOffset offset:8 ptA:undefined ptB:undefined ptC:undefined =
(