Problem not knowing parameters when dealing with Blender from Python

Blender Python API

Blender has a Python API, and the Documentation is open to the public. I think that if there is a document, I can afford it, so I look at the parameter name from the GUI and search for the document, but I feel that it often does not get caught. Why. The simple story is that the property name displayed in the GUI and the property name in the python API are different.

Concrete example

Point Light

For example, Power displayed by a light source, which is energy if it is an API. No no no. Radius is shadow_soft_size. What is it already? If you drop the creation of the light source in the above figure into the code, it will be as follows

light_add.py


bpy.ops.object.light_add(type='POINT')
light_obj = bpy.context.active_object
light = light_obj.data
light.color = (1.0, 1.0, 1.0)
light.energy = 10
light.specular_factor = 1.0
light.shadow_soft_size = 0.25

Solution

solution

How to find out

  1. Right-click on the property and select Copy Data Path. Or hit the command on the right (Shift + Command + C on macOS)
  2. Paste this on your code. that's all. I spent a huge amount of time getting here, so I'll write it here.

2020/5/21 postscript

If I set the workspace to Scripting, will the code come out when I change it manually? In FreeCAD, it is displayed at the bottom by default. I am grateful that it will be easier to automate. Scripting workspace ~~ By the way, why doesn't it apply even if I change cycles.samples from the code? (Under investigation) ~~ Orz that seems to have changed the setting in another place

Recommended Posts

Problem not knowing parameters when dealing with Blender from Python
How to not escape Japanese when dealing with json in python
Precautions when dealing with control structures in Python 2.6
Character encoding when dealing with files in Python 3
Run Blender with python
Operate Blender with Python
BigQuery-Python was useful when working with BigQuery from Python
Precautions when dealing with ROS MultiArray types in Python
Japanese output when dealing with python in visual studio
ABC163 C problem with python3
Error when playing with python
Xpath summary when extracting data from websites with Python Scrapy
ABC188 C problem with python3
With skype, notify with skype from python!
ABC187 C problem with python
How to deal with the problem that the current directory moves when Python is executed from Atom
Tkinter canvas (window) does not start when running Python 3.7.4 with Atom
Using Rstan from Python with PypeR
Install Python from source with Ansible
Create folders from '01' to '12' with python
Run mruby with Python or Blender
Run Aprili from Python with Orange
Call python from nim with Nimpy
Until dealing with python in Atom
Precautions when using phantomjs from python
When matplotlib doesn't work with python2.7
Access Blender Shader Nodes from Python
Read fbx from python with cinema4d
Easy modeling with Blender and Python
When using MeCab with virtualenv python
Precautions when using six with Python 2.5
Get started with Python in Blender
[Python] Format when to_csv with pandas
Did not change from Python 2 to 3
Dealing with key not found error in pacstrap when installing Arch Linux
How to deal with OAuth2 error when using Google APIs from Python
gRPC-Methods used when dealing with protocol buffers types in Python CopyFrom, Extend
Collecting information from Twitter with Python (Twitter API)
Receive textual data from mysql with python
python note: when easy_install is not available
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
Snippet when searching all bits with python
Play audio files from Python with interrupts
Create wordcloud from your tweet with python3
Note when creating an environment with python
Tips for dealing with binaries in Python
Tweet from python with Twitter Developer + Tweepy
Precautions when solving DP problems with Python
Business efficiency starting from scratch with Python
Decrypt files encrypted with openssl from python with openssl
Working with Azure CosmosDB from Python Part.2
Image acquisition from camera with Python + OpenCV
Dealing with "years and months" in Python
[AtCoder] Solve ABC1 ~ 100 A problem with Python
Getting started with Dynamo from Python boto
Try calling Python from Ruby with thrift
Scraping from an authenticated site with python
Use C ++ functions from python with pybind11
[Blender x Python] Let's get started with Blender Python !!