Тёмный

Avoid THIS when using lists in Blender Python 

Michael Bridges
Подписаться 3,4 тыс.
Просмотров 247
50% 1

Learn how to avoid a common mistake when using lists in Blender Python. Discover why iterating over a live list can cause unexpected issues and how to fix it easily.
🔗 LINKS:
My Asset Pack | michaelbridges...
Patreon | / michaelbridges
🍿 WATCH NEXT:
• Quick Tips
• Absolute Beginner Blen...
MY CURATED COURSES
The Blender Creative Suite | bit.ly/Blender...
Learn Blender Python | bit.ly/LearnBl...
MY DESK TOOLS & GEAR
📷 Panasonic G7 | amzn.to/4cdbBEV
🎙️ Shure MV7 | amzn.to/3zcikjL
🎛️ Audio Interface Revelator io24 | amzn.to/3ze4A85
🖥️ Dell AW3423DFW | amzn.to/4cptVKG
💻 THE PC:
Ryzen 5950X | amzn.to/3xCRil2
64GB 3600MT/s Crucial | amzn.to/45AfAsF
RTX 3090 | amzn.to/3VESMmQ
2TB Samsung Pro SSD | amzn.to/4cgxV0k
🖱️ Logitech G903 / G703 / Powerplay | amzn.to/3KYyVuc | amzn.to/45FkEMm | amzn.to/45FkEMm
⌨️ Logitech G915 Wireless (Tactile) | amzn.to/3VB1keC
🎧 Bose QC35 | amzn.to/4benxVv
🔊 Alesis M1 Active 520USB | amzn.to/3zchLq9
🎛️ Elgato Stream Deck | amzn.to/3xtw7ly
🖊️ Wacom Intuos | amzn.to/3xrUsIv
🖊️🖥️ XPPen Artist 15.6 | amzn.to/4eEtu0P
MY ON THE GO TOOLS & GEAR
💻 Macbook M1 Pro | amzn.to/3RBPGyX
🎤 Rode NT-1 USB | amzn.to/4cfBHqG
🖱️ Logitech Pebble | amzn.to/4caDRYT
MY OTHER SOCIALS:
🎙 My podcast - Dive into game development and gaming topics | / @canopygames
🌍 My website / Courses | bit.ly/CanopyG...
🐦 Twitter / X | x.com/TechEdMike
💬 Discord | canopy.games/p...
WHO AM I?
Hi there! 👋 I'm Mike, and I'm relatively new to RU-vid. I've been teaching Blender professionally for over 10 years, and I'm excited to share my knowledge with the community here. On this channel, you'll find full guides, courses, and tools to help guide, reassure, and educate you on your Blender journey. Let's create something amazing together!
PS: Some of the links in this description are affiliate links that I get a kickback from 😜
When I first encountered this issue in Blender, I thought I had found a bug. However, I quickly realized it was a simple mistake in my approach to working with lists in Python. I want to share this with you because it's something you might easily run into when using Python in Blender.
First, I demonstrate a piece of code where we add five monkeys to the scene and name them sequentially. The code seems straightforward at first glance, but I then introduce an alternative method that doesn't work as expected. Running this incorrect code results in unexpected naming patterns, and it took me a while to understand why.
The problem lies in how the list of objects is handled during iteration. Modifying the list while looping over it causes Blender to produce unpredictable results. This happens because the list changes dynamically, leading to multiple iterations and incorrect outputs.
To fix this, we need to create a copy of the list before iterating. By working with this copy, the original list remains unchanged, and the code functions as intended. After making this adjustment, the code runs correctly, and the objects are named as desired.
This experience was a valuable lesson in understanding list operations in Python within Blender. I hope this explanation helps you avoid the same pitfall. See you in the next video!

Опубликовано:

 

16 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 2   
@pedroreis6384
@pedroreis6384 7 месяцев назад
Hey there Michael! Just wanted to thank you, I've took your Blender course on Udemy a GOOD while back, finished it entirely, and loved it! I've even given several workshops, and it was all thanks to you and your amazing teaching, it was a wonderful course. Shame that version was lost to time, I really enjoyed my time. Just wanted to spread a bit of positivity, and a huge thank you once again, I'm sure that there are so many more people just like me, that really got to grips with Blender through your teaching. Hope you have a wonderful day!
@BitGamey
@BitGamey 7 месяцев назад
Good catch, Mike!
Далее
The 11 Ways To Move Around in Blender
10:03
I Made Sorting Algorithms Race Each Other
8:24
Просмотров 171 тыс.
Managing Blender Assets The Right Way
14:06
Просмотров 1,4 тыс.
10 Crazy Python Operators That I Rarely Use
11:37
Просмотров 37 тыс.
How To Use Bitwise Operators in Python
7:57
Someone improved my code by 40,832,277,770%
28:47
Просмотров 2,6 млн
The Secret Science of Perfect Spacing
9:40
Просмотров 442 тыс.
Geometry Nodes and UV Mapping in Blender
20:45
Просмотров 2,5 тыс.
Did you know THIS about MatCaps?
9:43
Просмотров 996
The 3 Laws of Writing Readable Code
5:28
Просмотров 630 тыс.