how to fill up with BPY OPS?

i selected an object which seems to be the active object
then tried to fill faces



print ( ' obj_act = context.active_object  =', bpy.context.active_object )
 
 
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.fill()
bpy.ops.object.editmode_toggle()


this follows the viewport commands

no errors but it does not fill up the faces ?

what else is missing here to do the fill up of all faces and see results in viewport?

thanks

well this is correct for viewport, but in script, you can’t really use toggle commands without knowing the current state

try this instead:

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.fill()
bpy.ops.object.mode_set(mode='OBJECT')

i trid with a test like this

but then i get an error on poll for select command!

seems that the toggle must be done twice!



if bpy.context.object.mode == 'EDIT':
 bpy.ops.object.editmode_toggle()
 bpy.ops.object.editmode_toggle()
 
 
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.fill()
bpy.ops.object.editmode_toggle()


any other way to check for edit mode ?

thanks

you may get a poll error if you just deleted an object and bpy.context.object is therefore None. In this case, mode changing will cause an error. You can solve this by e.g.:

bpy.context.scene.objects.active = bpy.data.objects[0]
bpy.data.objects[0].select = True

it can fail if scene is entirely empty though

i printed the name of the active object just before that
so i know i have the right one

but then trying to go into edit mode and select all verts

and it fails right there on the select command ?

tried with you lines


 
object=bpy.context.active_object
print (' Active object  name =',object.name)
 
ob1=bpy.data.objects["gougon"]
print ('ob1=',ob1.name)
 
print ( ' obj_act = context.active_object  =', bpy.context.active_object )
 
 
bpy.context.scene.objects.active = bpy.data.objects[0]
bpy.data.objects[0].select = True

if bpy.context.object.mode == 'EDIT':
 bpy.ops.object.editmode_toggle()
 bpy.ops.object.editmode_toggle()

<b>bpy.ops.mesh.select_all(action='TOGGLE')</b>
bpy.ops.mesh.fill()
bpy.ops.object.editmode_toggle()



get error

dules\bpy\ops.py", line 188, in call
ret = op_call(self.idname_py(), None, kw)
untimeError: Operator bpy.ops.mesh.select_all.poll() failed, context is incorre
t

unless this command has changed !

somethings is wrong here but what

thanks

did a test here and no error this time




if bpy.context.object.mode == 'EDIT':
 pass
else:
 bpy.ops.object.editmode_toggle()
 
print ('after bpy.context.object.mode  =',bpy.context.object.mode)
print ()
 
 
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.edge_face_add()


no error but does not fill up the faces
like i do in viewport !
something is missing but what so it fills up all the faces !

thanks

found an example for using the fill command

but seems it may not work on first shot

to tried it like in the script example but still not working



 
bpy.ops.mesh.remove_doubles()
 
 
bpy.ops.mesh.fill()
 
for i in range(0, 5):
 bpy.ops.mesh.beautify_fill()
  
bpy.ops.mesh.tris_convert_to_quads()  # # Quadrangulate the mesh using blender ops
bpy.ops.object.editmode_toggle()    # this is  F key
 

so repeated it 5 times but it did not work to fill up faces!

any way to make it work ?

thanks

works fine here

if bpy.context.object:
    print(bpy.context.object.name)

    bpy.ops.object.mode_set(mode='EDIT', toggle=False)
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.mesh.fill()
    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
else:
    print("No context object!")

i remove some of the code lines before creating this new object
and now seems to work to fill up the object

not certain why
have to find out what cause this problem!

i tried to add the spin dup one and still in error it is out of context

if bpy.context.object:
print(’ bpy name =’,bpy.context.object.name)

bpy.ops.object.mode_set(mode=‘EDIT’, toggle=False)
bpy.ops.mesh.select_all(action=‘SELECT’)
bpy.ops.mesh.spin(steps=9, dupli=True, degrees=360, center=(0, 0, 0), axis=(0, 0, 1))

