how to spin normally ?

i did this little script to spin a cross section called spin1 around origin

now it does the spin ok

but it also changes the text editor window into a 3D view in perspective mode!

so how do i stop that ?


import bpy, math
from bpy.props import *
from mathutils import *
from math import *  

 
print(' area =',bpy.context.area.type)
bpy.context.area.type="VIEW_3D"
print(' area =',bpy.context.area.type)
 
o1=bpy.ops.object.select_name(name="spin1",extend=False)
print ('o1=',o1)
obj = bpy.context.active_object
myMesh = obj.data
print (' myMesh obj =',myMesh.name)
 
bpy.ops.object.mode_set(mode='EDIT')    # force it, be sure! 
bpy.ops.mesh.select_all(action='TOGGLE')
 
bpy.ops.mesh.spin(steps=9, dupli=False, degrees=90, center=(0, 0, 0), axis=(0, 0, 90))
 
 
 

thanks

use the Screw modifier, spin will only work if you have the view3d as a context. (but if you manage to figure out how to do that -without a panel in 3dview), that i would like to know, because that opens up all kinds of cool stuff)

while in object mode


bpy.context.active_object.modifiers.new(name="Screw", type="SCREW")

to see it added you must toggle editmode, or update the modifier parameters


# after this you will see it 
screw_access = bpy.data.objects["Cube"].modifiers["Screw"]
screw_access.angle = PI    # 180 degrees

the rest you can find at


>>> dir(screw_access)
['__doc__', '__module__', '__slots__', 'angle', 'axis', 'bl_rna', 'iterations', 'name', 'object', 'render_steps', 'rna_type', 'screw_offset', 'show_expanded', 'show_in_editmode', 'show_on_cage', 'show_render', 'show_viewport', 'steps', 'type', 'use_apply_on_spline', 'use_normal_calculate', 'use_normal_flip', 'use_object_screw_offset']

make sure you keep screw_offset at 0 for the ‘Lathe’ effect of spin.

api contains so many page on screw word!
it’s total confusion!

i did the following test and get to see all vertices selected in edit mode

but then it cannot find the word Screw?


 
import bpy, math
obj = bpy.context.active_object
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='TOGGLE')
#screw_access = bpy.data.objects["spin1"].modifiers["Screw"]
screw_access = bpy.data.objects["spin1"].modifiers["SCREW"]
 

if spin was working in proper context
and it is very simple to use
if it was not this window changing it would be a great tool!
i’ll experiment to see if there is a way to change the context
but need to find the other script on this subject!

thanks

my code gave the screw modifier a name ‘Screw’ the type of that modifier is ‘SCREW’. just like in the UI you can name your modifiers.

…documentation/bpy.types.Modifier.html

i agree, it would be neat to have access to context from elsewhere.

trying to find this thing about context

i had some script to do that from Mckraken
but awaiting his answer for this cause i cannot find it right now!

this script was run and was able to find another area context and dig into another script
so may be this can be used here!

for area in bpy.context.screen.areas:
print (’ Area type =’, area.type )

this can print all the areas available

but then how to change it !

by the way how do you write it to work the screw command?
i tried many combinations for things and cannot get it to work
unless it works in object mode instead
sometimes i get an out of context error sometimes or erro on the name Screw!

thanks

read my first post again. slowly.

I use spin to create the “standard” base and capital mesh data for the column script I’m working on. It expects the original mode to be 3D view (since that is when you add the object)…


            ob_new = bpy.data.objects.new("Base", meshBase)
            scene.objects.link(ob_new)
            scene.objects.active = ob_new
            ob_new.select = True
            bpy.ops.object.editmode_toggle() # change to edit mode for spin...
            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() # back to 3D View

tried it
like this with selected object
and still giving same error context is incorrect

tried to put before the vertices selection and same error!

hope this can work outside of a panel!


 
import bpy, math
 
obj = bpy.context.active_object
 
bpy.ops.object.select_all(action='DESELECT')
 
o1=bpy.ops.object.select_name(name="spin1",extend=False)
print ('o1=',o1)
obj = bpy.context.active_object
myMesh = obj.data
print (' obj=',obj)
print (' myMesh obj =',myMesh.name)
 
bpy.ops.object.editmode_toggle()     # Edit mode
 
bpy.ops.mesh.spin(steps=9, dupli=False, degrees=360, center=(0,0,0), axis=(0,0,1))
bpy.ops.mesh.select_all(action='SELECT')   # Edit mode  select all vertices
 
bpy.ops.object.editmode_toggle()     # Object mode
 

any idea how to get the proper context?

i cannot upload file here anymore du to some changes
anyone knows how to ?
i can see the little arrow at top right running around but waiting and waitng and nothing seems to happen!

the model is very simple i have a 1/2 circle at a distance from the origin on the X axis front view
called spin1 = ob the mesh seems to have the name Circle.

but it does not really matter the complexity of the shape it should spin!

and want to spin it around Z axis

thanks

i give up.

foud one way
but text editor changes to 3D window then at the end i change it back to text editor

wish there was a better way but it works


import bpy, math
 
bpy.context.area.type="VIEW_3D"
 
 
obj = bpy.context.active_object
 
bpy.ops.object.select_all(action='DESELECT')
 
o1=bpy.ops.object.select_name(name="spin1",extend=False)
print ('o1=',o1)
obj = bpy.context.active_object
print (' obj name =',obj.name)
myMesh = obj.data
print (' obj=',obj)
print (' myMesh name =',myMesh.name)
 
bpy.ops.object.editmode_toggle()     # Edit mode
 
 
bpy.ops.mesh.spin(steps=9, dupli=False, degrees=360, center=(0,0,0), axis=(0,0,1))
bpy.ops.mesh.select_all(action='SELECT')   # Edit mode  select all vertices
 
bpy.ops.object.editmode_toggle()     # Object mode
 
bpy.context.area.type="TEXT_EDITOR
 

happy 2.5

@zeffii as you should… RB is “exploring”…

@RickyBlender

The “fragment” I gave was related to creating an object using an script - expecting “current context” (3D view). You can always change it but that kinda defeats the purpose of a general script - why leave in edit mode? incomplete script is only reason I can think of.

You should never assume what mode started (though I do for create) and never force mode for end unless absolutely necessary for additional use of script (but that defeats toolbar usage if not 3D View).

Just a ramble/comment.

according to ideasman_42 there is no nice way to do this.