Python API Docs: fix some examples
This commit is contained in:
parent
3abb1695cf
commit
3a7af37e28
@ -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)
|
||||
|
@ -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]))
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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'
|
||||
|
@ -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):
|
||||
|
@ -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'
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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)))
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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:")
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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 the 3d cursor
|
||||
print("Close 10 points")
|
||||
@ -31,6 +30,5 @@ for (co, index, dist) in kd.find_n(co_find, 10):
|
||||
|
||||
# Find points within a radius of the 3d cursor
|
||||
print("Close points within 0.5 distance")
|
||||
co_find = context.scene.cursor_location
|
||||
for (co, index, dist) in kd.find_range(co_find, 0.5):
|
||||
print(" ", co, index, dist)
|
||||
|
@ -6,7 +6,7 @@ vec = mathutils.Vector((1.0, 2.0, 3.0))
|
||||
mat_rot = mathutils.Matrix.Rotation(radians(90.0), 4, 'X')
|
||||
mat_trans = mathutils.Matrix.Translation(vec)
|
||||
|
||||
mat = mat_trans * mat_rot
|
||||
mat = mat_trans @ mat_rot
|
||||
mat.invert()
|
||||
|
||||
mat3 = mat.to_3x3()
|
||||
|
Loading…
Reference in New Issue
Block a user