bpy.ops.mesh.fill()

print (‘object ######### filled up’)
bpy.ops.object.mode_set(mode=‘OBJECT’, toggle=False)
else:
print(“No context object!”)

what can causes this out of context ?

the object is seleted in edit mode so it should do the spin
!
same sequence of commands then in viewport!

thanks

please upload your blend file to http://www.pasteall.org/blend/ so we can see what’s going on

here sample file

cagegear3.blend (96.7 KB)

i added spin under the fill mesh around L288

but it is also at the end of script but that one is not working
but not important if it works in first location around lines 288

i check the object is active and in edit mode
like in viewport report window!

thanks

well it fills one segment, then errors out at line 294, not sure why

ye that’s the line for spin dup
which is same then in report window
so it should work

but it is out of context ?

anyose else has an idea how to correct that

thanks

got another example working 50 %

has to do with viewport

bpy.context.area.type=“VIEW_3D”
but then have to come back !

but not working well!

but got this ecample from column script

        bpy.ops.object.editmode_toggle()
        bpy.ops.mesh.spin(steps=(self.base_faces*4), dupli=False, degrees=360, center=(0,0,0), axis=(0,0,1))
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.object.editmode_toggle()

thanks

this seems to work but not in my script !




import bpy
import mathutils
from math import *
from bpy.props import *
import random
 
 
nseg1=12
 

object=bpy.context.active_object
print (' Active object  name =',object.name)
 

print ('after bpy.context.object.mode  =',bpy.context.object.mode)
print ()
 
 
 
if bpy.context.object:
 print('  bpy  name =',bpy.context.object.name)
 
 bpy.ops.object.mode_set(mode='EDIT', toggle=False)
 bpy.ops.mesh.select_all(action='SELECT')
 bpy.ops.mesh.fill()
 print ('object ######### filled up  nseg1=',nseg1)
 bpy.context.scene.cursor_location =(0,0,0)
 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
 bpy.ops.object.mode_set(mode='EDIT', toggle=False)
 if bpy.context.object.mode == 'EDIT':
  print('  mode   edit ')
 else:
  print('  mode   edit ')
 
 print(bpy.context.area.type)
 bpy.context.area.type="VIEW_3D"
# bpy.context.area.type="VIEW_3D"
# bpy.ops.mesh.spin(steps=9, dupli=True, degrees=360, center=(0, 0, 0), axis=(0, 0, 1))
 bpy.ops.object.mode_set(mode='EDIT', toggle=False)
 bpy.ops.mesh.select_all(action='SELECT')
# bpy.ops.mesh.spin(steps=nseg1, dupli=False, degrees=360, center=(0, 0, 0), axis=(0, 0, 1))
 bpy.ops.mesh.spin(steps=nseg1, dupli=True, degrees=360, center=(0, 0, 0), axis=(0, 0, 1))
 bpy.context.area.type="TEXT_EDITOR"
 
 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
 bpy.ops.object.shade_smooth()
else:
 print("No context object!")
 
print ('  fill up')
print ()


thanks

this might be indeed a context problem…

make your code an operator itself, then call it via spacebar menu in 3d view to get proper context!

as an operator it will work with spacebar no doubt
but i need this inside the script!

the independant script works fine by itself alone

but when i add it to the other scritp after doing the fill operation it is refusing to work
it has the right object in edit node and should work like in the other stand alone script but it doesn!

there must be a way to make this spin command work !

i saw another step by step way of doing spin
if i have to use that one which is more complicated then i’ll take that one
but much more work!

thanks

what is the IRC channel where we can ask questions for python

may be i’ll get lucky there!

thanks

#blenderpython on irc.freenode.net

just talk to Meta androco and told me
that spin is broken and many bugs report have been done and he does
not think it will be corrected soon = not a priority right now!

so have to try use screw tool or use move rotate things

any example using the screw modifier or screw tool ?
never use these one before !

thanks