I tried to get started with blender python script_Part 01

How to run python in Blender?

There is a Python console!

image01.png

Why a Python tutorial here too?

Geometry Generate Geometry with a Python script.

import bpy

#Remove default Cube
def delete_all():
    for item in bpy.context.scene.objects:
        bpy.context.scene.objects.unlink(item)

    for item in bpy.data.objects:
        bpy.data.objects.remove(item)

    for item in bpy.data.meshes:
        bpy.data.meshes.remove(item)

    for item in bpy.data.materials:
        bpy.data.materials.remove(item)

delete_all()

#Define vertex coordinates
coords=[
    (-1.0, -1.0, -1.0),
    ( 1.0, -1.0, -1.0),
    ( 1.0,  1.0, -1.0),
    (-1.0,  1.0, -1.0),
    ( 0.0,  0.0,  1.0)
]

#Define a face using this subscript
#Each face is defined by a sequence of four integers
#Triangular face must have the same first and fourth vertices
faces=[
    (2,1,0,3),
    (0,1,4,0),
    (1,2,4,1),
    (2,3,4,2),
    (3,0,4,3)
]

#Create a new mesh
me          = bpy.data.meshes.new("PyramidMesh")
#Create an object with a mesh
ob          = bpy.data.objects.new("Pyramid", me)
#Place the object at the 3D cursor position
ob.location = bpy.context.scene.cursor_location
#Link objects to scenes
bpy.context.scene.objects.link(ob)
#Fill the vertices, edges, and faces of the mesh
me.from_pydata(coords,[],faces)
#Update mesh with new data
me.update(calc_edges=True)

Caution

Do not use Japanese for comments (even comments are garbled)

motion01.gif

Recommended Posts

I tried to get started with blender python script_Part 01
I tried to get started with blender python script_Part 02
I tried to get started with Hy
I tried to get CloudWatch data with Python
[Python] A memo that I tried to get started with asyncio
Link to get started with python
How to get started with Python
Get started with Python in Blender
I tried to get started with Hy ・ Define a class
[Blender x Python] Let's get started with Blender Python !!
I tried to get started with Bitcoin Systre on the weekend
I tried to output LLVM IR with Python
I tried to automate sushi making with python
A layman wants to get started with Python
I tried scraping with Python
I tried to get the authentication code of Qiita API with Python.
Get started with Python! ~ ② Grammar ~
I tried gRPC with Python
I tried scraping with python
I tried to get the movie information of TMDb API with Python
I tried to implement Minesweeper on terminal with python
I tried to touch the CSV file with Python
I tried to draw a route map with Python
I tried to solve the soma cube with python
I tried to implement an artificial perceptron with python
I tried to automatically generate a password with Python3
I tried to solve the problem with Python Vol.1
I tried to analyze J League data with Python
[Python] I tried to get Json of squid ring 2
What I did to get started with Linux commands
I tried to solve AOJ's number theory with Python
Get started with Python! ~ ① Environment construction ~
I tried to touch Python (installation)
I tried web scraping with python.
How to get started with Scrapy
How to get started with Django
I want to debug with Python
I tried running prolog with python 3.8.2.
I tried SMTP communication with Python
I tried to find the entropy of the image with python
I tried to simulate how the infection spreads with Python
I tried to make various "dummy data" with Python faker
I tried "How to get a method decorated in Python"
[Python] I tried to visualize tweets about Corona with WordCloud
Mayungo's Python Learning Episode 3: I tried to print numbers with print
I tried to make GUI tic-tac-toe with Python and Tkinter
I tried to divide the file into folders with Python
[5th] I tried to make a certain authenticator-like tool with python
Step notes to get started with django
I tried to solve the ant book beginner's edition with python
I tried to implement Autoencoder with TensorFlow
I tried to implement permutation in Python
[2nd] I tried to make a certain authenticator-like tool with python
I tried to visualize AutoEncoder with TensorFlow
A memorandum when I tried to get it automatically with selenium
I tried scraping Yahoo News with Python
I started python
I tried to implement PLSA in Python 2
[3rd] I tried to make a certain authenticator-like tool with python
Python3 standard input I tried to summarize
I wrote a script to get you started with AtCoder fast!