JacquesLucke / blender_vscode

Visual Studio Code extension for Blender development.
MIT License
540 stars 70 forks source link

Running script produce an error #128

Open Almaghasilah opened 2 years ago

Almaghasilah commented 2 years ago

Hello,

I am trying to run a function from a library called Goo (https://github.com/smegason/Goo) in a Python script. Here is my code:

import bpy
from goo import goo 
from importlib import reload
reload(goo)

for collection in bpy.data.collections:  # loop through the existing collection
      for objs in collection.objects:
            bpy.data.objects.remove(objs)
      bpy.data.collections.remove(collection)

cA_collection = bpy.data.collections.new("A_Cells")
bpy.context.scene.collection.children.link(cA_collection)
cA1 = goo.Cell("cell_A1", loc=(2, 2, 0), flavor="ico_sphere")
goo.make_cell(cA1)
obj = bpy.context.active_object
bpy.ops.collection.objects_remove_all()
bpy.data.collections['A_Cells'].objects.link(obj)

Every time I run it, it would produce this following error

Traceback (most recent call last):
  File "/Users/ahmedalmaghasilah/.vscode/extensions/jacqueslucke.blender-development-0.0.17/pythonFiles/include/blender_vscode/utils.py", line 22, in always
    try: func()
  File "/Users/ahmedalmaghasilah/.vscode/extensions/jacqueslucke.blender-development-0.0.17/pythonFiles/include/blender_vscode/operators/script_runner.py", line 24, in run_script_action
    bpy.ops.dev.run_script(context, filepath=path)
  File "/Applications/Blender.app/Contents/Resources/3.2/scripts/modules/bpy/ops.py", line 113, in __call__
    ret = _op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Error: Python: Traceback (most recent call last):
  File "/Users/ahmedalmaghasilah/.vscode/extensions/jacqueslucke.blender-development-0.0.17/pythonFiles/include/blender_vscode/operators/script_runner.py", line 16, in execute
    runpy.run_path(self.filepath, init_globals={"CTX" : ctx})
  File "/Applications/Blender.app/Contents/Resources/3.2/python/lib/python3.10/runpy.py", line 269, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/Applications/Blender.app/Contents/Resources/3.2/python/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Applications/Blender.app/Contents/Resources/3.2/python/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/ahmedalmaghasilah/Desktop/Blender/Goo/scripts/modules/goo/sample_codes.py", line 30, in <module>
    goo.make_cell(cA1)
  File "/Users/ahmedalmaghasilah/Desktop/Blender/Goo/scripts/modules/goo/goo.py", line 568, in make_cell
    bpy.context.object.name = cell.data['name']
AttributeError: 'NoneType' object has no attribute 'name'
Location: /Applications/Blender.app/Contents/Resources/3.2/scripts/modules/bpy/ops.py:113`

However, when I run it on Blender's Scripting tab, it runs fine and never produce the error above.

I am wondering if anyone has the same issue before.

Griperis commented 1 year ago

Hi @Almaghasilah, this seems like issue of the goo library. You can see that in the output the function make_cell expected some cell.data to exist, but it is None.

  File "/Users/ahmedalmaghasilah/Desktop/Blender/Goo/scripts/modules/goo/goo.py", line 568, in make_cell
    bpy.context.object.name = cell.data['name']
AttributeError: 'NoneType' object has no attribute 'name'