[Blender x Python] Think of code with symbols

table of contents

  1. Thinking of codes as symbols
  2. Code used this time
  3. What is a variable?
  4. What is a method?
  5. The role of dots (.)
  6. Role of equal (=) Finally

0. Thinking of codes as symbols

To read the code correctly, it is important to ** look at the entire code **.

To see the whole code, the point is to abstract and ** compress the information **. It's easier to understand if it gets shorter !! This is to symbolize the code.

When reading the code, ** reading from the left end ** is not recommended !!!!!!!!!

1. Code used this time

The code to use is the code (↓) that adds the monkey used in the previous article.

bpy.ops.mesh.primitive_monkey_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))

The image of symbolization (abstraction) is as follows.

bpy.ops.mesh.primitive_monkey_add(size←2, enter_editmode←False, align←'WORLD', location←(0, 0, 0), scale←(1, 1, 1))

⬇️ □.□.□.primitive_monkey_add(□←2,□←False,□←'WORLD',□←(0, 0, 0),□←(1, 1, 1))

⬇️ ===> Function (□ ← numerical value, □ ← boolean value, □ ← character string, □ ← tuple, □ ← tuple)

⬇️ ===> Function (argument 1, argument 2, argument 3, argument 4, argument 5)

⬇️ ** Perform the process of adding a monkey using 5 arguments **


2. What is a variable?

Variables are like ** boxes ** that hold data.

If you set the variable as □, the above code will be □.□.□.primitive_monkey_add(□=2,□=False,□='World',□=(0,0,0),□=(1,1,1)) It will be.


3. What is a function?

The function is like a ** output device . The information ( argument **) in () provided is used to perform the specified processing.

Here, ** primitive_monkey_add () ** is the function. Use the ** size and position information ** in () to make the monkey appear.


4. The role of dots (.)

Dots are easy to understand if you think of them as ** right-pointing arrows (→) **. So the first part is bpy → ops → mesh → primitive_monkey_add( ) It will be.

In Japanese, it means ** go inside **. primitive_monkey_add () in mesh in ops in bpy

In other words, it can be said that it is a ** route ** to reach the target (function in this case). ====> primitive_monkey_add( )

5. The role of equal (=)

It is easy to understand if you think that the equal is ** arrow pointing to the left (←) **. In other words, the inside of the method () is

size ← 2, enter_editmode ← False, align ← 'WORLD', location ← (0, 0, 0), scale ← (1, 1, 1)

It will be.

In Japanese, it means ** to substitute for ** ~.

#Assign the integer 2 to the variable size
size = 2, 
#Variable enter with Boolean False_Assign to editmode
enter_editmode = False,
#String'WORLD'To the variable align
align = 'WORLD',
#Tuple(0, 0, 0)To the variable location
location = (0, 0, 0),
#Tuple(1, 1, 1)To the variable scale
scale = (1, 1, 1)

Finally

This time, I aimed to make it easier to understand the whole picture of the code by abstracting the code and thinking with symbols. Anyway, I hope you find it useful to think in terms of symbols.

Recommended Posts

[Blender x Python] Think of code with symbols
2.x, 3.x character code of python
[Blender x Python] Let's get started with Blender Python !!
Think yaml with python
Run Blender with python
Operate Blender with Python
Convert the character code of the file with Python3
Static analysis of Python code with GitLab CI
Get country code with python
Python with VS Code (Windows 10)
x86 compiler self-made with python
Debug Python with VS Code
Document Python code with Doxygen
[Blender x Python] Let's arrange a lot of Susanne neatly !!
Mass generation of QR code with character display by Python
Basics of Python x GIS (Part 3)
Install Python 2.7.9 and Python 3.4.x with pip.
Run mruby with Python or Blender
Getting Started with Python Basics of Python
[Blender x Python] Particle Animation (Part 1)
10 functions of "language with battery" python
Basics of Python x GIS (Part 2)
[Blender x Python] Let's master random !!
Implementation of Dijkstra's algorithm with python
[Blender x Python] Let's master rotation !!
Coexistence of Python2 and 3 with CircleCI (1.0)
Easy modeling with Blender and Python
Get started with Python in Blender
Install python with mac vs code
Basic study of OpenCV with Python
[Blender] List of shortcut keys of Python Console that comes standard with Blender
Let's summarize the degree of coupling between modules with Python code
Installation of Visual studio code and installation of python
Basics of binarized image processing with Python
[Examples of improving Python] Learning Python with Codecademy
[Blender x Python] Let's master the material !!
Execute Python script with cron of TS-220
Check the existence of the file with python
Algorithm learned with Python 8th: Evaluation of algorithm
Clogged with python update of GCP console ①
Easy introduction of speech recognition with Python
[Python3] Rewrite the code object of the function
I tried to get the authentication code of Qiita API with Python.
Source code of sound source separation (machine learning practice series) learned with Python
UnicodeEncodeError struggle with standard output of python3
1. Statistics learned with Python 1-3. Calculation of various statistics (statistics)
The Python project template I think of.
Python code to train and test with Custom Vision of Cognitive Service
Drawing with Matrix-Reinventor of Python Image Processing-
Recommendation of Altair! Data visualization with Python
[Python] Get the character code of the file
Join an online judge with Python 3.x
Light image processing with Python x OpenCV
[Blender x Python] How to use modifiers
Comparison of matrix transpose speeds with Python
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
I tried hundreds of millions of SQLite with python
[Python] Read the source code of Bottle Part 2
Prepare the execution environment of Python3 with Docker
Automatic operation of Chrome with Python + Selenium + pandas