Python Scripting Tutorial Creating a Panel That allows the User to Add and Place Bricks in Blender

Share this & earn $10
3D Blender Tutorials by ianscott888
Published at : 31 Oct 2020
3375 views
65
0

This tutorial shows how to create a set of buttons that can be used to add and place bricks, enabling the user to make simple models out of bricks in Blender.

The tutorial shows how to write Python script to define operators that become buttons in the user interface. The tutorial shows the script needed to add a panel to the interface, the script controls the layout of the buttons in the panel, when the buttons are clicked the code inside the operators is executed.

The operators move the bricks in all directions and rotate the bricks.

An operator adds a new brick to the scene by duplicating the currently selected brick.

The finished file can be downloaded from the following link -

http://blender.freemovies.co.uk/blenderfiles/scripts/bricksTut21.blend

The listing of the Python script is at the end of this description.

Both the finished file and the listing can be downloaded from my website -

http://blender.freemovies.co.uk

Python Listing -

class AddFullOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.add_full_operator"
bl_label = "add full brick"

def execute(self, context):
bpy.ops.object.duplicate()
return {'FINISHED'}

class BricksPanel(bpy.types.Panel):
"""Creates a Tab in the tool shelf"""
bl_label = "Bricks Panel"
bl_idname = "3D_VIEW_TS_bricks"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = "Bricks"

def draw(self, context):
layout = self.layout

row = layout.row()
row.alignment = 'CENTER'
row.operator("object.move_plusy_operator")

row = layout.row()
row.operator("object.move_minusx_operator")
row.operator("object.move_plusx_operator")

row = layout.row()
row.alignment = 'CENTER'
row.operator("object.move_minusy_operator")

row = layout.row()
row.operator("object.move_up_operator")

row = layout.row()
row.operator("object.move_down_operator")

row = layout.row()
row.operator("object.rotate_operator")

row = layout.row()
row.operator("object.add_full_operator")

def register():
bpy.utils.register_class(MovePlusXOperator)
bpy.utils.register_class(MoveMinusXOperator)
bpy.utils.register_class(MovePlusYOperator)
bpy.utils.register_class(MoveMinusYOperator)
bpy.utils.register_class(MoveUpOperator)
bpy.utils.register_class(MoveDownOperator)
bpy.utils.register_class(RotateOperator)
bpy.utils.register_class(AddFullOperator)
bpy.utils.register_class(BricksPanel)

def unregister():
bpy.utils.unregister_class(MovePlusXOperator)
bpy.utils.unregister_class(MoveMinusXOperator)
bpy.utils.unregister_class(MovePlusYOperator)
bpy.utils.unregister_class(MoveMinusYOperator)
bpy.utils.unregister_class(MoveUpOperator)
bpy.utils.unregister_class(MoveDownOperator)
bpy.utils.unregister_class(RotateOperator)
bpy.utils.unregister_class(AddFullOperator)
bpy.utils.unregister_class(BricksPanel)

if __name__ == "__main__":
register()
blenderpythonscript

Lauching a tender loaded from the Beach

Lauching a tender loaded from the Beach

Crime alert | unpredicted affair with hot lady

Crime alert | unpredicted affair with hot lady

Great Beauty Care Guide for You #108

Great Beauty Care Guide for You #108

Marshmello - Alone (Streex Remake) [Monstercat Official Music Video]

Marshmello - Alone (Streex Remake) [Monstercat Official Music Video]

This Workout Will Help Your Butt Get Bigger and Legs Sexier (No Equipment Needed)

This Workout Will Help Your Butt Get Bigger and Legs Sexier (No Equipment Needed)

[Eng/Rom] Nell - Time spent Walking through Memories lyrics 기억을 걷는 시간

[Eng/Rom] Nell - Time spent Walking through Memories lyrics 기억을 걷는 시간

Wear Your Mask Song with Vlad and Niki

Wear Your Mask Song with Vlad and Niki

Cover|RENJUN - FOOLS (Troye Sivan)

Cover|RENJUN - FOOLS (Troye Sivan)

Maggie Rose - "Pull You Through" (Official Audio)

Maggie Rose - "Pull You Through" (Official Audio)

Some Dallas Officers Being Kept Away From Awards Banquet Due To Internal Affairs Investigations

Some Dallas Officers Being Kept Away From Awards Banquet Due To Internal Affairs Investigations

Cómo es el examen PER

Cómo es el examen PER

Vast 37# нашли аэропорт

Vast 37# нашли аэропорт

DAYZ HAS BECOME FRIENDLIER - The Jammed Gun Experiment vol 2

