select a point on a poly surface and have it return the coords?

203 views
Skip to first unread message

e955...@gmail.com

unread,
Sep 21, 2014, 9:01:46 PM9/21/14
to python_in...@googlegroups.com
Hey guys,

im trying to write some python code to be able to click a random point on a poly surface and then have it create a locator at that coordinate x,y,z.

is this possible ? - at the moment i have to create a locator and then make the surface live and drag the locator into the chosen position.

any advice would be great,

thanks,
Sam

Mahmoodreza Aarabi

unread,
Sep 22, 2014, 2:11:54 AM9/22/14
to python_in...@googlegroups.com
Hey.
i think for controling click on an object in maya you should write plugin.
but in maya env, you can use a helper(like locator) to put it on your point and then get its position with xform command.
and you can use geometryConstraint for sticking to poly, pointOnSurface node or other ways.


--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d701a530-da99-4ac1-9169-4e6d990c8807%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

e955...@gmail.com

unread,
Sep 22, 2014, 4:56:43 AM9/22/14
to python_in...@googlegroups.com
i guess plugins are c++ right. way over my head, but ill look into it.
thanks,

Sam

Mahmoodreza Aarabi

unread,
Sep 22, 2014, 4:58:03 AM9/22/14
to python_in...@googlegroups.com
You can write plugin with Maya Python API too.
but i think you get good result with maya commands too with mel and python script.

thanks,

Sam

--
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_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

Ricardo Viana

unread,
Sep 22, 2014, 11:59:11 AM9/22/14
to python_in...@googlegroups.com
This might help.
I've commented so you can follow.


Ricardo Viana

unread,
Sep 22, 2014, 11:59:24 AM9/22/14
to python_in...@googlegroups.com
import maya.cmds as cmds

#list selected vertices, only works if you dont lasso select them.

selVerts = cmds.ls(sl=True)

#create empty list to store positions
selPositions = []


#loop to look up every vertex position and store it in selPositions
for vertex in selVerts:
    #query the position
    pos = cmds.xform(vertex, query = True , t = True)
    #append to list
    selPositions.append(pos)


# loop to create locators
for position in selPositions:
    #create a locator
    locator = cmds.spaceLocator()
    #move it into the position
    cmds.xform(locator, t= position)

Marcus Ottosson

unread,
Sep 22, 2014, 4:52:47 PM9/22/14
to python_in...@googlegroups.com
Hi Sam,

This is certainly possible, if by "point" you mean vertex, you can:

1a. Get all components
2a. Pick one at random
3a. Emit from object, using the component

It will create 2 nodes, one of which is an emitter that follows the component in worldspace.

If by "point" you mean arbitrary location on a mesh, including inbetween vertices, you can:

1b. Create follicle on surface
2b. Insert a random value between 0-1

If you don't have any UVs, you can

1c. Duplicate the mesh
2c. Project planar
3c. Repeat 1b and 2b.
4c. Delete duplicate

Best,
Marcus


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Reply all
Reply to author
Forward
0 new messages