Avoid THIS when using lists in Blender Python

Поделиться
HTML-код
  • Опубликовано: 5 фев 2025
  • 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 RUclips. 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!

Комментарии • 4