1
$\begingroup$

After learned about new changes in blender API, I had to update script from 2.8 into 3.0 using : instead of =.

So following the changes in this script to 3.0...


class ALP_OT_Params(Operator):
 
   # Old 
   #text= bpy.props.StringProperty(name= "Enter Object Name", default= "")

   # Update
   text: bpy.props.StringProperty(name= "Enter Object Name", default= "")
   
   def excute(self,context):

     new_obj_name = self.text
     obj = bpy.context.object
     obj.name = new_obj_name

I am getting type error at this string obj.name = new_obj_name.

From blender console, The error stating...

TypeError: bpy_struct: item.attr = val: Object.name expected a bytes type, not str

I am not exactly sure what error was, but I am assuming it have something to do with changes in this string text:. I didn't have problem or getting any error on text= before Before Blender made API changes. What am I missing?

Couldn't find any information around that might help me to resolve my issues any suggestions?

UPDATE: Full script requested by @Gorgious & @Marty Fouts

import bpy
from bpy.types import Operator
from bpy.props import StringProperty

class ALP_OT_Params(Operator):
    """Opens Add Cube with New name Dialog Box"""
    bl_idname = "alp.ot_params"
    bl_label = "Add Cube Popup Dialog"

    text: StringProperty(name="Enter Text", default="")

    @classmethod
    def poll(cls, context):
        return True

    def execute(self, context):

        new_obj_name = self.text

        bpy.ops.mesh.primitive_cube_add()
        obj = bpy.context.object
        obj.name = new_obj_name

        return {"FINISHED"}

    def invoke(self, context, event):

        return context.window_manager.invoke_props_dialog(self)


 def register():
     bpy.utils.register_class(ALP_OT_Params)


 def unregister():
     bpy.utils.unregister_class(ALP_OT_Params)


 if __name__ == "__main__":
     register()
     bpy.ops.alp.ot_params('INVOKE_DEFAULT')


ERROR

enter image description here

UPDATE: File from Blender 3.1.0

$\endgroup$
7
  • $\begingroup$ Hello, just to be sure, is excute a typo ? It should be execute $\endgroup$
    – Gorgious
    Commented Mar 31, 2022 at 20:49
  • $\begingroup$ Please cut and paste the actual script as well as the entire error message. In addition to the type @Gorgious pointed out, I'm curious where the error occurred. $\endgroup$ Commented Mar 31, 2022 at 21:21
  • $\begingroup$ @Gorgious, Yes it was comment typo, not on my script. $\endgroup$
    – sirrus
    Commented Mar 31, 2022 at 21:34
  • $\begingroup$ @MartyFouts, See update with full script. $\endgroup$
    – sirrus
    Commented Mar 31, 2022 at 21:35
  • $\begingroup$ and the full text of the error with the complete traceback? $\endgroup$ Commented Mar 31, 2022 at 21:36

1 Answer 1

2
$\begingroup$

So the code in your example has never been run, because if it had, it would have given an error message about the bl_idname. When I modify the bl_idname, it still won't run because there's no scale property. When I disable the reference to self.scale, it runs fine. Here's working code:

import bpy
from bpy.types import Operator
from bpy.props import StringProperty

class ALP_OT_Params(Operator):
    """Opens Add Cube with New name Dialog Box"""
    bl_idname = "alp.params"
    bl_label = "Add Cube Popup Dialog"
    text: StringProperty(name="Enter Text", default="")

    @classmethod
    def poll(cls, context):
        return True

    def execute(self, context):
        new_obj_name = self.text
        #scale_nbr = self.scale
        bpy.ops.mesh.primitive_cube_add()
        obj = bpy.context.object
        obj.name = new_obj_name
        return {"FINISHED"}

    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self)


def register():
    bpy.utils.register_class(ALP_OT_Params)


def unregister():
    bpy.utils.unregister_class(ALP_OT_Params)


if __name__ == "__main__":
    register()
    bpy.ops.alp.params('INVOKE_DEFAULT')
$\endgroup$
8
  • $\begingroup$ After copied and pasted from your to blender editor, run and excute operator. I am still getting same error. "TypeError: bpy_struct: item.attr = val: Object.name expected a bytes type, not str" $\endgroup$
    – sirrus
    Commented Mar 31, 2022 at 21:55
  • $\begingroup$ Open a fresh copy of blender. Go to the scripting workspace. Click "New" in the editor. Paste the code exactly. Hit the play button. When I do that in 2.93.6, 3.0.1, or 3.1.0, the dialog pops up. When I enter the name I get a cube with that name in the 3D Viewport. What happens when you do it? $\endgroup$ Commented Mar 31, 2022 at 22:22
  • $\begingroup$ After following exactly to your instruction (Copy and pasted exactly script). The Error occur on 3.1.0 and 3.0.1 but not on my 2.93.5 $\endgroup$
    – sirrus
    Commented Mar 31, 2022 at 22:34
  • 1
    $\begingroup$ and it works fine. You have a problem with your installation. What addons do you have enabled? $\endgroup$ Commented Mar 31, 2022 at 23:23
  • 1
    $\begingroup$ Addon was the problem! It was my own old experimential addon that I forgot to disenage for while. After I disengage it, the script run fine. Thank you for your time truly appreciated. $\endgroup$
    – sirrus
    Commented Apr 1, 2022 at 0:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .