Can't move objects from one collection into another with Python

I’m watching the video scripting for artist #6 for blender https://youtu.be/opZy2OJp8co?t=845

and at 14 minutes and eight seconds into the video he runs code that moves 4 objects from one collection into another my script is the same as his as you could see in this picture


but mine doesn’t work I get a

Traceback (most recent call last):
File “E:\BLENDER ASSETS\SCRIPTS\Scripting for ARTISTS\Blender Collections\1.blend\move_stuff.py”, line 15, in
RuntimeError: Error: Object ‘Suzanne.003’ not in collection ‘SfA’

Error: Python script failed, check the message in the system console

here is my blender file https://drive.google.com/file/d/1t4USzKSFcHJundOFWcqFYHEghHq9ZvQU/view?usp=sharing any help is appreciated

These two offending lines simply need to be unindented:

for ob in to_unlink:
    coll_from.objects.unlink(ob)

I think the lines 12 and 14 can be safely removed and the line 15 unindented once, I don’t see the point in storing the objects into a to_unlink list when it’s the exact same objects that are being iterated over. (I guess it does have a meaning in the context of this tutorial but still)

Also please post your code as a text, not image, it’s easier for others to help you :slight_smile:

He already provided a blend file with his code initially. :slightly_smiling_face:

Yeah although we all know how safe it is to download random files from strangers on the internet ^^

I would beg to differ. There really isn’t any way to embed a virus in a blend file that I’m aware of, although if you’re worried about scripts running in the background you can disable this User Preferences setting to disallow the auto running of Python scripts on startup.

Side note, you can also see the blend file extension in the Google Drive link, meaning it’s probably not maliciously hidden content.

I agree with you and I thank you for bringing it up, although I’m not sure every regular user knows about this setting. I think this protection has other flaws (mainly located between the monitor and the chair, as usual) that can be exploited. I’ve seen it and experienced it myself. Also, a file extension can be modified very easily.

Anyways my main point is that I don’t think it is mandatory to download a file, open it, open up the right editor, etc, when the problem can be exposed by just copy / pasting 15 lines of code :slight_smile:
Sorry for distracting the flow of the thread, I’ll see myself out.

Cheers

1 Like

As someone who has answered hundreds of python questions I can say that there is a 0% chance I’m going to close out whatever I was working on, download a random .blend file, and then proceed to debug somebody’s script from within the editor window. I’m sure there are plenty of benevolent people out there willing to go through that extra effort, but I would bet they are a very small minority.

posting code directly in a forum post, a github link, or even pastebin is definitely the way to go.

1 Like

As someone who passes quite a bit of code back and forth at work every day, if someone doesn’t know how to effectively share code, I’m just going to assume they have no idea what they’re doing and so I couldn’t help them anyway. I don’t mean to rag on OP, this is an unfounded and probably unfair assumption, it’s just my instinct when I see someone sharing code in an inefficient way to say “yeah, everything I say here is just going to confuse them”.

That aside, this issue has been solved, and this discussion and my reply to it is a bit off topic, so let’s end this here and if anyone wants to have a discussion about good ways to share code, feel free to make a thread in #general-forums:off-topic-chat