3
$\begingroup$

I want to create an arrow like in the image using python script. Can someone help me out?

enter image description here enter image description here

Thanks

$\endgroup$
5
$\begingroup$

a very flexible way to do that is to use the Rigify addon. You enable it in the User Preferences -> Addons tab, look for Rigify and check it.

Now, if you go to Edit Mode of ANY mesh, there's a button in the Transform Panel:

Encode Widget

Rigify now creates the code needed to make this Object via Python. Go to a Text Editor, and select widget.py:

widget

This is all the code you need, wrapped in a nice Python function. So to recap: Model your Mesh as you wish it to be, Apply all modifiers, and encode it using Rigify Dev Tools.

$\endgroup$
2
$\begingroup$

What matters here is the order in which vertices are used to create the unique face of the arrow.

I have chosen to set them clockwise.

enter image description here

import bpy
import bmesh

#Size parameters
body_length = 4
body_width = 0.6
head_length = 1.1
head_width = 1

#Half sizes along Z
half_body_width = body_width / 2.0
half_head_width = head_width / 2.0

#Define the wanted coordinates
coords = [ [body_length, 0.0, half_body_width],       #1
            [body_length, 0.0, half_head_width],      #2
            [body_length + head_length, 0.0, 0.0],    #3
            [body_length, 0.0, -half_head_width],     #4
            [body_length, 0.0, -half_body_width],     #5
            [-body_length, 0.0, -half_body_width],    #6
            [-body_length, 0.0, -half_head_width],    #7
            [-body_length - head_length, 0.0, 0.0],   #8
            [-body_length, 0.0, half_head_width],     #9
            [-body_length, 0.0, half_body_width] ]    #10

#Create the mesh
bpy.ops.object.add(type='MESH')
#Get the object
obj = bpy.context.object
#Get the mesh data
mesh = obj.data

#Create a bmesh instance in order to add data (vertices and faces) to the mesh
bm = bmesh.new()

#Create the vertices
for coord in coords:
    bm.verts.new( coord )

#Add a face with all the vertices (the vertices order matters here)
bm.faces.new(  bm.verts )

#Updates to Blender
bm.to_mesh(mesh)
mesh.update()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.