Update for object add align property changes

This commit is contained in:
Brecht Van Lommel 2019-05-15 17:55:28 +02:00
parent 467303ba70
commit 8c37a7fe4a
Notes: blender-bot 2023-02-14 19:15:30 +01:00
Referenced by issue #64685, Boltfactory : AttributeError: type object 'AddObjectHelper' has no attribute 'view_align_update_callback'
24 changed files with 67 additions and 102 deletions

View File

@ -456,7 +456,7 @@ class add_curlycurve(Operator, AddObjectHelper):
col = layout.column(align=True)
# AddObjectHelper props
col.prop(self, "view_align")
col.prop(self, "align")
col.prop(self, "location")
col.prop(self, "rotation")

View File

@ -195,7 +195,7 @@ def add_type1(self, context):
def make_path(self, context, verts):
target = bpy.context.view_layer.objects.active
bpy.ops.curve.primitive_nurbs_path_add(
view_align=False, enter_editmode=False, location=(0, 0, 0)
align='WORLD', enter_editmode=False, location=(0, 0, 0)
)
target.data.taper_object = bpy.context.view_layer.objects.active
taper = bpy.context.view_layer.objects.active
@ -359,7 +359,7 @@ class add_bevelcurve(Operator, AddObjectHelper):
col = layout.column(align=True)
# AddObjectHelper props
col.prop(self, "view_align")
col.prop(self, "align")
col.prop(self, "location")
col.prop(self, "rotation")

View File

@ -237,23 +237,6 @@ class add_mesh_bolt(Operator, AddObjectHelper):
description='Flat distance of the Hex Nut'
)
# generic transform props
view_align: BoolProperty(
name="Align to View",
default=False,
update=AddObjectHelper.view_align_update_callback,
)
location: FloatVectorProperty(
name="Location",
subtype='TRANSLATION',
)
rotation: FloatVectorProperty(
name="Rotation",
subtype='EULER',
)
def draw(self, context):
layout = self.layout
col = layout.column()
@ -314,7 +297,7 @@ class add_mesh_bolt(Operator, AddObjectHelper):
# generic transform props
col.separator()
col.prop(self, 'view_align')
col.prop(self, 'align')
col.prop(self, 'location')
col.prop(self, 'rotation')
@ -355,4 +338,4 @@ def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
bpy.types.VIEW3D_MT_mesh_add.remove(menu_func_bolt)
bpy.types.VIEW3D_MT_mesh_add.remove(menu_func_bolt)

View File

@ -1,7 +1,10 @@
# GPL # "author": "Kayo Phoenix"
import bpy
from bpy_extras import object_utils
from bpy_extras.object_utils import (
AddObjectHelper,
object_data_add,
)
from math import (
pi, sin,
cos,
@ -207,7 +210,7 @@ def edge_max(diam):
return diam * sin(pi / 3)
class add_mesh_honeycomb(bpy.types.Operator):
class add_mesh_honeycomb(bpy.types.Operator, AddObjectHelper):
bl_idname = "mesh.honeycomb_add"
bl_label = "Add HoneyComb"
bl_description = "Simple honeycomb mesh generator"
@ -248,19 +251,6 @@ class add_mesh_honeycomb(bpy.types.Operator):
min=0.0, update=fix_edge,
description='Width of the edge'
)
# generic transform props
view_align: BoolProperty(
name="Align to View",
default=False
)
location: FloatVectorProperty(
name="Location",
subtype='TRANSLATION'
)
rotation: FloatVectorProperty(
name="Rotation",
subtype='EULER'
)
@classmethod
def poll(cls, context):
@ -275,6 +265,6 @@ class add_mesh_honeycomb(bpy.types.Operator):
mesh.from_pydata(vertices=verts, edges=[], faces=faces)
mesh.update()
object_utils.object_data_add(context, mesh, operator=self)
object_data_add(context, mesh, operator=self)
return {'FINISHED'}

View File

