Skip to content

Instantly share code, notes, and snippets.

@justinfx
Created January 26, 2012 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinfx/1684064 to your computer and use it in GitHub Desktop.
Save justinfx/1684064 to your computer and use it in GitHub Desktop.
Generating a list of Float2 pointers using MScriptUtil
from maya import OpenMaya
import random
import sys
ptrArray = []
numObjs = 4
print "Before"
for obj in range(numObjs):
data = [random.uniform(0,1), random.uniform(0,1)]
util = OpenMaya.MScriptUtil()
util.createFromList(data, 2)
ptrArray.append( (util.asFloat2Ptr(), util) )
print data
print "After"
getItem = util.getFloat2ArrayItem
for ptr, _ in ptrArray:
print [getItem( ptr, 0, 0 ), getItem( ptr, 0, 1 )]
# OUTPUT:
#
# Before
# [0.89307049110058534, 0.40570332879091231]
# [0.93074504835543426, 0.17761800498029423]
# [0.89936420586396393, 0.4011772803522774]
# [0.70293726920888766, 0.89923031176507728]
# After
# [0.8930705189704895, 0.4057033360004425]
# [0.93074506521224976, 0.17761801183223724]
# [0.89936423301696777, 0.40117728710174561]
# [0.70293724536895752, 0.89923030138015747]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment