My AddOn converts the selected curve to a mesh. With the poll def() I want to grey out the AddOn-button for other object types then curves. the problem is that the undo-menue that should apear in the bottom left after execution with all the props vanishes/doesnt show up because of this, because the object type isnt curve anymore, i think.
excerpt poll:
@classmethod
def poll(cls, context):
return context.object.select_get() and context.object.type == 'CURVE'
excerpt undo-menue-activation:
bl_options = {'REGISTER', 'UNDO'}
For better comprehension of the problem here the full script: (its used for a very specific svg to mesh for 3d-printing workflow. It works only on imported and selected svg-object)
bl_info = {
"name": "SVG_Center&Extrude",
"author": "AM",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "View3D > Object",
"description": "specific workflow for svg to extruded printable form",
"warning": "",
"wiki_url": "",
"category": "Object",
}
import bpy
from bpy.types import(
AddonPreferences,
Operator,
Panel,
PropertyGroup,
)
from bpy.props import(FloatVectorProperty)
from bpy.props import(FloatProperty)
class OBJECT_OT_SVG_CnE(Operator):
bl_label = "[SVG] CnE"
bl_idname = "object.svg_cne"
bl_description = "specific workflow for svg to extruded printable form"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = {'REGISTER', 'UNDO'}
height = bpy.props.FloatProperty(
name = "Extrude Height",
default = 1,
description = "height",
)
scale: bpy.props.FloatProperty(
name = "XY Scale",
default = 100.0,
description = "Scale",
)
resolution = bpy.props.FloatProperty(
name = "Preview Resolution",
default = 12,
description = "Preview Resolution",
)
#@classmethod
#def poll(cls, context):
# return context.object.select_get() and context.object.type in ['CURVE']
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
# prerequisites:
# 1: import SVG-File
# 2: select imported object!
# 3: run this script
#check if curve
if context.object.type != 'CURVE':
return {'CANCELLED'}
extrudeHeight = 0.0, 0.0, self.height
scale = self.scale, self.scale, self.scale
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')
bpy.context.object.location[1] = 0
bpy.context.object.location[2] = 0
bpy.context.object.location[0] = 0
bpy.ops.transform.resize(value=scale, orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
bpy.context.object.data.fill_mode = 'NONE'
bpy.context.object.data.resolution_u = self.resolution
bpy.ops.object.convert(target='MESH')
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.edge_face_add()
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude_region={"use_normal_flip":False, "mirror":False}, TRANSFORM_OT_translate={"value":extrudeHeight, "orient_type":'NORMAL', "orient_matrix":((-0.163277, -0.98658, 0), (0.98658, -0.163277, 0), (0, 0, 1)), "orient_matrix_type":'NORMAL', "constraint_axis":(False, False, True), "mirror":False, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
bpy.ops.object.editmode_toggle()
bpy.context.object.active_material.diffuse_color = (1, 1, 1, 1)
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator(OBJECT_OT_SVG_CnE.bl_idname)
def register():
bpy.utils.register_class(OBJECT_OT_SVG_CnE)
bpy.types.VIEW3D_MT_object.append(menu_func)
def unregister():
bpy.utils.unregister_class(OBJECT_OT_SVG_CnE)
bpy.types.VIEW3D_MT_object.remove(menu_func)
if __name__ == "__main__":
register()
bpy.ops.curve...
and abpy.ops.mesh...
operator is too "big". Consider making it two operators. $\endgroup$