Create Simple Blender Addon in 15 Minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
have you ever wondered how to simplify tasks in blender so they become a single click solutions in this video I will show you how to create a simple blender add in just under 15 minutes you have no Python or coding skills well neither do I and guess what you don't actually need them all you need is a cup of coffee blender console and a few tips on how to copy and paste the lines of code sounds easy then let's get started hi everyone my name is lek and before we begin I just want to say I'm not a coder my code probably sucks but it gets the job done for me recently I was working on a project where I had to add very simple illumination set up to multiple 3d files adjust the materials and then remove the setup to keep the files clean doing it all by hand was a nightmare that's why I tried creating an add-in to automate the process and guess what it worked in this video I want to show you step-by-step how I did it but if you have any other interesting content on that topic feel free living it in the comment section now without the further ado let's just jump into it once we launch blender the easiest way to start is simply going to the scripting tab here and hitting new here so we can start working on a script now here we have a console window and basically everything we do in blender is actually launching a command here I can select this command right click and copy it to my script window here as you can see we also have a run script button and when I press it well we get an error and to check out what's actually cooking with blender it's good to use the console window here we can see error name saying something about BPI well in practice when you look here we have some Python modules that are available in blender and execute any command we have to tell blender to import those modules essentially you have to just add import BPI line here and any command you enter to the script window will be then executed since I wanted to create some sample environment in my scene I will now add the point lamp and again I can copy the command to my script window I will delete the cube command and paste the add lamp command a few more times so as you can see we can also change some of the very basic settings taken from the command here I will just change the locations of the lamps added to my scene now I will also like some of the basic scene settings to be applied when I run the script so I want to enable screen space reflections and you can see I have direct command I also want to enable the refraction again I can see the command here and I would also like to set the surface or the world strength to zero so if I do that just by left clicking and sliding the value down I also have the command so I can now simply copy this script and when I restart blender go to the scripting window here and paste the script if I just click this button here you can see everything is applied so the read and render settings are also changing just within this one click it would be great if we could now run this entire code using just a single command from the console to do that we have to create an operator and we are going to use one of the Python templates from here let's select operator simple and as you can see it doesn't look simple at all but don't worry what I usually do is simply deleting this line of code here because we are not gonna need it and here under the DEF main context is where we can paste our commands so I'm gonna select them I'm gonna skip the import BPI gonna copy and just paste them here now what's really important in Python is the layout of our code so we have to add indentations to all those lines and what you also want to know is that with the hashes we can disable parts of the code so if I do it here you can see it becomes gray and this way we can also add some descriptions to the script so you know what's happening within it if I now execute the script will have a new command registered under this name here the default name from the operator simple template so let's do it so as you can see I'm now pasting this line of code here as a command and when I hit enter we can see all of the new objects added to the scene as well as the render settings changing to create a button that will execute our newly created command I'm gonna use another Python template and it's gonna be UI panel so you can see we get another big portion of code let's run the script and as you can see we now have to look for our button but here under the BL context we can see the scene so everything is added under the scene properties you can see we have our layout demo tool same name as here and a lot of buttons visible so we are just gonna leave the big button with the render sign on it you can see with the hash it's located here I'm gonna delete everything else and just hit run script again so you can see we right now have just this one button changing the row scale we can modify the size of the button the description is defined by the operator so if we go to our operators simple this is the name that will be defining what you can see on the button let's now copy this part of the code and let's paste it to our panel template what you have to do right now is linking our command with big button so let's just select and copy it and here let's paste it within the render line of code and that already works however let's just clean up our code a little bit more so let's remove those lines here since we also have them copied down below and let's move the register operations down here and stack them together gonna delete those lines of code now it looks much cleaner and if we run the script you can see the button name changed to what we have defined here meaning our command is now running if I click the button you can see everything is executed as we want it together with the render settings to save our script as an add-on we going to use another template which is called add an add object here it looks way more complex that we need we just have to copy this lines of code from here and paste them above the import VPI line somewhere like this you can define all all of your add in descriptions here I'm gonna leave it as defaults and if I go to text save as I can now save my add in here and run it within blender to install your ad and go to the Edit preferences add-ins install and find your little atom now enable it here and it just works okay well we've created so far is very quick and dirty but now let's add another button to our add-on and make it a bit cleaner let's now add another button to our script that will remove the light sources without touching the chair so I'm going back to the scripting window and I'm gonna start as if I was creating a new script we can use the console window to either search for a command or to modify the existing one so I want to look for a command that will select the light sources only you can see we have some of the commands already listed here and I'm gonna use the autocomplete option to find the command so I'm going to type VP IOPS and so on and I'm gonna press the control spacebar button to fill the rest of the command I'm going to type select and you can see we can choose by type select option so I'm gonna use it and within the type we can see there is the mesh ending so let's try using the lamp input light sorry so you can see if I execute this kind of command all of the light sources are selected for me let me copy this command to my script and let's run it if I delete the light sources here I can copy another command and paste it here and this way we already have working script that removes all of the light sources from the scene we now have to create another operator that will link these two commands to a new button in our Adhan so let's copy them let's open our Eden and let's paste the new comments before the actual panel code here now this is the point where we can't use the default names any longer in order to the second button to work so we'll have to rename a few things here within the DEF main let's change this name to button zero one and let's use the same name here within the dev function again now also we have to change the name of the class let's call it add environment and let's copy the same name to the register and unregister function here or a class sorry for being an amateur encoding let's now also change the con man name to something more meaningful say chuckle for and environment and let's change the label to simply and add environment let's now copy the new name of the command to the button and paste it here let's mute those lines of codes using the hashes and let's now run the script so you can see the label changed meaning it all works let's now move to adding another button I'm going to start with creating a new operator so let's select this one let's paste it here just remember to keep the correct format of your code let's cut those two lines of code and replace the existing ones removing the hashes and adding the indentations let's now change the names button 0 to we also have to change the class name and register the new classes here so let's copy those lines of code paste them and let's copy the new class name and paste it here we are almost set what we have to do right now is changing the command name so let's add remove here and let's change the description to remove as well we now need to copy the button code paste it again and let's replace this command with the newly created one if I now execute the script you will see another button appearing and by clicking it I'm able to remove all of the light sources to make the final version of the Adhan more user-friendly I've edited the information we have here added some hash descriptions I've also included one line of code that changes the scene settings to the default one value here and within the toolbar itself I've changed the height of the buttons remove the big button descriptions and also change the names of the tool itself so you can see it displayed here if you want the add-on to be available under the different set of tools here if I click on it you can see we have the name changed in the console so if I change the context input to render for example the tool is now available here under the scene render settings so I really hope this video was interesting and you learned something new today feel free letting me know what you think in the comment section and remember you can download the script I've just created in the chaco first or together with this cool red it's all for free that's it for me today thanks everyone for watching and see you in another video bye bye
Info
Channel: chocofur
Views: 40,917
Rating: undefined out of 5
Keywords: blender 2.8, blender 2.8 python tutorial, blender 2.8 tutorial, blender 2.8 python scripting, blender 2.8 python scripting tutorial, blender, blender tutorial, tutorial, blender 3d, 3d, how to, 2.8, blender 2.8 python, blender scripting, blender python tutorial, blender 2.8 scripting, b3d, eevee, blender python, python
Id: Y67eCfiqJQU
Channel Id: undefined
Length: 15min 25sec (925 seconds)
Published: Tue Jan 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.