Create Cone at Locator


#1

How can I create a cone at the selected Locator’s position but with the pivot of the Cone being at the base of the cone itself? It appears something is not working here. Here are my results

image

What i want…

image

my code…

def createMarkers(transforms, radius=1):
    markers = []

    for t in transforms:
        marker = cmds.polyCone(r=radius, h=radius*2, axis=(0, 1, 0)) # actually returns a list of 2 items, the transform and the polyCube input, so grab the first index.
        markerTM = marker[0]
        markers.append(markerTM)
        cmds.xform(markerTM, piv=[0,-radius,0], ws=True)

        pos = cmds.xform(t, q=1, ws=1, rp=1)
        cmds.xform(markerTM, t=pos, ws=1)
        # cmds.move(pos[0], pos[1], pos[2], markerTM, absolute=True)
        cmds.parent(markerTM, t)

    return markers


cmds.select( allDagObjects=True )
cmds.delete()
l = cmds.spaceLocator()
cmds.move(2, 3, 4, l, absolute=True)
transforms = [obj for obj in cmds.ls(sl=True) if cmds.listRelatives(obj)]
createMarkers(transforms)

#2

Guess you already found your solution. But for the record… ^^
With your code:

def createMarkers(transforms, radius=1):
    markers = []

    for t in transforms:
        marker = cmds.polyCone(r=radius, h=radius*2, axis=(0, 1, 0)) # actually returns a list of 2 items, the transform and the polyCube input, so grab the first index.
        markerTM = marker[0]
        markers.append(markerTM)
        cmds.xform(markerTM, piv=[0,(radius*-1),0], r=True)

        pos = cmds.xform(t, q=1, ws=1, rp=1)
        cmds.xform(markerTM, t=[pos[0],pos[1]+(radius),pos[2]], ws=1)
        cmds.move(pos[0], pos[1], pos[2], markerTM, absolute=True)
        cmds.parent(markerTM, t)

    return markers



l = cmds.spaceLocator()
cmds.move(2, 3, 4, l, absolute=True)
transforms = [obj for obj in cmds.ls(sl=True) if cmds.listRelatives(obj)]
createMarkers(transforms)

Or a bit shorter like this:

from pymel.core import *

def create_cone_at_pivot(locator_list, cone_size = 1):
    
    for item in locator_list:
        locator = PyNode(item)
        locator_pos = locator.getTranslation(space='world')
        
        poly_cone = polyCone(r=cone_size, h=cone_size*2, axis=(0, 1, 0))
        xform(poly_cone, piv=[0,-cone_size,0], r=True)
        
        
        poly_cone[0].setTranslation([locator_pos[0],locator_pos[1]+cone_size,locator_pos[2]], space = "world")
        
       

create_cone_at_pivot(ls(sl=1))        

hope it helps,
have an awesome day!
Ben