2
$\begingroup$

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'}

enter image description here

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()
$\endgroup$
8
  • $\begingroup$ Possible thoughts in witch direction a solution could work, without the knowledge how to do it: 1. check if mesh was a curve type one step before (don’t know if that’s possible and reliable with the undo menue) $\endgroup$
    – A M
    Commented Aug 17, 2019 at 10:32
  • $\begingroup$ 2. store that the object has been converted with the execute function in the last step and therefore make an exception in the poll function to return true. (don’t know how to do that, because im not shure how the poll def with @classmethod works executionwise, because its “async-like” every tick, so im not shure how to give it a boolean variable for example) $\endgroup$
    – A M
    Commented Aug 17, 2019 at 10:33
  • $\begingroup$ 3. give the object itself some kind of variable – expl. custom property - of being converted that one could check with bpy.context.object etc. (but has to be deleted/changed after further steps) $\endgroup$
    – A M
    Commented Aug 17, 2019 at 10:33
  • 1
    $\begingroup$ Maybe the divide between a bpy.ops.curve... and a bpy.ops.mesh... operator is too "big". Consider making it two operators. $\endgroup$
    – batFINGER
    Commented Aug 17, 2019 at 11:24
  • $\begingroup$ Have you tried experimenting with bpy.ops.ed.undo_push ? It's says internal only but others have used successfully $\endgroup$
    – Moog
    Commented Aug 17, 2019 at 12:55

0

You must log in to answer this question.

Browse other questions tagged .