View Full Version : Edge length
cppgraphics 01-23-2010, 06:24 AM Dear folks,
I'm a basic user of Maya. I would like to know how to measure the length of an edge in MEL or Python?, what is the command or method to do it?
Thanks
|
|
Zerflag
01-23-2010, 08:23 AM
been ages since i've done aything in maya, so there is probably a better way, but... get the vertices that belong to the edge, get their global coordinates, compute vector between the two. there's your length.
cppgraphics
01-23-2010, 10:40 AM
been ages since i've done aything in maya, so there is probably a better way, but... get the vertices that belong to the edge, get their global coordinates, compute vector between the two. there's your length.
Thanks dude let me try it.
kyleh
01-24-2010, 09:08 PM
Here's some python code that will return the length of a selected edge:
import maya.cmds as cmds
import math
sel=cmds.ls(sl=True,fl=True)
cmds.ConvertSelectionToVertices()
p=cmds.xform(sel,q=True,t=True,ws=True)
length=math.sqrt(math.pow(p[0]-p[3],2)+math.pow(p[1]-p[4],2)+math.pow(p[2]-p[5],2))
cmds.select(sel)
print 'Edge Length=',length
cppgraphics
01-25-2010, 12:18 PM
Here's some python code that will return the length of a selected edge:
import maya.cmds as cmds
import math
sel=cmds.ls(sl=True,fl=True)
cmds.ConvertSelectionToVertices()
p=cmds.xform(sel,q=True,t=True,ws=True)
length=math.sqrt(math.pow(p[0]-p[3],2)+math.pow(p[1]-p[4],2)+math.pow(p[2]-p[5],2))
cmds.select(sel)
print 'Edge Length=',length
Thank you kyleh :cool:.
Its working exactly fine and can you please explain what the xform will return. In the document they gave like xform returns depends on flag you selected.
kyleh
01-25-2010, 02:16 PM
In this script I convert the selected edge into verts. xform then returns the world space location of the selected verts in this form (v0x, v0y, v0z, v1x, v1y, v1z). From there I just calculate the length between the two verts.
cppgraphics
01-26-2010, 05:55 AM
In this script I convert the selected edge into verts. xform then returns the world space location of the selected verts in this form (v0x, v0y, v0z, v1x, v1y, v1z). From there I just calculate the length between the two verts.
kyleh,
Where is the definition of this funtion(cmds.ConvertSelectionToVertices())? It is not available in the Docs.
Is this any internal function used in Maya?
kyleh
01-26-2010, 02:37 PM
ConvertSelectionToVertices() is an undocumented command that converts the current component selection to vertices. I try not to us many undocumented commands since they may change in the future, but sometimes they're just too convenient :)
cppgraphics
01-27-2010, 04:40 AM
ConvertSelectionToVertices() is an undocumented command that converts the current component selection to vertices. I try not to us many undocumented commands since they may change in the future, but sometimes they're just too convenient :)
Thanks Kyleh, please let me know where did you find all these undocumented commands?
Blot12345
02-01-2010, 06:54 PM
You may be able to use the arclen node in maya. It'll give you the length of a curve in maya, and it'll update when the curve changes.
Here is a link: http://download.autodesk.com/us/maya/2009help/Commands/arclen.html
I hope this helps.
CGTalk Moderation
02-01-2010, 06:54 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.