Blender Python #0003

By telleropnul, March 27, 2020

Redraw

bpy.context.view_layer layer.update()

bpy.context.area.tag_redraw()      # granted the context area is the one you are working with

Voxel remesher

 

Camera

1. dolly in / out
2. pedestal up / down
3. truck left / right
4. pan left / right
5. tilt up / down
6. roll left / right

7. Zoom in / out
Zooming involves changing the focal length of the lens to make an object appear closer or further away. It’s an unnatural and overused movement. Dolly is preferred. If you absolutely must use a zoom, use a very slow one.

Track To camera constraint

Add a camera.
Constraints > Track To

Target: select object you want to track (tracks origin of object)
To: -Z
Up: Y

To understand those settings you have to think of the LOCAL AXES for the camera: X is Horizontal, Y vertical and Z is depth. Negative Z is what is in front of the camera.

 

Copy animation keyframes to another object

Select both objects in Outliner.
Make sure to select the object without keyframes last.
In 3D viewport, [SHIFT]+[L] to link.
Select animation data.

Also works for materials, particle systems, etc.

Make Single User

[SHIFT+D] Duplicates an object.
[ALT+D] Creates an instance of an object.

Duplicating creates a new object with a copy of the mesh object data ‘inside’ it.  You can expand Outliner and see each duplicate object has a unique name and contain a copy of the mesh data with a unique name as well.

Instancing creates a new object with a link to the original object’s mesh object data ‘inside it’.  You can expand Outliner and see each duplicate object has a unique name and contain the same mesh data with the same single name.

In order to apply transforms e.g. applying scale to objects with multi-user instanced single mesh: do this:

Select all the instanced objects
[F3] search for "single" to find "make single user", or
Objects > Relations > Make Single User > Object & Data, or
Object Data Properties (green triangle) and click on the "number of users" number for a mesh to make it single user.
Now you can apply the scale using CTRL+A

If you want to recreate the instances:

keep all your objects selected and press CTRL+L > Object Data

Outliner > Orphan Data

This video explains:
– relationship between objects <-> materials <-> image texture files
– linking materials
– materials users count
– image browser
– [X symbol button] = unlinking = sort of like removing, but does not purge
– [COPY symbol button] = duplicating a material = making images / materials unique = making them single user = does the same as clicking users count number.
– [SHIFT clicking X symbol] = unlink everywhere = think remove everywhere else this image was used, but does not purge.

To purge: – Outliner > Orphaned Data > select entries and RMB > Delete to purge permanently, or: – Reopen a .blend file and 0 users materials, images, objects will be removed upon load.

Mouse XY

mouseXY.blend

Regions

Note: Data API more strictly pertains to data stored in the blend file itself, it pretty much is the blend file, event and many other systems would not be stored here.

Outliner > Data API:

Window Managers
    WinMan
        Windows
            Window
                Screen
                    Layout
                        Areas
                            Area[n]
                                Regions
                                    Region[n]

View3D regions:
  Tool Header
  Header
  Tools
  UI
  Floating Region
  Window

Logos parametric

logos_parametric.blend

 

Hide

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import bpy
 
# prints the name of hidden objects
def get_hidden():
 
    context = bpy.context
 
    with_eye = []
    with_monitor = []
    with_eye_and_monitor = []
 
    for o in context.view_layer.objects:
 
        if not o.hide_viewport and not o.visible_get():
            with_eye.append(o)
            continue
 
        if o.hide_viewport:
            o.hide_viewport = False # toggle to test visibility
 
            if o.visible_get():
                with_monitor.append(o)
 
            else:
                with_eye_and_monitor.append(o)
 
            o.hide_viewport = True # toggle back
 
    if with_eye:
        print(
            "With eye only:\n",
            [o.name for o in with_eye])
 
    if with_monitor:
        print(
            "With monitor only:\n",
            [o.name for o in with_monitor])
 
    if with_eye_and_monitor:
        print(
            "With eye and monitor:\n",
            [o.name for o in with_eye_and_monitor])
 
get_hidden()

Reveal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import bpy
 
# toggles all cutters
def toggle():
 
    context = bpy.context
    cutters = []
    all_cutters = []
 
 
    # all cutters
    for o in bpy.data.objects:
        for m in o.modifiers:
            if m.type == 'BOOLEAN':
                all_cutters.append(m.object)
 
    # cutters of selected objects
    for o in context.selected_objects:
        for m in o.modifiers:
            if m.type == 'BOOLEAN':
                if m.object.display_type == 'WIRE':
                    cutters.append(m.object)
 
    # cutters of cutters
    for o in cutters:
        for m in o.modifiers:
            if m.type == 'BOOLEAN':
                cutters.append(m.object)
 
    # DEBUG
    print(
            "Cutters:\n",
            [c.name for c in cutters])
 
    # Show cutters collection
    context.view_layer.layer_collection.children['Cutters'].hide_viewport = False
 
    # Outliner Monitor is Evil.  Do not use Monitor.  Eye only.
    for o in context.view_layer.objects:
        o.hide_viewport = False
 
    # Toggle Eye
    for o in cutters:
        o.hide_set (o.visible_get())
 
toggle()