1
$\begingroup$

I know I can use StringProperty() to get a string from UI Layout, what if it is a List containing strings? Is this possible?

The UI layout:

class PanelAdd(CreatePanel, bpy.types.Panel):
    bl_idname = "VIEW3D_PT_create"
    bl_label = "Add Reference Mesh"

    def draw(self, context):
        layout = self.layout
        props = box.operator("myops.addthings", text="Add Items", icon="ZOOMIN")
        props.addObject=["item1", "item2"]

The Operator:

class OBJECT_add(bpy.types.Operator):
    # I know it is wrong to use StringProperty(), but what can i use to get the list so I can use in the operator?
   addObject = bpy.props.StringProperty()
   bl_idname = "myops.addthings"
   bl_label = "Add Mesh"
   bl_options = {'REGISTER', 'UNDO'}
   bl_description ="Add Parts"
$\endgroup$
  • $\begingroup$ If your list happens to be a scene id property, you could pass the property name as a string to the operator. Otherwise can convert list to string and back (tokenized) or use a CollectionProperty $\endgroup$ – batFINGER May 20 '18 at 18:03

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.