[Blender x Python] Blender Python tips (11/100)

This article replaces the operations in CG Boost's 100+ Tips to Boost Modeling in Blender with Python.

table of contents

0.BlenderPython tips

  1. Mode switching
  2. Shader mode switching
  3. Switching transparent mode
  4. MATCAPS settings
  5. Adjust CAVITY
  6. Randomize the color of the object
  7. Focus on the object 8.3 Increase the operability of the D viewport
  8. Allow only selected objects to be displayed
  9. Align the viewpoint to the selected surface

0.BlenderPython tips

● All executed code is displayed in Info

スクリーンショット 2020-11-09 19.06.09.png

Info location: Scripting → Info (bottom left of screen)

● When Python tool tips are enabled, the operation code is displayed in the panel part.

How to enable: Check Edit → preferences → Tooltips and Python Tooltips

● If you press [ctrl + C] with the cursor on the panel (button) in Blender, the Python code will be copied.

ezgif.com-gif-maker (45).gif


1. Mode switching

Object mode and edit mode ↓ ezgif.com-gif-maker (33).gif

#Set to Object Mode
bpy.ops.object.mode_set(mode='OBJECT')
#Set to Edit Mode
bpy.ops.object.mode_set(mode='EDIT')
#Set to Sculpt Mode
bpy.ops.object.mode_set(mode='SCULPT')
#Make it Vertex Paint
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
#Set to Weight Mode
bpy.ops.object.mode_set(mode='WEIGHT_PAINT')
#Set to Texture Mode
bpy.ops.object.mode_set(mode='TEXTURE_PAINT')

2. Shader mode switching

Wireframe and render mode ↓

ezgif.com-gif-maker (34).gif

#Switch to WIREFRAME mode
bpy.context.space_data.shading.type = 'WIREFRAME'
#Set to SOLID mode
bpy.context.space_data.shading.type = 'SOLID'
#Set to MATERIAL mode
bpy.context.space_data.shading.type = 'MATERIAL'
#Set to RENDERED mode
bpy.context.space_data.shading.type = 'RENDERED'

3. Switching transparent mode

#Set to transparent mode
bpy.ops.view3d.toggle_xray()

4. MATCAPS settings

It becomes easier to see dents on the surface ↓

ezgif.com-gif-maker (38).gif

bpy.context.space_data.shading.type = 'SOLID'
bpy.context.space_data.shading.light = 'MATCAP'
#Choose the one you like
bpy.context.space_data.shading.studio_light = 'metal_carpaint.exr'

5. Adjust CAVITY

The structure becomes easier to see ↓ ezgif.com-gif-maker (39).gif

bpy.context.space_data.shading.show_cavity = True
bpy.context.space_data.shading.cavity_type = 'WORLD'
#ridge is a ridge
bpy.context.space_data.shading.cavity_ridge_factor = 1
#valley is a depression
bpy.context.space_data.shading.cavity_valley_factor = 1


6. Randomize the color of the object

ezgif.com-gif-maker (41).gif

bpy.context.space_data.shading.type = 'SOLID'
bpy.context.space_data.shading.color_type = 'RANDOM'

7. Focus on the object

ezgif.com-gif-maker (42).gif

bpy.ops.view3d.view_selected(use_all_regions = False)

8.3 Increase the operability of the D viewport

● Zoom to where the mouse is

PreferencesInput.use_zoom_to_mouse

● Allows you to zoom close to an object

PreferencesInput.use_mouse_depth_navigate

● Allows the field of view to rotate around the selected object

● Can also be used in edit mode

PreferencesInput.use_rotate_around_active

9. Allow only selected objects to be displayed

ezgif.com-gif-maker (43).gif

bpy.ops.view3d.localview()

10. Align the viewpoint to the selected surface

ezgif.com-gif-maker (44).gif

#TOP for the following types,BOTTOM,FRONT,BACK,RIGHT,Contains one of LEFT.
bpy.ops.view3d.view_axis(type = 'TOP',align_active = True)

Recommended Posts

[Blender x Python] Blender Python tips (11/100)
python tips
python tips
Python Tips
Python tips
[Blender x Python] Particle Animation (Part 1)
[Blender x Python] Let's master random !!
[Blender x Python] Let's master rotation !!
Python debugging tips
[Blender x Python] Let's master the material !!
[Blender x Python] How to use modifiers
[Blender x Python] Let's get started with Blender Python !!
Python and numpy tips
blender, python, spiral staircase
Run Blender with python
Python Tips (my memo)
blender, python, sphere behavior
Blender 2.8, Python Cube Scaling
Operate Blender with Python
[Blender x Python] How to make an animation
Python PyTorch install tips
[Blender x Python] How to make vertex animation
[Blender x Python] Think of code with symbols
[Blender x Python] How to create an original object
[Blender x Python] 3D Bouncing Ball and other animations
x86 compiler self-made with python
Register DynamoDB x Python / Decimal
blender, python, spiral staircase, color
Receiving standard input tips @ python
Run Tensorflow 2.x on Python 3.7
[Tips] Handle Athena with Python
2.x, 3.x character code of python
Blender 2.9, Python Odd Even Building
Blender 2.9, Python, hexadecimal color specification
Blender 2.8, Python, light Spot lighting
Blender Python API in Houdini (Python 3)
[Python + Selenium] Tips for scraping
Google Drive Api Tips (Python)
~ Tips for beginners to Python ③ ~
Generate 8 * 8 (64) cubes in Blender Python
Convert python 3.x code to python 2.x
[Blender x Python] Let's arrange a lot of Susanne neatly !!
Draw Sine Waves in Blender Python
Basics of Python x GIS (Part 3)
Install Python 2.7.9 and Python 3.4.x with pip.
Python memo Anaconda x Jupyter Notebook
[Blender] Modeling tips Summary User Interface
[Blender] Modeling tips Summary User Interface Part2
[Blender x Python] Blender Python tips (11/100)
Easy modeling with Blender and Python
Python
Tips on Python file input / output
LaTeX, Python tips in master's thesis
Blender 2.8, Python Cube, Lighting, Camera Circumference
Run mruby with Python or Blender
Install Pytorch on Blender 2.90 python on Windows
GitHub x Python development preparation memo
Use blender as a python module
[TouchDesigner] Tips for for statements using python
Tips for calling Python from C
python x tensoflow x image face recognition
Basics of Python x GIS (Part 2)
Write python list fast vim tips
Access Blender Shader Nodes from Python