@ -3,6 +3,12 @@
# This file is distributed under the MIT License. See the LICENSE.md for more details.
import bpy
from bpy_extras.object_utils import (
AddObjectHelper,
object_data_add,
)
from bpy.props import (
IntProperty,
BoolProperty,
@ -138,7 +144,7 @@ class MengerSponge(object):
depth - 1)
class AddMengerSponge(bpy.types.Operator):
class AddMengerSponge(bpy.types.Operator, AddObjectHelper):
bl_idname = "mesh.menger_sponge_add"
bl_label = "Menger Sponge"
bl_description = "Construct a menger sponge mesh"
@ -156,19 +162,6 @@ class AddMengerSponge(bpy.types.Operator):
min=0.01, max=100.0,
default=1.0,
)
# generic transform props
view_align: BoolProperty(
name="Align to View",
default=False,
)
location: FloatVectorProperty(
name="Location",
subtype='TRANSLATION',
)
rotation: FloatVectorProperty(
name="Rotation",
subtype='EULER',
)
layers: BoolVectorProperty(
name="Layers",
size=20,
@ -188,7 +181,6 @@ class AddMengerSponge(bpy.types.Operator):
for i, uvloop in enumerate(mesh.uv_layers.active.data):
uvloop.uv = uvs[i % 4]
from bpy_extras import object_utils
object_utils.object_data_add(context, mesh, operator=self)
object_data_add(context, mesh, operator=self)
return {'FINISHED'}

View File

@ -37,7 +37,7 @@ def create_lamp(context, loc):
bpy.ops.object.light_add(
type='POINT',
radius=1,
view_align=False,
align='WORLD',
location=loc)
lamp = context.active_object
lamp.data.use_nodes = True
@ -47,7 +47,7 @@ def create_lamp(context, loc):
def create_camera(context, loc, rot):
bpy.ops.object.camera_add(
view_align=True,
align='VIEW',
enter_editmode=False,
location=loc,
rotation=rot)
@ -159,7 +159,7 @@ def generateThumb(context, cls, preset, engine):
# add plane
bpy.ops.mesh.primitive_plane_add(
size=1000,
view_align=False,
align='WORLD',
enter_editmode=False,
location=(0, 0, 0)
)

View File

@ -525,7 +525,7 @@ def build_dolly_rig(context):
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.camera_add(
view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0))
align='WORLD', enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0))
cam = bpy.context.active_object
# this will name the Camera Object
@ -711,7 +711,7 @@ def build_crane_rig(context):
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.camera_add(
view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0))
align='WORLD', enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0))
cam = bpy.context.active_object
# this will name the Camera Object

View File