DAYZ HAS BECOME FRIENDLIER - The Jammed Gun Experiment vol 2

SAMSUNG A71|A51 How to take a SCREENSHOT|SCREEN RECORD

SAMSUNG A71|A51 How to take a SCREENSHOT|SCREEN RECORD

Petit Biscuit - Problems ft. Lido (Official Audio)

Petit Biscuit - Problems ft. Lido (Official Audio)

Best Mexico All Inclusive Resorts -  Riviera Maya

Best Mexico All Inclusive Resorts - Riviera Maya

Hire slowly, fire rapidly

Hire slowly, fire rapidly

Room on the Broom - Read by Alan Mandel

Room on the Broom - Read by Alan Mandel

8 Year Old Yuri's First Dance Competition! + Girls Dance Recital

8 Year Old Yuri's First Dance Competition! + Girls Dance Recital

5 Steps To Instantly Manifest A Specific Person | THIS REALLY WORKS!

5 Steps To Instantly Manifest A Specific Person | THIS REALLY WORKS!

5 TIPS FOR SPLENDOR

5 TIPS FOR SPLENDOR

Describe an area of science that interest you sample answer

Describe an area of science that interest you sample answer

VSP 60.60 firewood combined machine for large diameter logs processing

VSP 60.60 firewood combined machine for large diameter logs processing

How maggots are being used to save limbs

How maggots are being used to save limbs

Spicy Pork Ribs with Honey

Spicy Pork Ribs with Honey

Lauv ft. Julia Michaels - There's No Way [Official Video]

Lauv ft. Julia Michaels - There's No Way [Official Video]

Vera-Ellen performs in "Miss Turnstiles"

Vera-Ellen performs in "Miss Turnstiles"

Father of 2 pays off $20K in debt with the help of ‘Bad With Money’ podcast l GMA

Father of 2 pays off $20K in debt with the help of ‘Bad With Money’ podcast l GMA

The New Forbidden Hunter Technique... [Destiny 2 Beyond Light]

The New Forbidden Hunter Technique... [Destiny 2 Beyond Light]

How To Heal The Emotional Body - Teal Swan

How To Heal The Emotional Body - Teal Swan

Neuroanatomy - The Visual Pathway (Visual Mnemonic)

Neuroanatomy - The Visual Pathway (Visual Mnemonic)

Revive 030 With Retroid And Alter Form

Revive 030 With Retroid And Alter Form

What does it mean to prepare for an outbreak?

What does it mean to prepare for an outbreak?

British lord resigns from parliament for being late to debate

British lord resigns from parliament for being late to debate

GK | General knowledge Question And Answer | Daily Practice Set | Basic GK | Quiz Test-121

GK | General knowledge Question And Answer | Daily Practice Set | Basic GK | Quiz Test-121

THY ART IS MURDER - They Will Know Another (OFFICIAL LYRIC VIDEO)

THY ART IS MURDER - They Will Know Another (OFFICIAL LYRIC VIDEO)

It Came Upon A Midnight Clear - piano cover - pianotunes

It Came Upon A Midnight Clear - piano cover - pianotunes

Вечерний Ургант. Swanky Tunes & LP - «Day by day». 28.12.2018

Вечерний Ургант. Swanky Tunes & LP - «Day by day». 28.12.2018

Minecraft | Varied Commodities | Mod Showcase | 1.12.2

Minecraft | Varied Commodities | Mod Showcase | 1.12.2

Naruto: Kagami Uchiha An Often Forgotten Hero

Naruto: Kagami Uchiha An Often Forgotten Hero

END OF THE LINE for Modern Warfare...

END OF THE LINE for Modern Warfare...

How to Value Stocks QUICKLY

How to Value Stocks QUICKLY

Disregard - Infallible Refutation (Lyric Video)

Disregard - Infallible Refutation (Lyric Video)

My Immortal - Evanescence - Lindsey Stirling cover

My Immortal - Evanescence - Lindsey Stirling cover

"My Domain" (feat. Svrcina) // Produced by Tommee Profitt

"My Domain" (feat. Svrcina) // Produced by Tommee Profitt

[SOLVED] 'pip' is not recognized - with subtitle

[SOLVED] 'pip' is not recognized - with subtitle

Kid Cudi vs. Crookers - Day 'n' Night (Official Video)

Kid Cudi vs. Crookers - Day 'n' Night (Official Video)

Ваша реализация этой зимой!!! В любой сфере жизни!!!

Ваша реализация этой зимой!!! В любой сфере жизни!!!

TIP 42 Co-Occurring Disorders Part 1

TIP 42 Co-Occurring Disorders Part 1