bl_info = {
"name" : "test",
"author" : "Diego Quevedo",
"description" : "",
"blender" : (2, 80, 0),
"version" : (0, 1, 0),
"location" : "",
"warning" : "",
"category" : "Generic"
}
import bpy
from bpy.props import *
from bpy.types import (
AddonPreferences,
Operator,
Panel,
PropertyGroup
)
from bpy.app.handlers import persistent
@persistent
def returnCollections():
if len(bpy.context.scene.collection.children) <= 0:
bpy.data.collections.new("pUPA""TEST")
collections = [c.name for c in bpy.context.scene.collection.children]
items =[]
for c in collections:
items.append((c,c,c))
r= (items,collections[len(collections)-1])
return r
bpy.app.handlers.save_post.append(returnCollections)
class Test_OT_Test(bpy.types.Operator):
bl_idname = "view3d.test"
bl_label = "Test"
bl_category = "Test"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {'REGISTER', 'UNDO'}
CollectionName: EnumProperty(
default= returnCollections()[1],
items =returnCollections()[0],
name="Collections"
)
def Test(self, context, CollectionName):
print("test")
@classmethod
def poll(self, context):
return context
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
D = bpy.data
C = bpy.context
self.Test(C, self.CollectionName)
return {'FINISHED'}
####################
class Test_PT_Test(bpy.types.Panel):
bl_idname = "panel test"
bl_label = "Test"
bl_category = "Test"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("view3d.test", text="test", icon = "DOT")
def register():
bpy.types.VIEW3D_HT_header.prepend(returnCollections)
bpy.utils.register_class(Test_OT_Test)
bpy.utils.register_class(Test_PT_Test)
def unregister():
bpy.utils.unregister_class(Test_OT_Test)
bpy.utils.unregister_class(Test_PT_Test)
if __name__ == "__main__":
register()
bl_info = {
"name" : "test",
"author" : "Diego Quevedo",
"description" : "",
"blender" : (2, 80, 0),
"version" : (0, 1, 0),
"location" : "",
"warning" : "",
"category" : "Generic"
}
import bpy
from bpy.props import *
from bpy.types import (
AddonPreferences,
Operator,
Panel,
PropertyGroup
)
from bpy.app.handlers import persistent
@persistent
def returnCollections():
if len(bpy.context.scene.collection.children) <= 0:
bpy.data.collections.new("pUPA")
collections = [c.name for c in bpy.context.scene.collection.children]
items =[]
for c in collections:
items.append((c,c,c))
r= (items,collections[len(collections)-1])
return r
bpy.app.handlers.save_post.append(returnCollections)
class Test_OT_Test(bpy.types.Operator):
bl_idname = "view3d.test"
bl_label = "Test"
bl_category = "Test"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {'REGISTER', 'UNDO'}
CollectionName: EnumProperty(
default= returnCollections()[1],
items =returnCollections()[0],
name="Collections"
)
def Test(self, context, CollectionName):
print("test")
@classmethod
def poll(self, context):
return context
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
D = bpy.data
C = bpy.context
self.Test(C, self.CollectionName)
return {'FINISHED'}
####################
class Test_PT_Test(bpy.types.Panel):
bl_idname = "panel test"
bl_label = "Test"
bl_category = "Test"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("view3d.test", text="test", icon = "DOT")
def register():
bpy.types.VIEW3D_HT_header.prepend(returnCollections)
bpy.utils.register_class(Test_OT_Test)
bpy.utils.register_class(Test_PT_Test)
def unregister():
bpy.utils.unregister_class(Test_OT_Test)
bpy.utils.unregister_class(Test_PT_Test)
if __name__ == "__main__":
register()
bl_info = {
"name" : "test",
"author" : "Diego Quevedo",
"description" : "",
"blender" : (2, 80, 0),
"version" : (0, 1, 0),
"location" : "",
"warning" : "",
"category" : "Generic"
}
import bpy
from bpy.props import *
from bpy.types import (
AddonPreferences,
Operator,
Panel,
PropertyGroup
)
from bpy.app.handlers import persistent
@persistent
def returnCollections():
if len(bpy.context.scene.collection.children) <= 0:
bpy.data.collections.new("TEST")
collections = [c.name for c in bpy.context.scene.collection.children]
items =[]
for c in collections:
items.append((c,c,c))
r= (items,collections[len(collections)-1])
return r
bpy.app.handlers.save_post.append(returnCollections)
class Test_OT_Test(bpy.types.Operator):
bl_idname = "view3d.test"
bl_label = "Test"
bl_category = "Test"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {'REGISTER', 'UNDO'}
CollectionName: EnumProperty(
default= returnCollections()[1],
items =returnCollections()[0],
name="Collections"
)
def Test(self, context, CollectionName):
print("test")
@classmethod
def poll(self, context):
return context
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
D = bpy.data
C = bpy.context
self.Test(C, self.CollectionName)
return {'FINISHED'}
####################
class Test_PT_Test(bpy.types.Panel):
bl_idname = "panel test"
bl_label = "Test"
bl_category = "Test"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("view3d.test", text="test", icon = "DOT")
def register():
bpy.types.VIEW3D_HT_header.prepend(returnCollections)
bpy.utils.register_class(Test_OT_Test)
bpy.utils.register_class(Test_PT_Test)
def unregister():
bpy.utils.unregister_class(Test_OT_Test)
bpy.utils.unregister_class(Test_PT_Test)
if __name__ == "__main__":
register()
'_RestrictData' or '_RestrictContext' in addon 2.8
actually I want to show a EnumProperty with all the current collections.
all works fine if I run the addon from text editor
but if I try to install it I have '_RestrictData' or '_RestrictContext' atributeErrors.
I test some solutions like "persistent" AttributeError: '_RestrictData' object has no attribute 'filepath'
or "prepend"
AttributeError: '_RestrictContext' object has no attribute 'space_data'
and others, but nothing works
What could I do to achieve my goal?
bl_info = {
"name" : "test",
"author" : "Diego Quevedo",
"description" : "",
"blender" : (2, 80, 0),
"version" : (0, 1, 0),
"location" : "",
"warning" : "",
"category" : "Generic"
}
import bpy
from bpy.props import *
from bpy.types import (
AddonPreferences,
Operator,
Panel,
PropertyGroup
)
from bpy.app.handlers import persistent
@persistent
def returnCollections():
if len(bpy.context.scene.collection.children) <= 0:
bpy.data.collections.new("pUPA")
collections = [c.name for c in bpy.context.scene.collection.children]
items =[]
for c in collections:
items.append((c,c,c))
r= (items,collections[len(collections)-1])
return r
bpy.app.handlers.save_post.append(returnCollections)
class Test_OT_Test(bpy.types.Operator):
bl_idname = "view3d.test"
bl_label = "Test"
bl_category = "Test"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {'REGISTER', 'UNDO'}
CollectionName: EnumProperty(
default= returnCollections()[1],
items =returnCollections()[0],
name="Collections"
)
def Test(self, context, CollectionName):
print("test")
@classmethod
def poll(self, context):
return context
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
D = bpy.data
C = bpy.context
self.Test(C, self.CollectionName)
return {'FINISHED'}
####################
class Test_PT_Test(bpy.types.Panel):
bl_idname = "panel test"
bl_label = "Test"
bl_category = "Test"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator("view3d.test", text="test", icon = "DOT")
def register():
bpy.types.VIEW3D_HT_header.prepend(returnCollections)
bpy.utils.register_class(Test_OT_Test)
bpy.utils.register_class(Test_PT_Test)
def unregister():
bpy.utils.unregister_class(Test_OT_Test)
bpy.utils.unregister_class(Test_PT_Test)
if __name__ == "__main__":
register()
lang-py