2
$\begingroup$

I am surprised at how difficult it is to do elementary things with the blender api, or at least find the information on the web to do elementary things like lines, texts and in the case, a prism. So I hope to make a great contribution to the blender community with this question and in general with every question I ask because I'm starting from scratch and I think is the case of many people.
I suspect that the way to do it is through a cube.

$\endgroup$
3
  • 1
    $\begingroup$ This question seems too vague - what specifically are you trying to achieve? Technically, a cube is a prism so running 'bpy.ops.mesh.primitive_cube_add()' would add a square prism to the scene. There are API calls to create a mesh from a set of points in 3D space and this could easily be used in a python function to create a generic prism. Add some detail of what you've achieved so far and a specific problem you're stuck on. See wiki.blender.org/index.php/Dev:Py/Scripts/Cookbook/… for an example of creating a mesh from a set of points. $\endgroup$ Commented Jan 8, 2018 at 11:22
  • 1
    $\begingroup$ @RichSedman if the "fluff" was edited out of this question it would be the title again. $\endgroup$
    – batFINGER
    Commented Jan 8, 2018 at 13:03
  • $\begingroup$ Enable the Extra Objects addon, look through the addons code to see how to create more complex meshes. $\endgroup$
    – sambler
    Commented Jan 8, 2018 at 13:48

1 Answer 1

5
$\begingroup$

Use add primitive cylinder to make a prism

Basically by definition a cylinder in blender is really a regular ngon prism. Therefore, to add a prism via the UI, simply add > mesh > cylinder with the amount of sides you want the ngon end to have. For example for a triangular prism

enter image description here

This is a simple call to the operator:

bpy.ops.mesh.primitive_cylinder_add(vertices=3)

change the value of vertices to make other ngons on the ends of prism.

And via the bmesh API with bmesh.ops.create_cone

Rather than having a create cylinder bmesh has a create cone, which allows us to create a prism by setting the end radii the same. Simple code to add a triangular prism.

import bpy
import bmesh
context = bpy.context
bm = bmesh.new()
bmesh.ops.create_cone(bm, 
        cap_ends=True, 
        cap_tris=False, 
        segments=3, 
        diameter1=1, 
        diameter2=1, 
        depth=2)
mesh = bpy.data.meshes.new("Prism")
bm.to_mesh(mesh)
prism = bpy.data.objects.new("Prism", mesh)
# link to scene
context.scene.objects.link(prism) 
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .