0
$\begingroup$

I'm trying to retrieve a class from the module called draw_op. The problem is in the module, some of classes can be imported normally while some don't.

Error:

<class 'draw_op.BlenderObject'>

<class 'draw_op.Drawer'>

Traceback (most recent call last):

File "/__init__.py", line 21, in

AttributeError: module 'draw_op' has no attribute 'DrawOperators'

__init__.py:

bl_info = {
    "name": "Draw a line",
    "author": "t",
    "blender": (3, 1, 0),
    "description": "test ",
    "location": "",
    "warning": "",
    
} # addon information, displayed on the preference panel. type = dictionary

import bpy, sys

#from operators.draw_op import BlenderObject
sys.path.append("/Users/jobpc/Desktop/Draw/operators")
import draw_op

BlenderObject = draw_op.BlenderObject
print(BlenderObject)
Drawer = draw_op.Drawer
print(Drawer)
DrawOperaotors = draw_op.DrawOperators # << This throws the error

draw_op.py:

import bpy, bgl, gpu

from gpu_extras.batch import batch_for_shader
from bpy.types import Operator

# ============ Following these classes are imported well ===============
class BlenderObject():
    prop1 = 10
    dict = {prop1: 5}
    @staticmethod
    def getNew():
        print("Hello")

class Drawer():
    def __init__(self):
        print('hello')   

# ============ From now, those classes cannot be imported ===============

class DrawOperators():
    def __init__(self):
        pass

class draw_operators():
    def __init__(self):
        pass

class OT_draw_operators(Operator):
    bl_idname = "object.draw_op"
    bl_label = "Draw Operator"
    bl_description = "Draw Line"
    bl_options = {'REGISTER'}
    
    def __init__(self):
        self.draw_handle = None
        self.draw_event = None
        self.widget = []
        
    def invoke(self, context):
        self.create_batch() 

Seriously, why this keep happening? Is this an error of Python itself? or just Blender?

Have been wasting almost 2 weeks, now I'm out of my patience. This makes me sick. I want to get out of this unending limbo hell asap.

Can somebody help?

$\endgroup$
6
  • $\begingroup$ It should work. Make sure the script that's located in "/Users/jobpc/Desktop/Draw/operators" is the same file that you made your edits to. And that you saved it. Saving it inside the Blender text editor doesn't save it on your disk. You need to use ALT + S or Text > Save to save to disk $\endgroup$
    – Gorgious
    May 24 at 7:12
  • $\begingroup$ @Gorgious I checked the location. The file is in /Users/jobpc/Desktop/Draw/operators and I saved the file manually but still nothing changed. $\endgroup$ May 24 at 7:17
  • $\begingroup$ You may need to restart blender to reload the script ? $\endgroup$
    – Gorgious
    May 24 at 7:18
  • $\begingroup$ @Gorgious Thank GOD I restarted the blender then it finally works. Thank you for answering. This one nearly killed me. $\endgroup$ May 24 at 7:31
  • $\begingroup$ Alternatively you can go to the blender logo (yes, it's a button) > System > Reload scripts i.stack.imgur.com/UQRG6.png $\endgroup$
    – Gorgious
    May 24 at 8:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.