[Bf-blender-cvs] [3a7af37e280] master: Python API Docs: fix some examples
Jacques Lucke
noreply at git.blender.org
Thu Jun 6 17:13:13 CEST 2019
Commit: 3a7af37e280276026e937aa95aefde11290741d2
Author: Jacques Lucke
Date: Thu Jun 6 17:12:49 2019 +0200
Branches: master
https://developer.blender.org/rB3a7af37e280276026e937aa95aefde11290741d2
Python API Docs: fix some examples
===================================================================
M doc/python_api/examples/bmesh.ops.1.py
M doc/python_api/examples/bpy.data.py
M doc/python_api/examples/bpy.props.1.py
M doc/python_api/examples/bpy.types.Menu.1.py
M doc/python_api/examples/bpy.types.NodeTree.py
M doc/python_api/examples/bpy.types.Panel.1.py
M doc/python_api/examples/bpy.types.Panel.2.py
M doc/python_api/examples/bpy.types.UIList.1.py
M doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.1.py
M doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.py
M doc/python_api/examples/mathutils.Color.py
M doc/python_api/examples/mathutils.Euler.py
M doc/python_api/examples/mathutils.Matrix.py
M doc/python_api/examples/mathutils.Quaternion.py
M doc/python_api/examples/mathutils.Vector.py
M doc/python_api/examples/mathutils.kdtree.py
M doc/python_api/examples/mathutils.py
===================================================================
diff --git a/doc/python_api/examples/bmesh.ops.1.py b/doc/python_api/examples/bmesh.ops.1.py
index d6a5b1222d8..1576f676d2c 100644
--- a/doc/python_api/examples/bmesh.ops.1.py
+++ b/doc/python_api/examples/bmesh.ops.1.py
@@ -99,10 +99,9 @@ bm.free()
# Add the mesh to the scene
-scene = bpy.context.scene
obj = bpy.data.objects.new("Object", me)
-scene.objects.link(obj)
+bpy.context.collection.objects.link(obj)
# Select and make active
-scene.objects.active = obj
-obj.select = True
+bpy.context.view_layer.objects.active = obj
+obj.select_set(True)
diff --git a/doc/python_api/examples/bpy.data.py b/doc/python_api/examples/bpy.data.py
index 7d6bf94532b..c06199d8af3 100644
--- a/doc/python_api/examples/bpy.data.py
+++ b/doc/python_api/examples/bpy.data.py
@@ -19,9 +19,6 @@ if "Cube" in bpy.data.meshes:
# write images into a file next to the blend
import os
-file = open(os.path.splitext(bpy.data.filepath)[0] + ".txt", 'w')
-
-for image in bpy.data.images:
- file.write("%s %d x %d\n" % (image.filepath, image.size[0], image.size[1]))
-
-file.close()
+with open(os.path.splitext(bpy.data.filepath)[0] + ".txt", 'w') as fs:
+ for image in bpy.data.images:
+ fs.write("%s %d x %d\n" % (image.filepath, image.size[0], image.size[1]))
diff --git a/doc/python_api/examples/bpy.props.1.py b/doc/python_api/examples/bpy.props.1.py
index e442faf245b..a7055fd4712 100644
--- a/doc/python_api/examples/bpy.props.1.py
+++ b/doc/python_api/examples/bpy.props.1.py
@@ -34,8 +34,8 @@ class OBJECT_PT_property_example(bpy.types.Panel):
bl_idname = "object_PT_property_example"
bl_label = "Property Example"
bl_space_type = 'VIEW_3D'
- bl_region_type = 'TOOLS'
- bl_category = "Tools"
+ bl_region_type = 'UI'
+ bl_category = "Tool"
def draw(self, context):
# You can set the property values that should be used when the user
diff --git a/doc/python_api/examples/bpy.types.Menu.1.py b/doc/python_api/examples/bpy.types.Menu.1.py
index 8ccc1123c35..c07e647c660 100644
--- a/doc/python_api/examples/bpy.types.Menu.1.py
+++ b/doc/python_api/examples/bpy.types.Menu.1.py
@@ -24,7 +24,7 @@ class SubMenu(bpy.types.Menu):
layout.separator()
# expand each operator option into this menu
- layout.operator_enum("object.lamp_add", "type")
+ layout.operator_enum("object.light_add", "type")
layout.separator()
diff --git a/doc/python_api/examples/bpy.types.NodeTree.py b/doc/python_api/examples/bpy.types.NodeTree.py
index e969c1a41dc..fc926cc47af 100644
--- a/doc/python_api/examples/bpy.types.NodeTree.py
+++ b/doc/python_api/examples/bpy.types.NodeTree.py
@@ -16,6 +16,7 @@ import bpy
class CyclesNodeTree(bpy.types.NodeTree):
""" This operator is only visible when Cycles is the selected render engine"""
bl_label = "Cycles Node Tree"
+ bl_icon = 'NONE'
@classmethod
def poll(cls, context):
diff --git a/doc/python_api/examples/bpy.types.Panel.1.py b/doc/python_api/examples/bpy.types.Panel.1.py
index b409f8dadea..911ece7ade0 100644
--- a/doc/python_api/examples/bpy.types.Panel.1.py
+++ b/doc/python_api/examples/bpy.types.Panel.1.py
@@ -22,17 +22,11 @@ class ObjectSelectPanel(bpy.types.Panel):
def draw_header(self, context):
layout = self.layout
- obj = context.object
- layout.prop(obj, "select", text="")
+ layout.label(text="My Select Panel")
def draw(self, context):
layout = self.layout
- obj = context.object
- row = layout.row()
- row.prop(obj, "hide_select")
- row.prop(obj, "hide_render")
-
box = layout.box()
box.label(text="Selection Tools")
box.operator("object.select_all").action = 'TOGGLE'
diff --git a/doc/python_api/examples/bpy.types.Panel.2.py b/doc/python_api/examples/bpy.types.Panel.2.py
index 2c860e3e1a7..ee7dae5f186 100644
--- a/doc/python_api/examples/bpy.types.Panel.2.py
+++ b/doc/python_api/examples/bpy.types.Panel.2.py
@@ -9,7 +9,8 @@ import bpy
class View3DPanel:
bl_space_type = 'VIEW_3D'
- bl_region_type = 'TOOLS'
+ bl_region_type = 'UI'
+ bl_category = "Tool"
@classmethod
def poll(cls, context):
diff --git a/doc/python_api/examples/bpy.types.UIList.1.py b/doc/python_api/examples/bpy.types.UIList.1.py
index 92b115b2af4..6fbb8890fc7 100644
--- a/doc/python_api/examples/bpy.types.UIList.1.py
+++ b/doc/python_api/examples/bpy.types.UIList.1.py
@@ -40,18 +40,6 @@ class MATERIAL_UL_matslots_example(bpy.types.UIList):
layout.prop(ma, "name", text="", emboss=False, icon_value=icon)
else:
layout.label(text="", translate=False, icon_value=icon)
- # And now we can add other UI stuff...
- # Here, we add nodes info if this material uses (old!) shading nodes.
- if ma and not context.scene.render.use_shading_nodes:
- manode = ma.active_node_material
- if manode:
- # The static method UILayout.icon returns the integer value of the icon ID "computed" for the given
- # RNA object.
- layout.label(text="Node %s" % manode.name, translate=False, icon_value=layout.icon(manode))
- elif ma.use_nodes:
- layout.label(text="Node <none>", translate=False)
- else:
- layout.label(text="")
# 'GRID' layout type should be as compact as possible (typically a single icon!).
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
diff --git a/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.1.py b/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.1.py
index 27706c06688..6a56683732d 100644
--- a/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.1.py
+++ b/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.1.py
@@ -28,7 +28,7 @@ obj = bpy.data.objects["Armature"]
arm = obj.data
# Set the keyframe at frame 1.
-arm.bones["Bone"].my_prop_group.nested = 10
+arm.bones["Bone"].my_prop.nested = 10
arm.keyframe_insert(
data_path='bones["Bone"].my_prop.nested',
frame=1,
diff --git a/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.py b/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.py
index f1f4b98b32f..13fe848bdad 100644
--- a/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.py
+++ b/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.py
@@ -7,5 +7,5 @@ import bpy
obj = bpy.context.object
# set the keyframe at frame 1
-obj.location = 3.0, 4.0, 10.0
+obj.location = (3.0, 4.0, 10.0)
obj.keyframe_insert(data_path="location", frame=1)
diff --git a/doc/python_api/examples/mathutils.Color.py b/doc/python_api/examples/mathutils.Color.py
index cedda98ae53..3b33003cac1 100644
--- a/doc/python_api/examples/mathutils.Color.py
+++ b/doc/python_api/examples/mathutils.Color.py
@@ -27,4 +27,4 @@ col += mathutils.Color((0.25, 0.0, 0.0))
print("Color: %d, %d, %d" % (col * 255.0)[:])
# This example prints the color as hexadecimal
-print("Hexadecimal: %.2x%.2x%.2x" % (col * 255.0)[:])
+print("Hexadecimal: %.2x%.2x%.2x" % (int(col.r * 255), int(col.g * 255), int(col.b * 255)))
diff --git a/doc/python_api/examples/mathutils.Euler.py b/doc/python_api/examples/mathutils.Euler.py
index bfd2a3ed5a0..f1fcd53c70f 100644
--- a/doc/python_api/examples/mathutils.Euler.py
+++ b/doc/python_api/examples/mathutils.Euler.py
@@ -29,4 +29,4 @@ vec.rotate(eul)
# transformations with more flexibility
mat_rot = eul.to_matrix()
mat_loc = mathutils.Matrix.Translation((2.0, 3.0, 4.0))
-mat = mat_loc * mat_rot.to_4x4()
+mat = mat_loc @ mat_rot.to_4x4()
diff --git a/doc/python_api/examples/mathutils.Matrix.py b/doc/python_api/examples/mathutils.Matrix.py
index 079070a5ec7..26c7ccba27c 100644
--- a/doc/python_api/examples/mathutils.Matrix.py
+++ b/doc/python_api/examples/mathutils.Matrix.py
@@ -11,7 +11,7 @@ mat_sca = mathutils.Matrix.Scale(0.5, 4, (0.0, 0.0, 1.0))
mat_rot = mathutils.Matrix.Rotation(math.radians(45.0), 4, 'X')
# combine transformations
-mat_out = mat_loc * mat_rot * mat_sca
+mat_out = mat_loc @ mat_rot @ mat_sca
print(mat_out)
# extract components back out of the matrix
diff --git a/doc/python_api/examples/mathutils.Quaternion.py b/doc/python_api/examples/mathutils.Quaternion.py
index 8a40389a8d6..315a0024ee9 100644
--- a/doc/python_api/examples/mathutils.Quaternion.py
+++ b/doc/python_api/examples/mathutils.Quaternion.py
@@ -13,7 +13,7 @@ print("Check quaternions match", quat_a == quat_b)
# like matrices, quaternions can be multiplied to accumulate rotational values
quat_a = mathutils.Quaternion((0.0, 1.0, 0.0), math.radians(90.0))
quat_b = mathutils.Quaternion((0.0, 0.0, 1.0), math.radians(45.0))
-quat_out = quat_a * quat_b
+quat_out = quat_a @ quat_b
# print the quat, euler degrees for mere mortals and (axis, angle)
print("Final Rotation:")
diff --git a/doc/python_api/examples/mathutils.Vector.py b/doc/python_api/examples/mathutils.Vector.py
index a8db4aa6691..4d8bf8c065c 100644
--- a/doc/python_api/examples/mathutils.Vector.py
+++ b/doc/python_api/examples/mathutils.Vector.py
@@ -32,11 +32,10 @@ vec_a <= vec_b
# Math can be performed on Vector classes
vec_a + vec_b
vec_a - vec_b
-vec_a * vec_b
+vec_a @ vec_b
vec_a * 10.0
-matrix * vec_a
-quat * vec_a
-vec_a * vec_b
+matrix @ vec_a
+quat @ vec_a
-vec_a
diff --git a/doc/python_api/examples/mathutils.kdtree.py b/doc/python_api/examples/mathutils.kdtree.py
index 18e61a2bc58..8799f4ecb96 100644
--- a/doc/python_api/examples/mathutils.kdtree.py
+++ b/doc/python_api/examples/mathutils.kdtree.py
@@ -4,9 +4,6 @@ import mathutils
from bpy import context
obj = context.object
-# 3d cursor relative to the object data
-co_find = context.scene.cursor_location * obj.matrix_world.inverted()
-
mesh = obj.data
size = len(mesh.vertices)
kd = mathutils.kdtree.KDTree(size)
@@ -22,6 +19,8 @@ co_find = (0.0, 0.0, 0.0)
co, index, dist = kd.find(co_find)
print("Close to center:", co, index, dist)
+# 3d cursor relative to the object data
+co_find = obj.matrix_world.inverted() @ context.scene.cursor.location
# Find the closest 10 points to t
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list