Can't Make a Textfield

I’m trying to get my head around getting string input from a text field processed by a script but it’s not working. Here’s the error I’m getting.

TypeError: Base BPy_StructRNA() takes exactly 1 argument (0 given)

I have a few other questions too.

  1. All textfields, combo boxes, and so forth are “Properties” of some form or another right?
  2. Do they have to be declared in the operator to work?
  3. Are classes like StringProperty, IntProperty, and so on supposed to be replacements for the old widget creation functions from the now obsolete Draw module?
  4. Are there any places that explain it?

class OBJECT_OT_destroycity( bpy.types.Operator ):
    bl_idname = "destroy_city_id"

    nameOfCity = bpy.types.StringProperty( name="City To Destroy", description="", max_length=50, type='STRING' )

    def invoke( self, context, evt ):
        print( "kaboom" )
        return( 'FINISHED', )

You realize, that the interface is written in python. So you can visit the source code here…


Here is a snippet from the

class OBJECT_PT_context_object(ObjectButtonsPanel):
    bl_label = ""
    bl_show_header = False

    def draw(self, context):
        layout = self.layout

        ob = context.object

        row = layout.row()
        row.label(text="", icon='OBJECT_DATA')
        row.prop(ob, "name", text="")

I think this handles where you type in the name for an object. Just dig around and see how the interface is created.

What you showed me was some good examples of properties in the sense of gui layout in a properties panel for stuff that already exists. But I’m guessing that this is a little different from properties in the sense of something that doesn’t yet exist. ( VarkenVarken’s gear script comes to mind ). But then again, if you’re creating something new, the gui for creating that new thing doesn’t really belong in the properties panel does it? :confused:

It seems to be coming together as I sort through these example scripts though I admit I still don’t completely “get it” yet.

Okay, it looks like I got a better head around the relationship between properties and gui widgets. String properties could be stored in the current scene context with said scene object being used to setup my text fields.

The Twitter example I found was good for the property setting part and the ui folder in blender was good for setting up widgets to access said properties. In the end, I ended up with something like this and it worked for me.

# set at the top of the script
StringProp = bpy.context.scene.StringProperty
StringProp( attr="cityName", name="city name", description="Name of the victim city", default="Detroit" )
# done in the panel class draw method
scene = context.scene
layout = self.layout
col = layout.column()
col.prop( scene, "cityName", text="City to destroy:" )

And to all the scripters who put out those examples for me to learn from…
Thank you.