# Python script to determine XYZ of tip of cone

My scene contains a cone named 'MyCone'

I'm trying to construct a Python script: get_XYZ_for_tip( 'MyCone' )

How could I go about doing this?

• This Q is a bit vague - do you know which vertex is the tip of the cone? - or would the script have to analyze the mesh and detect this? – ideasman42 Jan 10 '14 at 6:47

This script finds the vertex that is referenced by more edges than other vertices, this should meet the 'tip-criteria' to make a function getTip simply return the vert.co value.

import bpy

obj = bpy.context.scene.objects.active
mesh = obj.data

v_edge_tot = [0] * len(mesh.vertices)
maxedges = 0
maxvert = None
for edge in mesh.edges:
for vert in edge.vertices:
v_edge_tot[vert] += 1
count = v_edge_tot[vert]
if count > maxedges:
maxedges = count
maxvert = vert

vert = mesh.vertices[maxvert]
print(maxvert)
print('v %f %f %f' % (vert.co[:]))


Using BMesh this can be a one liner :), assuming your in editmode.

import bpy
import bmesh

tip_index = max((len(v.link_edges), i) for i, v in enumerate(bmesh.from_edit_mesh(bpy.context.object.data).verts))[1]


The same idea expanded (longhand):

import bpy
import bmesh

obj = bpy.context.object
bm = bmesh.from_edit_mesh(obj.data)

vert_user_index = []
for i, v in enumerate(bm.verts):