@ -292,7 +292,7 @@ def main(report, File, Path, LayerViewers, MixerViewers, LayerOffset,
LayerNum += 1
# Object
bpy.ops.mesh.primitive_plane_add(view_align=False,
bpy.ops.mesh.primitive_plane_add(align='WORLD',
enter_editmode=False,
rotation=(0, 0, 0))

View File

@ -694,24 +694,24 @@ def draw_atoms_one_type(draw_all_atoms_type,
# Now, build a representative sphere (atom).
if atom[0] == "Vacancy":
bpy.ops.mesh.primitive_cube_add(
view_align=False, enter_editmode=False,
align='WORLD', enter_editmode=False,
location=(0.0, 0.0, 0.0),
rotation=(0.0, 0.0, 0.0))
else:
# NURBS balls
if Ball_type == "0":
bpy.ops.surface.primitive_nurbs_surface_sphere_add(
view_align=False, enter_editmode=False,
align='WORLD', enter_editmode=False,
location=(0,0,0), rotation=(0.0, 0.0, 0.0))
# UV balls
elif Ball_type == "1":
bpy.ops.mesh.primitive_uv_sphere_add(
segments=Ball_azimuth, ring_count=Ball_zenith,
view_align=False, enter_editmode=False,
align='WORLD', enter_editmode=False,
location=(0,0,0), rotation=(0, 0, 0))
# Meta balls
elif Ball_type == "2":
bpy.ops.object.metaball_add(type='BALL', view_align=False,
bpy.ops.object.metaball_add(type='BALL', align='WORLD',
enter_editmode=False, location=(0, 0, 0),
rotation=(0, 0, 0))
@ -1141,7 +1141,7 @@ def draw_sticks_normal(all_atoms,
radius=Stick_diameter,
depth=v.length,
end_fill_type='NGON',
view_align=False,
align='WORLD',
enter_editmode=False,
location=location,
rotation=(0, 0, 0))
@ -1211,7 +1211,7 @@ def draw_sticks_normal(all_atoms,
else:
# Here we use an empty ...
bpy.ops.object.empty_add(type='ARROWS',
view_align=False,
align='WORLD',
location=(0, 0, 0),
rotation=(0, 0, 0))
sticks_empty = bpy.context.view_layer.objects.active

View File

@ -534,25 +534,25 @@ def draw_obj(atom_shape, atom, new_material):
segments=32,
ring_count=32,
radius=1,
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0, 0, 0))
if atom_shape == '1b': #Sphere NURBS
bpy.ops.surface.primitive_nurbs_surface_sphere_add(
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0.0, 0.0, 0.0))
if atom_shape == '2': #Cube
bpy.ops.mesh.primitive_cube_add(
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0.0, 0.0, 0.0))
if atom_shape == '3': #Plane
bpy.ops.mesh.primitive_plane_add(
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0.0, 0.0, 0.0))
@ -561,13 +561,13 @@ def draw_obj(atom_shape, atom, new_material):
vertices=32,
radius=1,
fill_type='NOTHING',
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0, 0, 0))
if atom_shape == '4b': #Circle NURBS
bpy.ops.surface.primitive_nurbs_surface_circle_add(
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0, 0, 0))
@ -576,7 +576,7 @@ def draw_obj(atom_shape, atom, new_material):
bpy.ops.mesh.primitive_ico_sphere_add(
subdivisions=int(index[atom_shape]),
radius=1,
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0, 0, 0))
@ -586,13 +586,13 @@ def draw_obj(atom_shape, atom, new_material):
radius=1,
depth=2,
end_fill_type='NGON',
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0, 0, 0))
if atom_shape == '6b': #Cylinder NURBS
bpy.ops.surface.primitive_nurbs_surface_cylinder_add(
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0, 0, 0))
@ -603,7 +603,7 @@ def draw_obj(atom_shape, atom, new_material):
radius2=0,
depth=2,
end_fill_type='NGON',
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0, 0, 0))
@ -611,7 +611,7 @@ def draw_obj(atom_shape, atom, new_material):
bpy.ops.mesh.primitive_torus_add(
rotation=(0, 0, 0),
location=atom.location,
view_align=False,
align='WORLD',
major_radius=1,
minor_radius=0.25,
major_segments=48,
@ -620,7 +620,7 @@ def draw_obj(atom_shape, atom, new_material):
abso_minor_rad=0.5)
if atom_shape == '8b': #Torus NURBS
bpy.ops.surface.primitive_nurbs_surface_torus_add(
view_align=False,
align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0, 0, 0))
@ -699,7 +699,7 @@ def draw_obj_special(atom_shape, atom):
# F2+ center
if atom_shape == '1':
# Create first a cube
bpy.ops.mesh.primitive_cube_add(view_align=False,
bpy.ops.mesh.primitive_cube_add(align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0.0, 0.0, 0.0))
@ -763,7 +763,7 @@ def draw_obj_special(atom_shape, atom):
# F+ center
if atom_shape == '2':
# Create first a cube
bpy.ops.mesh.primitive_cube_add(view_align=False,
bpy.ops.mesh.primitive_cube_add(align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0.0, 0.0, 0.0))
@ -790,7 +790,7 @@ def draw_obj_special(atom_shape, atom):
# Create now an electron
scale = atom.scale / 10.0
bpy.ops.surface.primitive_nurbs_surface_sphere_add(
view_align=False,
align='WORLD',
enter_editmode=False,
location=(0.0, 0.0, 0.0),
rotation=(0.0, 0.0, 0.0))
@ -850,7 +850,7 @@ def draw_obj_special(atom_shape, atom):
# F0 center
if atom_shape == '3':
# Create first a cube
bpy.ops.mesh.primitive_cube_add(view_align=False,
bpy.ops.mesh.primitive_cube_add(align='WORLD',
enter_editmode=False,
location=atom.location,
rotation=(0.0, 0.0, 0.0))
@ -877,7 +877,7 @@ def draw_obj_special(atom_shape, atom):
# Create now two electrons
scale = atom.scale / 10.0
bpy.ops.surface.primitive_nurbs_surface_sphere_add(
view_align=False,
align='WORLD',
enter_editmode=False,
location=(scale[0]*1.5,0.0,0.0),
rotation=(0.0, 0.0, 0.0))
@ -886,7 +886,7 @@ def draw_obj_special(atom_shape, atom):
electron1.name = atom.name + "_F0_electron1"
electron1.parent = cube
bpy.ops.surface.primitive_nurbs_surface_sphere_add(
view_align=False,
align='WORLD',
enter_editmode=False,
location=(-scale[0]*1.5,0.0,0.0),
rotation=(0.0, 0.0, 0.0))

View File

@ -666,24 +666,24 @@ def import_xyz(Ball_type,
# Now, build a representative sphere (atom)
if atom.name == "Vacancy":
bpy.ops.mesh.primitive_cube_add(
view_align=False, enter_editmode=False,
align='WORLD', enter_editmode=False,
location=(0.0, 0.0, 0.0),
rotation=(0.0, 0.0, 0.0))
else:
# NURBS balls
if Ball_type == "0":
bpy.ops.surface.primitive_nurbs_surface_sphere_add(
view_align=False, enter_editmode=False,
align='WORLD', enter_editmode=False,
location=(0,0,0), rotation=(0.0, 0.0, 0.0))
# UV balls
elif Ball_type == "1":
bpy.ops.mesh.primitive_uv_sphere_add(
segments=Ball_azimuth, ring_count=Ball_zenith,
view_align=False, enter_editmode=False,
align='WORLD', enter_editmode=False,
location=(0,0,0), rotation=(0, 0, 0))
# Meta balls
elif Ball_type == "2":
bpy.ops.object.metaball_add(type='BALL', view_align=False,
bpy.ops.object.metaball_add(type='BALL', align='WORLD',
enter_editmode=False, location=(0, 0, 0),
rotation=(0, 0, 0))

View File

@ -137,7 +137,7 @@ class OBJECT_OT_create_lightfield_rig(Operator):
def createCameraAnimated(self):
scene = bpy.context.scene
bpy.ops.object.camera_add(view_align=False)
bpy.ops.object.camera_add(align='WORLD')
cam = bpy.context.active_object
cam.name = "light_field_camera"
@ -176,7 +176,7 @@ class OBJECT_OT_create_lightfield_rig(Operator):
for cam_idx, vert in enumerate(self.verts):
# add and name camera
bpy.ops.object.camera_add(view_align=False)
bpy.ops.object.camera_add(align='WORLD')
cam = bpy.context.active_object
cam.name = "light_field_cam_" + str(cam_idx)

View File

@ -3507,7 +3507,7 @@ class GPENCIL_OT_SURFSK_init(Operator):
if not context.scene.bsurfaces.SURFSK_use_annotation and bs.SURFSK_object_with_strokes == None:
bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT')
bpy.ops.object.gpencil_add(radius=1.0, view_align=False, location=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0), type='EMPTY')
bpy.ops.object.gpencil_add(radius=1.0, align='WORLD', location=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0), type='EMPTY')
bpy.context.scene.tool_settings.gpencil_stroke_placement_view3d = 'SURFACE'
gpencil_object = bpy.context.scene.objects[bpy.context.scene.objects[-1].name]
gpencil_object.select_set(True)

View File

@ -365,7 +365,7 @@ class lattice_along_surface(Operator):
bb = max - min
lattice_loc = (max + min) / 2
bpy.ops.object.add(type='LATTICE', view_align=False,
bpy.ops.object.add(type='LATTICE', align='WORLD',
enter_editmode=False)
lattice = bpy.context.active_object
lattice.location = lattice_loc

View File

@ -2,7 +2,7 @@ import bpy
op = bpy.context.active_operator
op.location = (0.0, 0.0, 0.0)
op.view_align = False
op.align = 'WORLD'
op.rotation = (0.0, 0.0, 0.0)
op.options_plus = False
op.absolute_location = False

View File

@ -2,7 +2,7 @@ import bpy
op = bpy.context.active_operator
op.location = (0.0, 0.0, 0.0)
op.view_align = False
op.align = 'WORLD'
op.rotation = (0.0, 0.0, 0.0)
op.options_plus = False
op.absolute_location = False

View File

@ -2,7 +2,7 @@ import bpy
op = bpy.context.active_operator
op.location = (0.0, 0.0, 0.0)
op.view_align = False
op.align = 'WORLD'
op.rotation = (0.0, 0.0, 0.0)
op.options_plus = False
op.absolute_location = False

View File

@ -2,7 +2,7 @@ import bpy
op = bpy.context.active_operator
op.location = (0.0, 0.0, 0.0)
op.view_align = False
op.align = 'WORLD'
op.rotation = (0.0, 0.0, 0.0)
op.options_plus = True
op.absolute_location = False

View File

@ -2,7 +2,7 @@ import bpy
op = bpy.context.active_operator
op.location = (0.0, 0.0, 0.0)
op.view_align = False
op.align = 'WORLD'
op.rotation = (0.0, 0.0, 0.0)
op.options_plus = True
op.absolute_location = False

View File

@ -3,7 +3,7 @@ op = bpy.context.active_operator
op.rotation = (0.0, 0.0, 0.0)
op.location = (0.0, 0.0, 0.0)
op.view_align = False
op.align = 'WORLD'
op.options_plus = True
op.absolute_location = False
op.use_colors = True

View File

@ -2,7 +2,7 @@ import bpy
op = bpy.context.active_operator
op.location = (0.0, 0.0, 0.0)
op.view_align = False
op.align = 'WORLD'
op.rotation = (0.0, 0.0, 0.0)
op.options_plus = True
op.absolute_location = False

View File

@ -2,7 +2,7 @@ import bpy
op = bpy.context.active_operator
op.location = (0.0, 0.0, 0.0)
op.view_align = False
op.align = 'WORLD'
op.rotation = (0.0, 0.0, 0.0)
op.options_plus = True
op.absolute_location = False

View File

@ -3,7 +3,7 @@ op = bpy.context.active_operator
op.rotation = (0.0, 0.0, 0.0)
op.location = (0.0, 0.0, 0.0)
op.view_align = False
op.align = 'WORLD'
op.options_plus = True
op.absolute_location = False
op.use_colors = True

View File

@ -2,7 +2,7 @@ import bpy
op = bpy.context.active_operator
op.location = (0.0, 0.0, 0.0)
op.view_align = False
op.align = 'WORLD'
op.rotation = (0.0, 0.0, 0.0)
op.options_plus = True
op.absolute_location = False