----------

------ Moved ------

simplify what you are trying to do, as a test make a cube. if you are still stuck, post your code.

@ zeffii

The addon works ok until i want to create face from 4 vertices that i added
sometimes it creates triangle and sometimes blender crashes

api mesh_faces

me.faces.add(4) it adds 4 faces not 4 vertices like api says



Last face added
This should work because blender wants 4 vertex indices but it does not.
me.faces[-1].vertices = [1, 2, 3, 4]
Does anybody know how to do that

update() is a function call. it requires ()

a face is assumed (currently) to have 3…or 4 verts,

me.faces.add(1) 

essentially appends an empty list [] to the existing list of faces. You tell that face how many verts it has by adding a [1,2,3] or [1,2,3,4] to that list index (-1)

My point about the cube was, you have so much other stuff in this script that has nothing to do with your problem. I suggest making a cube from scratch starting with a simple plane, and adding faces and verts to get a feeling for it.

it could be as simple as setting the mode to edit or object
-add vertices/faces/ in object mode

@ zeffii Thx for help but How do i add those vertices to that list can you write some simple code pls

@ zeffii I have simplified a code that i posted before.
Can you help me with adding that face

it’s a little weird, and probably not documented well enough (or at least not a quick resource mentioning it). I’ve higlighted the show-stopper in the code below. works nicely.


import bpy
# start with adding a plane at 0,0,0
bpy.ops.mesh.primitive_plane_add()
mplane = bpy.context.active_object

# in object mode 
if mplane.mode == 'EDIT':
    bpy.ops.object.mode_set(mode='OBJECT')

# add 4 verts
mplane.data.vertices.add(4)
mplane.data.vertices[-4].co = (1, -1, 1)
mplane.data.vertices[-3].co = (-1, -1, 1)
mplane.data.vertices[-2].co = (-1, 1, 1)
mplane.data.vertices[-1].co = (1, 1, 1)

# for m in mplane.data.vertices: print(m.co)
print("mplane.data.faces - before")
for l in mplane.data.faces:
    print("face===")
    for em in l.vertices:
        print(em)
        
# add one face    
mplane.data.faces.add(1)
<b>mplane.data.faces[-1].vertices_raw = [7,4,5,6]
mplane.data.update(calc_edges=True)</b>

print("mplane.data.faces - after")
for l in mplane.data.faces:
    print("face===")
    for em in l.vertices:
        print(em)

print("num faces=", len(mplane.data.vertices))
print(mplane.data.faces[-1])

From bartius Crouch :
https://sites.google.com/site/bartiuscrouch/scripts/bridge#TOC-Download
https://sites.google.com/site/bartiuscrouch/py/mesh_bridge.py?attredirects=0
(the second provides a download to the bridge tool, which effectively adds faces to an existing mesh,… and explains how to avoid crashing this stuff so hard).

@ zeffii

It works thank you very much.
Now i have to figure out what is wrong with my script.



Warning works only for quads

How do i delete a particular face from a mesh.
For example if i want to delete me.faces[1]

there are a few ways to achieve this, some more convoluted than others.


<b># must be in edit mode.</b>

# first select the face, then delete it. 
mplane.data.faces[-1].select = True   # won't show in viewport
bpy.ops.mesh.delete(type='ONLY_FACE') # will be acted on.

this deletes the face but not the vertices/edges associated with it. hover over the items to see tool-tips on the delete menu for other options

@ zeffii

Thx for reply
I kind of tried that but it does not do what i want.

In the script above in operator 0 when i put your code below the line that says ‘# edit mode in’ it does not do anything
I would like all the new faces to stay selected. I want to delete all the original faces from list_0

To add faces you have to go out of edit mode but to remove them you have to be in edit mode

why not add and remove them using python in object mode

bpy.ops.mesh.delete(type=‘ONLY_FACE’) is an operator that works only in edit mode

In blender 2.49 there was a function to do that ’ me.faces.delete(0, list_0) '.
Appending and deleting for example faces from mesh was a lot easier in blender 2.49

One more question.
me.faces is a collection of faces is it possible to remove face from collection using something like remove() or pop()

Thank you again for your help

i’m kind of running into the same problems here with some unrelated code. my code analyses a sequence of connected edges like :


and gathers the Vertices, starting from one end. but i’m stuck at replacing the bpy.context.active_object.data (meshtype) with another… or updating it in place.

as talked about earlier, adding to the object isn’t too difficult, but modifying existing data is something i’m going to have to look around for examples of. (longer syntax highlighted example here)

cool, looks like this works


# cobject   is bpy.context.active_object

bpy.ops.object.mode_set(mode = 'OBJECT')

prof_mesh = bpy.data.meshes.new("test_mesh")
prof_mesh.from_pydata(Verts, Edges, [])
prof_mesh.update()
cobject.data = prof_mesh

bpy.ops.object.mode_set(mode = 'EDIT')

i know this doesn’t solve your problem, but you might get some insight. Sometimes things don’t work the way we want, or idealized, and we get so attached to our preferred idea that we forget or become blind to other methods that do work.

@ zeffii
I have made it work but i am not happy how it is done.
They should add ability to remove verts, edges and faces the same way you add them without entering and exiting edit mode multiple times or maybe there is some other way to do that i do not know about.

Update



10 seconds of work using my inset and extrude islands


Have to rewrite code for creation of side faces.