Re: [Maya-Python] multiprocessing opening up output window GUI

2013-02-09 Thread Jan:
Hi Justin,

Thanks a million !
I will try this as soon as I have access to maya again.
Its a shame that the .set_executable() function is windows only. As that
would have been a great solution. However being able to use the standard
interpreter is a great alternative!.

I will get back to you asap with the test results.

Jan



2013/2/8 Justin Israel justinisr...@gmail.com

 I am not sure what platform you are running, but on OSX this is even more
 problematic. It creates orphaned processes that don't close and keep
 spinning the cpus.

 The problem, as I understand it, is that the multiprocessing module needs
 to be able to fork, copy the memory, and start up the same interpreter
 again. But Maya is using an embedded python interpreter and it thinks it
 needs to start up Maya in the new processes, which crashes. On windows, the
 multiprocessing module has the .set_executable() function:

 http://docs.python.org/2/library/multiprocessing.html#multiprocessing.set_executable
 But I don't have windows to test trying to set this to a valid python
 interpreter, and it is not even platform independent as a solution.

 What I have gotten to work just fine is the workflow of running your
 script in a subprocess, and communicating the results back over the pipe.
 This allows multiprocessing to run under whatever standard python
 interpreter you want, and is independent of Maya.

 There are two files here:
 https://gist.github.com/justinfx/4741527

 The first one is a modified version of your original code.
 The second is the snippet to launch the subprocess from Maya and read the
 results.

 -- justin



 On Feb 8, 2013, at 6:04 AM, Jan: wrote:

 Hi,

 i'm trying to use the python multiprocessing module to make my script
 multi-threaded.

 However every time it tries to start a new process it loads up the output
 window with command line on how to load the maya batch process.
 When I close the window the process closes as well and the function is
 never called or it locks up.
 Unfortunately I have no idea how I can pass command line info from the
 multiprocessing function.

 So my question is:
 How can I load a multiprocessing process without having the output window
 pop up and the process running properly.

 Any help would be much appreciated.
 (I was thinking of running my code inside of a different interpreter but I
 have no idea on how to go at it)


 Example function: (it works fine in any other standard python (2.6)
 interpreter ).



 from multiprocessing import Pool
 from time import time

 ## Simple func to eat up cpu power.
 def whileFunc(z):
 while z  100:
 z += 1
 return z

 ## We have to work in __main__ else in some os versions the threads become
 unsafe
 if __name__ == __main__:
 ## Get current time
 currtime = time()

 ## How often to run (just a test value)
 N = 1000
 ## Just a list with 1s
 myList = [1]*N

 nrOfProcessors = 8 #16

 ## Set our pool of processors
 po = Pool(nrOfProcessors)

 ## create the threads
 res = po.map_async(whileFunc, myList)


 print 'This value below should be a 1000:'

 ## The res.get() getting of the result actually starts the threads
 (surprisingly enough.)
 ## This is also where maya will open up the Output Window and in some
 cases lock up.
 print len(res.get())

 print 'time elapsed:', time() - currtime

 --
 You received this message because you are subscribed to the Google Groups
 Python Programming for Autodesk Maya group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to python_inside_maya+unsubscr...@googlegroups.com.
 To post to this group, send email to python_inside_maya@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




  --
 You received this message because you are subscribed to the Google Groups
 Python Programming for Autodesk Maya group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to python_inside_maya+unsubscr...@googlegroups.com.
 To post to this group, send email to python_inside_maya@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
You received this message because you are subscribed to the Google Groups 
Python Programming for Autodesk Maya group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To post to this group, send email to python_inside_maya@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[Maya-Python] Re: components in the selected order

2013-02-09 Thread Bradon Webb
On Thursday, July 30, 2009 3:34:59 PM UTC-5, wilsimar wrote:
 thanks.. I think the scriptjob is the easy way.

do you think you can post your code.  I'm looking to do the same thing, get a 
list of selected edges in the order they are selected. I'm not sure I 
understand how to put the script together using scriptJob.  

Thanks,
Bradon

-- 
You received this message because you are subscribed to the Google Groups 
Python Programming for Autodesk Maya group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To post to this group, send email to python_inside_maya@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[Maya-Python] Folding polygons

2013-02-09 Thread Bradon Webb
I'm trying to develop a script for oragami.

I have a few method in the works. It's a pretty difficult problem. I'm not sure 
if anyone else has tacked the problem or knows some steps that might help.

this is my reference for basic functionality:
https://vimeo.com/36969599

This is pretty good functionality.  It really only works well on quads though 
and with right angle faces.  If you try to do this on a sphere it has some 
problems due to the irregular polygons.

for Maya I was thinking of using Joints.  I have a script to extract Faces and 
Query the worldspace transforms this should work for orienting joint chain.

The one major problem I am having is finding a way to Query the fold path.  to 
choose the edge where the fold will happen.  Finding the center of the face to 
fold is easy, but finding the connected edges or edges along a path I'm coming 
up stumped.  

I think it comes down to tell how to automatically detect a shared edge between 
tow poly objects.  any clues how I might do that?

-- 
You received this message because you are subscribed to the Google Groups 
Python Programming for Autodesk Maya group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To post to this group, send email to python_inside_maya@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


attachment: OragamiJoints.PNG

[Maya-Python] Re: Finding the angle of a selected face

2013-02-09 Thread Bradon Webb
this code might be useful example for you.

Im working on a similar thing.  I want to re-orient a polygon if extracted from 
a mesh based on the angle of the face. Or if you have some model that has lost 
its transforms because of a lattice or vertex deformation.

I think if you only use the face normal you might get a twisting problem.  

In this case I use 3 points in space to define the angle of the plane.  The 
points are selected somewhat arbitrary for now.  I could't really think of a 
good way to define the three points.  You could probably do a vertex selection 
order, but unfortunately I don't think you can get the selected order of 
components very easily.

-- 
You received this message because you are subscribed to the Google Groups 
Python Programming for Autodesk Maya group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To post to this group, send email to python_inside_maya@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


#===
# Convert To Worldspace Transforms
# author: Bradon Webb
# bra...@paraportable.net
# 01/08/13
#
# This script will calculate world space rotation and transformation to an polygon object
# that has lost its transformation and rotation.
# Based on a the zero index polygon face and vertex 0, 1, 2
# 0 = origin
# 1 = X axis
# 2 = Up axis
#
# Select your object or polygon, then run script.
#
#===


import maya.cmds as mc
import math
import maya.OpenMaya as om
import maya.mel as mel
import pymel.core as pm

def createLineVector(point1 = om.MVector(0,0,0), point2 = om.MVector(1,1,0), name='vector'):
'''
@summary:
given two point MVectors create a line - good for visualizing normals
@arguments:
Point1 = MVector
point2 = MVector
name = string, names the created line
@returns:
curve name
'''

newCurve = mc.curve(name=name, worldSpace=True, degree=1,
point=[(point1.x, point1.y, point1.z),
   (point2.x, point2.y, point2.z)])
return newCurve


def calculateFaceCenter(nodeName='nodeName', faceNum=0):
'''
@summary:
gets the worldspace center given a nodeName and a face
centerpoint is based on average weigting or the same as the blue dot on the face
libraries pymel, openMaya 
@arguments:
nodeName = string of a node name
faceNum = Int face number
@returns:
worldspace XYZ coordinates of the face as a [list], [x,y,z]
'''

# format node name with face num, store as pymel face
face = pm.MeshFace('{node}.f[{num}]'.format(node=nodeName, num=faceNum))

# get centerpoint of face
pt = face.__apimfn__().center(om.MSpace.kWorld)
centerPoint = pm.datatypes.Point(pt)

print 'CENTERPOINT: ', centerPoint

return centerPoint


def calculateRotations(pointOrigin=0, pointX=1, pointUP=2, nodeName='nodeName'):
'''
@summary:
calculates Euler rotation values from a node and 3 points
@arguments:
pointOrigin = number of the point for the origin
pointX = number of the point for the X axis
pointUP = number of the point for the Y Axis
nodeName = the name of the geo to query the points from
@returns:
Euler rotation to UNnrotate the object, Euler rotation to rotate the object back
[[x,y,z],[x,y,z]]
'''
node = nodeName

rotOrder = mc.getAttr('%s.rotateOrder'%node)
print 'ROTORDER:', rotOrder

# Get Point Positions
originPosition = om.MVector(*mc.pointPosition('{mesh}.vtx[{vertex}]'.format(mesh=node, vertex=pointOrigin), world=True))
XDirection = om.MVector(*mc.pointPosition('{mesh}.vtx[{vertex}]'.format(mesh=node, vertex=pointX), world=True))
UPDirection = om.MVector(*mc.pointPosition('{mesh}.vtx[{vertex}]'.format(mesh=node, vertex=pointUP), world=True))
worldOrigin = om.MVector(0,0,0)

# Subtract Positions for Vector 
UpVector = originPosition - UPDirection
 
XAxis = XDirection - originPosition
ZAxis = UpVector^XAxis
YAxis = ZAxis^XAxis

# Debugging
#print 'XAxis:', XAxis.x, XAxis.y, XAxis.z
#print 'UpVector:', UpVector.x, UpVector.y, UpVector.z
#print 'ZAxis:', ZAxis.x, ZAxis.y, ZAxis.z
#print 'YAxis:', YAxis.x, YAxis.y, YAxis.z

XAxisNormalize = XAxis.normal()
YAxisNormalize = YAxis.normal()
ZAxisNormalize = ZAxis.normal()

# Create lines in space for each axis: visual aid
#xNormalCurve = createLineVector(point1=worldOrigin, point2=XAxisNormalize,  name='XAxisNormalize')
#yNormalCurve = createLineVector(point1=worldOrigin, point2=YAxisNormalize,  name='YAxisNormalize')
#zNormalCurve = 

[Maya-Python] Re: Folding polygons

2013-02-09 Thread Bradon Webb
I think the best way to write this script is to select the fold edges on the 
mesh.  I can query the centerpoint of the edge for joint position.  but how 
would I get the angle of rotation based of that selected edge?

here is a math diagram showing a basic setup.

I think it is ok to only select one edge and then have maya automatically 
determine the direction of joint orientation based on the other vertex/edge in 
the polygon?  but this is asking a lot but would make it more user friendly 
because then I only have to select one edge for each joint.

I'm guessing the best way to do this in maya would be to find the end points of 
selected line (the vertex) and then calculate the X and Z rotation axis.  Then 
the Y axis would be the opposite polygon edge.

I need help figuring out how to get the vertex information from an edge 
selection list. and how to find the opposite polygon edge.  

-- 
You received this message because you are subscribed to the Google Groups 
Python Programming for Autodesk Maya group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To post to this group, send email to python_inside_maya@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


attachment: intersectingLines.PNG