Skip to content
Snippets Groups Projects
add_dimension.py 128 KiB
Newer Older
  • Learn to ignore specific revisions
  •                           self.Dimension_arrowdepth,
                              self.Dimension_arrowlength)
    
        if Type == 'Angular2':
            if self.Dimension_angle == 0:
                return {'FINISHED'}
            verts = Angular2(self.Dimension_width,
                              self.Dimension_depth,
                              self.Dimension_angle,
                              self.Dimension_resolution,
                              self.Dimension_arrow,
                              self.Dimension_arrowdepth,
                              self.Dimension_arrowlength)
    
        if Type == 'Angular3':
            if self.Dimension_angle == 0:
                return {'FINISHED'}
            verts = Angular3(self.Dimension_width,
                              self.Dimension_length,
                              self.Dimension_dsize,
                              self.Dimension_depth,
                              self.Dimension_angle,
                              self.Dimension_resolution,
                              self.Dimension_depth_from_center,
                              self.Dimension_arrow,
                              self.Dimension_arrowdepth,
                              self.Dimension_arrowlength)
    
        if Type == 'Note':
            verts = Note(self.Dimension_width,
                              self.Dimension_length,
                              self.Dimension_depth,
                              self.Dimension_angle,
                              self.Dimension_arrow,
                              self.Dimension_arrowdepth,
                              self.Dimension_arrowlength)
    
        vertArray = []
        # turn verts into array
        for v in verts:
            vertArray  += v
    
        # create object
        createCurve(vertArray, self, align_matrix)
    
        return
    
    #### Delete dimension group
    def DimensionDelete(self, context):
    
    
        bpy.context.view_layer.update()
    
        bpy.ops.object.mode_set(mode = 'OBJECT')
    
    
        bpy.ops.object.select_grouped(extend=True, type='CHILDREN_RECURSIVE')
        bpy.ops.object.delete()
    
        bpy.context.view_layer.update()
    
    
        return
    
    class Dimension(bpy.types.Operator):
        ''''''
        bl_idname = "curve.dimension"
        bl_label = "Dimension"
    
        bl_options = {'REGISTER', 'UNDO', 'PRESET'}
    
        bl_description = "add dimension"
    
        #settings : bpy.props.PointerProperty(type=DimensionVariables)
    
    
        # align_matrix for the invoke
    
        align_matrix : Matrix()
    
        Dimension : BoolProperty(name = "Dimension",
    
                    default = True,
                    description = "dimension")
    
        #### change properties
    
        Dimension_Name : StringProperty(name = "Name",
    
        Dimension_Change : BoolProperty(name = "Change",
    
                    default = False,
                    description = "change dimension")
    
    
        Dimension_Delete : StringProperty(name = "Delete",
    
                        description = "Delete dimension")
    
        #### general properties
        Types = [('Linear-1', 'Linear-1', 'Linear-1'),
                 ('Linear-2', 'Linear-2', 'Linear-2'),
                 ('Linear-3', 'Linear-3', 'Linear-3'),
                 ('Radius', 'Radius', 'Radius'),
                 ('Diameter', 'Diameter', 'Diameter'),
                 ('Angular1', 'Angular1', 'Angular1'),
                 ('Angular2', 'Angular2', 'Angular2'),
                 ('Angular3', 'Angular3', 'Angular3'),
                 ('Note', 'Note', 'Note')]
    
        Dimension_Type : EnumProperty(name = "Type",
    
                    description = "Form of Curve to create",
                    items = Types)
    
        ATypes = [('A', 'A', 'A'),
                  ('B', 'B', 'B'),
                  ('C', 'C', 'C')]
        Angle_Type : EnumProperty(name = "Angle",
                    description = "Select corne ABC",
                    items = ATypes)
    
        XYZTypes = [
                    ('TOP', 'Top', 'TOP'),
                    ('FRONT', 'Front', 'FRONT'),
                    ('RIGHT', 'Right', 'RIGHT'),
                    ('BOTTOM', 'Bottom', 'BOTTOM'),
                    ('BACK', 'Back', 'BACK'),
                    ('LEFT', 'Left', 'LEFT')]
    
        Dimension_XYZType : EnumProperty(name = "Coordinate system",
    
                    description = "Place in a coordinate system",
                    items = XYZTypes)
        XYTypes = [
                    ('X', 'X', 'X'),
                    ('Y', 'Y', 'Y')]
    
        Dimension_XYType : EnumProperty(name = "XY",
    
                    description = "XY",
                    items = XYTypes)
        XZTypes = [
                    ('X', 'X', 'X'),
                    ('Z', 'Z', 'Z')]
    
        Dimension_XZType : EnumProperty(name = "XZ",
    
                    description = "XZ",
                    items = XZTypes)
        YZTypes = [
                    ('Y', 'Y', 'Y'),
                    ('Z', 'Z', 'Z')]
    
        Dimension_YZType : EnumProperty(name = "YZ",
    
                    description = "YZ",
                    items = YZTypes)
    
        Dimension_startlocation : FloatVectorProperty(name = "",
    
                    description = "Start location",
                    default = (0.0, 0.0, 0.0),
                    subtype = 'XYZ')
    
        Dimension_endlocation : FloatVectorProperty(name = "",
    
                    description = "End location",
                    default = (2.0, 2.0, 2.0),
                    subtype = 'XYZ')
    
        Dimension_endanglelocation : FloatVectorProperty(name = "",
    
                    description = "End angle location",
                    default = (4.0, 4.0, 4.0),
                    subtype = 'XYZ')
        width_or_location_items = [
                    ('width', 'width', 'width'),
                    ('location', 'location', 'location')]
    
        Dimension_width_or_location : EnumProperty(name = "width or location",
    
                    items = width_or_location_items,
                    description = "width or location")
        libertyItems = [
                    ('2D', '2D', '2D'),
                    ('3D', '3D', '3D')]
    
        Dimension_liberty : EnumProperty(name = "2D / 3D",
    
                    items = libertyItems,
                    description = "2D or 3D Dimension")
    
        ### Arrow
        Arrows = [
                    ('Arrow1', 'Arrow1', 'Arrow1'),
                    ('Arrow2', 'Arrow2', 'Arrow2'),
                    ('Serifs1', 'Serifs1', 'Serifs1'),
                    ('Serifs2', 'Serifs2', 'Serifs2'),
                    ('Without', 'Without', 'Without')]
    
        Dimension_arrow : EnumProperty(name = "Arrow",
    
                    items = Arrows,
                    description = "Arrow")
    
        Dimension_arrowdepth : FloatProperty(name = "Depth",
    
                    default = 0.1,
                    min = 0, soft_min = 0,
                    description = "Arrow depth")
    
        Dimension_arrowlength : FloatProperty(name = "Length",
    
                    default = 0.25,
                    min = 0, soft_min = 0,
                    description = "Arrow length")
    
    
        #### Dimension properties
    
        Dimension_resolution : IntProperty(name = "Resolution",
    
                    default = 10,
                    min = 1, soft_min = 1,
                    description = "Resolution")
    
        Dimension_width : FloatProperty(name = "Width",
    
                    default = 2,
                    unit = 'LENGTH',
                    description = "Width")
    
        Dimension_length : FloatProperty(name = "Length",
    
                    default = 2,
                    description = "Length")
    
        Dimension_dsize : FloatProperty(name = "Size",
    
                    default = 1,
                    min = 0, soft_min = 0,
                    description = "Size")
    
        Dimension_depth : FloatProperty(name = "Depth",
    
                    default = 0.1,
                    min = 0, soft_min = 0,
                    description = "Depth")
    
        Dimension_depth_from_center : BoolProperty(name = "Depth from center",
    
                    default = False,
                    description = "Depth from center")
    
        Dimension_angle : FloatProperty(name = "Angle",
    
                    default = 45,
                    description = "Angle")
    
        Dimension_rotation : FloatProperty(name = "Rotation",
    
                    default = 0,
                    description = "Rotation")
    
        Dimension_offset : FloatProperty(name = "Offset",
    
    
        #### Dimension units properties
        Units = [
                    ('None', 'None', 'None'),
                    ('\u00b5m', '\u00b5m', '\u00b5m'),
                    ('mm', 'mm', 'mm'),
                    ('cm', 'cm', 'cm'),
                    ('m', 'm', 'm'),
                    ('km', 'km', 'km'),
                    ('thou', 'thou', 'thou'),
                    ('"', '"', '"'),
                    ('\'', '\'', '\''),
                    ('yd', 'yd', 'yd'),
                    ('mi', 'mi', 'mi')]
    
        Dimension_units : EnumProperty(name = "Units",
    
                    items = Units,
                    description = "Units")
    
        Dimension_add_units_name : BoolProperty(name = "Add units name",
    
                    default = False,
                    description = "Add units name")
    
    
        #### Dimension text properties
    
        Dimension_textsize : FloatProperty(name = "Size",
    
                    default = 1,
                    description = "Size")
    
        Dimension_textdepth : FloatProperty(name = "Depth",
    
                    default = 0.2,
                    description = "Depth")
    
        Dimension_textround : IntProperty(name = "Rounding",
    
                    default = 2,
                    min = 0, soft_min = 0,
                    description = "Rounding")
    
        Dimension_font : StringProperty(name = "Font",
    
                    default = '',
                    subtype = 'FILE_PATH',
                    description = "Font")
    
    
        #### Materials properties
    
        Dimension_matname : StringProperty(name = "Name",
    
                    default = 'Dimension_Red',
                    description = "Material name")
    
        Dimension_note : StringProperty(name = "Note",
    
                    default = 'Note',
                    description = "Note text")
    
        Dimension_align_to_camera : BoolProperty(name = "Align to camera",
    
                    default = False,
                    description = "Align to camera")
    
    
        TMP_startlocation : FloatVectorProperty(name = "",
    
                    description = "Start location",
                    default = (0.0, 0.0, 0.0),
                    subtype = 'XYZ')
    
        TMP_endlocation : FloatVectorProperty(name = "",
    
                    description = "Start location",
                    default = (2.0, 2.0, 2.0),
                    subtype = 'XYZ')
    
        TMP_endanglelocation : FloatVectorProperty(name = "",
    
                    description = "Start location",
                    default = (4.0, 4.0, 4.0),
                    subtype = 'XYZ')
    
        Dimension_parent : StringProperty(name = "Parent",
    
                    default = '',
                    description = "Parent")
    
        Dimension_appoint_parent : BoolProperty(name = "Appoint parent",
    
                    default = False,
                    description = "Appoint parent")
    
    
        ##### DRAW #####
        def draw(self, context):
            layout = self.layout
    
            # general options
            col = layout.column()
            col.prop(self, 'Dimension_Type')
    
            # options per Type Linear-1(width = 2, length = 2, dsize = 1, depth = 0.1)
            if self.Dimension_Type == 'Linear-1':
                row = layout.row()
                row.prop(self, 'Dimension_width_or_location', expand = True)
                col = layout.column()
                col.label(text = "End location:")
                row = layout.row()
                if self.Dimension_width_or_location == 'width':
                    row.prop(self, 'Dimension_width')
                else:
                    row.prop(self, 'Dimension_endlocation')
                box = layout.box()
    
                box.label(text="Options")
    
                box.prop(self, 'Dimension_length')
                box.prop(self, 'Dimension_dsize')
                box.prop(self, 'Dimension_depth')
                box.prop(self, 'Dimension_depth_from_center')
                box.prop(self, 'Dimension_rotation')
    
    
            # options per Type Linear-2(width = 2, dsize = 1, depth = 0.1)
            if self.Dimension_Type == 'Linear-2':
                row = layout.row()
                row.prop(self, 'Dimension_width_or_location', expand = True)
                col = layout.column()
                col.label(text = "End location:")
                row = layout.row()
                if self.Dimension_width_or_location == 'width':
                    row.prop(self, 'Dimension_width')
                else:
                    row.prop(self, 'Dimension_endlocation')
                box = layout.box()
    
                box.label(text="Options")
    
                box.prop(self, 'Dimension_dsize')
                box.prop(self, 'Dimension_depth')
                box.prop(self, 'Dimension_rotation')
    
    
            # options per Type Linear-3(width = 2, length = 2, dsize = 1, depth = 0.1)
            if self.Dimension_Type == 'Linear-3':
                row = layout.row()
                row.prop(self, 'Dimension_width_or_location', expand = True)
                col = layout.column()
                col.label(text = "End location:")
                row = layout.row()
                if self.Dimension_width_or_location == 'width':
                    row.prop(self, 'Dimension_width')
                else:
                    row.prop(self, 'Dimension_endlocation')
                box = layout.box()
    
                box.label(text="Options")
    
                box.prop(self, 'Dimension_length')
                box.prop(self, 'Dimension_dsize')
                box.prop(self, 'Dimension_depth')
                box.prop(self, 'Dimension_depth_from_center')
                box.prop(self, 'Dimension_rotation')
    
    
            # options per Type Radius(width = 2, length = 2, dsize = 1, depth = 0.1)
            if self.Dimension_Type == 'Radius':
                row = layout.row()
                row.prop(self, 'Dimension_width_or_location', expand = True)
                col = layout.column()
                col.label(text = "End location:")
                row = layout.row()
                if self.Dimension_width_or_location == 'width':
                    row.prop(self, 'Dimension_width')
                else:
                    row.prop(self, 'Dimension_endlocation')
                box = layout.box()
    
                box.label(text="Options")
    
                box.prop(self, 'Dimension_length')
                box.prop(self, 'Dimension_dsize')
                box.prop(self, 'Dimension_depth')
                box.prop(self, 'Dimension_rotation')
    
            # options per Type Diameter(width = 2, length = 2, dsize = 1, depth = 0.1)
            if self.Dimension_Type == 'Diameter':
                row = layout.row()
                row.prop(self, 'Dimension_width_or_location', expand = True)
                col = layout.column()
                col.label(text = "End location:")
                row = layout.row()
                if self.Dimension_width_or_location == 'width':
                    row.prop(self, 'Dimension_width')
                else:
                    row.prop(self, 'Dimension_endlocation')
                box = layout.box()
    
                box.label(text="Options")
    
                box.prop(self, 'Dimension_length')
                box.prop(self, 'Dimension_dsize')
                box.prop(self, 'Dimension_depth')
                box.prop(self, 'Dimension_rotation')
    
            # options per Type Angular1(width = 2, dsize = 1, depth = 0.1, angle = 45)
            if self.Dimension_Type == 'Angular1':
                row = layout.row()
                row.prop(self, 'Dimension_width_or_location', expand = True)
                col = layout.column()
                col.label(text = "End location:")
                row = layout.row()
                if self.Dimension_width_or_location == 'width':
                    row.prop(self, 'Dimension_angle')
                else:
                    row.prop(self, 'Dimension_endlocation')
                    col = layout.column()
                    col.label(text = "End angle location:")
                    row = layout.row()
                    row.prop(self, 'Dimension_endanglelocation')
                    row = layout.row()
    
                    row.prop(self, 'Angle_Type')
    
                box.label(text="Options")
    
                box.prop(self, 'Dimension_width')
                box.prop(self, 'Dimension_length')
                box.prop(self, 'Dimension_depth')
                box.prop(self, 'Dimension_depth_from_center')
                box.prop(self, 'Dimension_rotation')
                box.prop(self, 'Dimension_resolution')
    
            # options per Type Angular2(width = 2, dsize = 1, depth = 0.1, angle = 45)
            if self.Dimension_Type == 'Angular2':
                row = layout.row()
                row.prop(self, 'Dimension_width_or_location', expand = True)
                col = layout.column()
                col.label(text = "End location:")
                row = layout.row()
                if self.Dimension_width_or_location == 'width':
                    row.prop(self, 'Dimension_angle')
                else:
                    row.prop(self, 'Dimension_endlocation')
                    col = layout.column()
                    col.label(text = "End angle location:")
                    row = layout.row()
                    row.prop(self, 'Dimension_endanglelocation')
                    row = layout.row()
    
                    row.prop(self, 'Angle_Type')
    
                box.label(text="Options")
    
                box.prop(self, 'Dimension_width')
                box.prop(self, 'Dimension_depth')
                box.prop(self, 'Dimension_rotation')
                box.prop(self, 'Dimension_resolution')
    
            # options per Type Angular3(width = 2, dsize = 1, depth = 0.1, angle = 45)
            if self.Dimension_Type == 'Angular3':
                row = layout.row()
                row.prop(self, 'Dimension_width_or_location', expand = True)
                col = layout.column()
                col.label(text = "End location:")
                row = layout.row()
                if self.Dimension_width_or_location == 'width':
                    row.prop(self, 'Dimension_angle')
                else:
                    row.prop(self, 'Dimension_endlocation')
                    col = layout.column()
                    col.label(text = "End angle location:")
                    row = layout.row()
                    row.prop(self, 'Dimension_endanglelocation')
                    row = layout.row()
    
                    row.prop(self, 'Angle_Type')
    
                box.label(text="Options")
    
                box.prop(self, 'Dimension_width')
                box.prop(self, 'Dimension_length')
                box.prop(self, 'Dimension_dsize')
                box.prop(self, 'Dimension_depth')
                box.prop(self, 'Dimension_depth_from_center')
                box.prop(self, 'Dimension_rotation')
                box.prop(self, 'Dimension_resolution')
    
            # options per Type Note(width = 2, length = 2, dsize = 1, depth = 0.1)
            if self.Dimension_Type == 'Note':
                row = layout.row()
                row.prop(self, 'Dimension_width_or_location', expand = True)
                col = layout.column()
                col.label(text = "End location:")
                row = layout.row()
                if self.Dimension_width_or_location == 'width':
                    row.prop(self, 'Dimension_width')
                else:
                    row.prop(self, 'Dimension_endlocation')
                box = layout.box()
    
                box.label(text="Options")
    
                box.prop(self, 'Dimension_length')
                box.prop(self, 'Dimension_depth')
                box.prop(self, 'Dimension_angle')
                box.prop(self, 'Dimension_rotation')
                box.prop(self, 'Dimension_note')
    
    
            col = layout.column()
            row = layout.row()
            row.prop(self, 'Dimension_align_to_camera')
            col = layout.column()
            row = layout.row()
            row.prop(self, 'Dimension_liberty', expand = True)
    
            if self.Dimension_liberty == '2D':
                col = layout.column()
    
                col.label(text="Coordinate system")
    
                row = layout.row()
                row.prop(self, 'Dimension_XYZType', expand = True)
                if self.Dimension_XYZType == 'TOP' or self.Dimension_XYZType == 'BOTTOM':
                    row = layout.row()
                    row.prop(self, 'Dimension_XYType', expand = True)
                if self.Dimension_XYZType == 'FRONT' or self.Dimension_XYZType == 'BACK':
                    row = layout.row()
                    row.prop(self, 'Dimension_XZType', expand = True)
                if self.Dimension_XYZType == 'RIGHT' or self.Dimension_XYZType == 'LEFT':
                    row = layout.row()
                    row.prop(self, 'Dimension_YZType', expand = True)
    
            col = layout.column()
    
            col.label(text="Start location:")
    
            row = layout.row()
            row.prop(self, 'Dimension_startlocation')
    
            box = layout.box()
            box.prop(self, 'Dimension_units')
    
            box.prop(self, 'Dimension_add_units_name')
    
            if not self.Dimension_parent == '':
                box = layout.box()
                box.prop(self, 'Dimension_appoint_parent')
    
    
            box.label(text="Text Options")
    
            box.prop(self, 'Dimension_textsize')
            box.prop(self, 'Dimension_textdepth')
            box.prop(self, 'Dimension_textround')
            box.prop(self, 'Dimension_font')
    
            box = layout.box()
    
            box.label(text="Arrow Options")
    
            box.prop(self, 'Dimension_arrow')
            box.prop(self, 'Dimension_arrowdepth')
            box.prop(self, 'Dimension_arrowlength')
    
            box = layout.box()
    
            box.label(text="Material Option")
    
            box.prop(self, 'Dimension_matname')
    
        ##### POLL #####
        @classmethod
        def poll(cls, context):
            return context.scene !=  None
    
        ##### EXECUTE #####
        def execute(self, context):
    
            if self.Dimension_Change:
                DimensionDelete(self, context)
    
            #go to object mode
            if bpy.ops.object.mode_set.poll():
                bpy.ops.object.mode_set(mode = 'OBJECT')
    
                bpy.context.view_layer.update()
    
    
            # main function
            self.align_matrix = align_matrix(context, self.Dimension_startlocation)
            main(self, self.align_matrix)
    
            return {'FINISHED'}
    
        ##### INVOKE #####
        def invoke(self, context, event):
    
            bpy.context.view_layer.update()
    
            if self.Dimension_Change:
    
                bpy.context.scene.cursor.location = self.Dimension_startlocation
    
            else:
                if self.Dimension_width_or_location == 'width':
    
                    self.Dimension_startlocation = bpy.context.scene.cursor.location
    
    
                if self.Dimension_width_or_location == 'location':
                    if (self.Dimension_endlocation[2] - self.Dimension_startlocation[2]) !=  0 :
                        self.Dimension_XYZType = 'FRONT'
                        self.Dimension_XZType = 'Z'
                    if (self.Dimension_endlocation[1] - self.Dimension_startlocation[1]) !=  0 :
                        self.Dimension_XYZType = 'TOP'
                        self.Dimension_XYType = 'Y'
                    if (self.Dimension_endlocation[0] - self.Dimension_startlocation[0]) !=  0 :
                        self.Dimension_XYZType = 'TOP'
                        self.Dimension_XYType = 'X'
    
            self.align_matrix = align_matrix(context, self.Dimension_startlocation)
    
            self.execute(context)
    
            return {'FINISHED'}
    
    #location update
    def StartLocationUpdate(self, context):
    
    
        bpy.context.scene.cursor.location = self.Dimension_startlocation
    
    # ### MENU append ###
    def Dimension_object_menu(self, context):
        bl_label = 'Dimension'
    
        obj = context.object
        layout = self.layout
    
        if 'Dimension' in obj.keys():
            props = layout.operator("curve.dimension", text="Change Dimension")
            props.Dimension_Change = True
            props.Dimension_Delete = obj.name
            props.Dimension_width_or_location = obj["Dimension_width_or_location"]
            props.Dimension_startlocation = obj.location
            props.Dimension_endlocation = obj["Dimension_endlocation"]
            props.Dimension_endanglelocation = obj["Dimension_endanglelocation"]
            props.Dimension_liberty = obj["Dimension_liberty"]
            props.Dimension_Type = obj["Dimension_Type"]
            props.Dimension_XYZType = obj["Dimension_XYZType"]
            props.Dimension_XYType = obj["Dimension_XYType"]
            props.Dimension_XZType = obj["Dimension_XZType"]
            props.Dimension_YZType = obj["Dimension_YZType"]
            props.Dimension_resolution = obj["Dimension_resolution"]
            props.Dimension_width = obj["Dimension_width"]
            props.Dimension_length = obj["Dimension_length"]
            props.Dimension_dsize = obj["Dimension_dsize"]
            props.Dimension_depth = obj["Dimension_depth"]
            props.Dimension_depth_from_center = obj["Dimension_depth_from_center"]
            props.Dimension_angle = obj["Dimension_angle"]
            props.Dimension_rotation = obj["Dimension_rotation"]
            props.Dimension_offset = 0
            props.Dimension_textsize = obj["Dimension_textsize"]
            props.Dimension_textdepth = obj["Dimension_textdepth"]
            props.Dimension_textround = obj["Dimension_textround"]
            props.Dimension_font = obj["Dimension_font"]
            props.Dimension_matname = obj["Dimension_matname"]
            props.Dimension_note = obj["Dimension_note"]
            props.Dimension_align_to_camera = obj["Dimension_align_to_camera"]
            props.Dimension_arrow = obj["Dimension_arrow"]
            props.Dimension_arrowdepth = obj["Dimension_arrowdepth"]
            props.Dimension_arrowlength = obj["Dimension_arrowlength"]
            props.Dimension_parent = obj["Dimension_parent"]
            props.Dimension_appoint_parent = obj["Dimension_appoint_parent"]
            props.Dimension_units = obj["Dimension_units"]
            props.Dimension_add_units_name = obj["Dimension_add_units_name"]
            layout.separator()
    
        vertex = []
        for obj in context.selected_objects :
            if obj.type == 'MESH':
                for i in obj.data.vertices :
                    if i.select :
                        vertex.append(obj.matrix_world @ i.co)
    
            if obj.type == 'CURVE':
                for i in obj.data.splines :
                    for j in i.bezier_points :
                        if j.select_control_point :
                            vertex.append(obj.matrix_world @ j.co)
    
        if len(vertex) == 1:
            startvertex = vertex[0]
            endvertex = bpy.context.scene.cursor.location
            props1 = layout.operator("curve.dimension", text = 'Add linear note')
            props1.Dimension_Change = False
            props1.Dimension_Type = 'Note'
            props1.Dimension_width_or_location = 'location'
            props1.Dimension_startlocation = startvertex
            props1.Dimension_liberty = '2D'
            props1.Dimension_rotation = 0
            props1.Dimension_parent = obj.name
    
            props2 = layout.operator("curve.dimension", text = 'Add 3D note')
            props2.Dimension_Change = False
            props2.Dimension_Type = 'Note'
            props2.Dimension_width_or_location = 'location'
            props2.Dimension_startlocation = startvertex
            props2.Dimension_liberty = '3D'
            props2.Dimension_rotation = 0
            props2.Dimension_parent = obj.name
    
            props3 = layout.operator("curve.dimension", text = 'Add linear dimension')
            props3.Dimension_Change = False
            props3.Dimension_Type = 'Linear-1'
            props3.Dimension_width_or_location = 'location'
            props3.Dimension_startlocation = endvertex
            props3.Dimension_endlocation = startvertex
            props3.Dimension_liberty = '2D'
            props3.Dimension_rotation = 0
            props3.Dimension_parent = obj.name
    
            props4 = layout.operator("curve.dimension", text = 'Add 3D dimension')
            props4.Dimension_Change = False
            props4.Dimension_Type = 'Linear-1'
            props4.Dimension_width_or_location = 'location'
            props4.Dimension_startlocation = endvertex
            props4.Dimension_endlocation = startvertex
            props4.Dimension_liberty = '3D'
            props4.Dimension_rotation = 0
            props4.Dimension_parent = obj.name
    
            props7 = layout.operator("curve.dimension", text = 'Add linear radius')
            props7.Dimension_Change = False
            props7.Dimension_Type = 'Radius'
            props7.Dimension_width_or_location = 'location'
            props7.Dimension_startlocation = endvertex
            props7.Dimension_endlocation = startvertex
            props7.Dimension_liberty = '2D'
            props7.Dimension_rotation = 0
            props7.Dimension_parent = obj.name
    
            props8 = layout.operator("curve.dimension", text = 'Add 3D radius')
            props8.Dimension_Change = False
            props8.Dimension_Type = 'Radius'
            props8.Dimension_width_or_location = 'location'
            props8.Dimension_startlocation = endvertex
            props8.Dimension_endlocation = startvertex
            props8.Dimension_liberty = '3D'
            props8.Dimension_rotation = 0
            props8.Dimension_parent = obj.name
    
            props9 = layout.operator("curve.dimension", text = 'Add linear diameter')
            props9.Dimension_Change = False
            props9.Dimension_Type = 'Diameter'
            props9.Dimension_width_or_location = 'location'
            props9.Dimension_startlocation = endvertex
            props9.Dimension_endlocation = startvertex
            props9.Dimension_liberty = '2D'
            props9.Dimension_rotation = 0
            props9.Dimension_parent = obj.name
    
            props10 = layout.operator("curve.dimension", text = 'Add 3D diameter')
            props10.Dimension_Change = False
            props10.Dimension_Type = 'Diameter'
            props10.Dimension_width_or_location = 'location'
            props10.Dimension_startlocation = endvertex
            props10.Dimension_endlocation = startvertex
            props10.Dimension_liberty = '3D'
            props10.Dimension_rotation = 0
            props10.Dimension_parent = obj.name
    
        if len(vertex) == 2:
            startvertex = vertex[0]
            endvertex = vertex[1]
            if endvertex[0] < startvertex[0]:
                startvertex = vertex[1]
                endvertex = vertex[0]
    
            props1 = layout.operator("curve.dimension", text = 'Add linear dimension')
            props1.Dimension_Change = False
            props1.Dimension_Type = 'Linear-1'
            props1.Dimension_width_or_location = 'location'
            props1.Dimension_startlocation = startvertex
            props1.Dimension_endlocation = endvertex
            props1.Dimension_liberty = '2D'
            props1.Dimension_rotation = 0
            props1.Dimension_parent = obj.name
    
            props2 = layout.operator("curve.dimension", text = 'Add 3D dimension')
            props2.Dimension_Change = False
            props2.Dimension_Type = 'Linear-1'
            props2.Dimension_width_or_location = 'location'
            props2.Dimension_startlocation = startvertex
            props2.Dimension_endlocation = endvertex
            props2.Dimension_liberty = '3D'
            props2.Dimension_rotation = 0
            props2.Dimension_parent = obj.name
    
            props3 = layout.operator("curve.dimension", text = 'Add linear radius')
            props3.Dimension_Change = False
            props3.Dimension_Type = 'Radius'
            props3.Dimension_width_or_location = 'location'
            props3.Dimension_startlocation = startvertex
            props3.Dimension_endlocation = endvertex
            props3.Dimension_liberty = '2D'
            props3.Dimension_rotation = 0
            props3.Dimension_parent = obj.name
    
            props4 = layout.operator("curve.dimension", text = 'Add 3D radius')
            props4.Dimension_Change = False
            props4.Dimension_Type = 'Radius'
            props4.Dimension_width_or_location = 'location'
            props4.Dimension_startlocation = startvertex
            props4.Dimension_endlocation = endvertex
            props4.Dimension_liberty = '3D'
            props4.Dimension_rotation = 0
            props4.Dimension_parent = obj.name
    
            props5 = layout.operator("curve.dimension", text = 'Add linear diameter')
            props5.Dimension_Change = False
            props5.Dimension_Type = 'Diameter'
            props5.Dimension_width_or_location = 'location'
            props5.Dimension_startlocation = startvertex
            props5.Dimension_endlocation = endvertex
            props5.Dimension_liberty = '2D'
            props5.Dimension_rotation = 0
            props5.Dimension_parent = obj.name
    
            props6 = layout.operator("curve.dimension", text = 'Add 3D diameter')
            props6.Dimension_Change = False
            props6.Dimension_Type = 'Diameter'
            props6.Dimension_width_or_location = 'location'
            props6.Dimension_startlocation = startvertex
            props6.Dimension_endlocation = endvertex
            props6.Dimension_liberty = '3D'
            props6.Dimension_rotation = 0
            props6.Dimension_parent = obj.name
    
        if len(vertex) == 3:
            startvertex = vertex[0]
            endvertex = vertex[1]
            endanglevertex = vertex[2]
            if endvertex[0] < startvertex[0]:
                startvertex = vertex[1]
                endvertex = vertex[0]
    
            props1 = layout.operator("curve.dimension", text = 'Add Linear angle dimension')
            props1.Dimension_Change = False
            props1.Dimension_Type = 'Angular1'
            props1.Dimension_width_or_location = 'location'
            props1.Dimension_startlocation = startvertex
            props1.Dimension_endlocation = endvertex
            props1.Dimension_endanglelocation = endanglevertex
            props1.Dimension_liberty = '2D'
            props1.Dimension_rotation = 0
            props1.Dimension_parent = obj.name
    
            props2 = layout.operator("curve.dimension", text = 'Add 3D angle dimension')
            props2.Dimension_Change = False
            props2.Dimension_Type = 'Angular1'
            props2.Dimension_width_or_location = 'location'
            props2.Dimension_startlocation = startvertex
            props2.Dimension_endlocation = endvertex
            props2.Dimension_endanglelocation = endanglevertex
            props2.Dimension_liberty = '3D'
            props2.Dimension_rotation = 0
            props2.Dimension_parent = obj.name
    
    def Dimension_edit_menu(self, context):
        bl_label = 'Dimension'
    
        obj = context.object
        layout = self.layout
    
        vertex = []
        for i in obj.data.vertices :
            if i.select :
                vertex.append(obj.matrix_world @ i.co)
    
        if len(vertex) == 1:
            startvertex = vertex[0]
            endvertex = bpy.context.scene.cursor.location
            props1 = layout.operator("curve.dimension", text = 'Add linear note')
            props1.Dimension_Change = False
            props1.Dimension_Type = 'Note'
            props1.Dimension_width_or_location = 'location'
            props1.Dimension_startlocation = startvertex
            props1.Dimension_liberty = '2D'
            props1.Dimension_rotation = 0
            props1.Dimension_parent = obj.name
    
            props2 = layout.operator("curve.dimension", text = 'Add 3D note')
            props2.Dimension_Change = False
            props2.Dimension_Type = 'Note'
            props2.Dimension_width_or_location = 'location'
            props2.Dimension_startlocation = startvertex
            props2.Dimension_liberty = '3D'
            props2.Dimension_rotation = 0
            props2.Dimension_parent = obj.name
    
            props3 = layout.operator("curve.dimension", text = 'Add linear dimension')
            props3.Dimension_Change = False
            props3.Dimension_Type = 'Linear-1'
            props3.Dimension_width_or_location = 'location'
            props3.Dimension_startlocation = endvertex
            props3.Dimension_endlocation = startvertex
            props3.Dimension_liberty = '2D'
            props3.Dimension_rotation = 0
            props3.Dimension_parent = obj.name
    
            props4 = layout.operator("curve.dimension", text = 'Add 3D dimension')
            props4.Dimension_Change = False
            props4.Dimension_Type = 'Linear-1'
            props4.Dimension_width_or_location = 'location'
            props4.Dimension_startlocation = endvertex
            props4.Dimension_endlocation = startvertex
            props4.Dimension_liberty = '3D'
            props4.Dimension_rotation = 0
            props4.Dimension_parent = obj.name
    
            props7 = layout.operator("curve.dimension", text = 'Add linear radius')
            props7.Dimension_Change = False
            props7.Dimension_Type = 'Radius'
            props7.Dimension_width_or_location = 'location'
            props7.Dimension_startlocation = endvertex
            props7.Dimension_endlocation = startvertex
            props7.Dimension_liberty = '2D'
            props7.Dimension_rotation = 0
            props7.Dimension_parent = obj.name
    
            props8 = layout.operator("curve.dimension", text = 'Add 3D radius')
            props8.Dimension_Change = False
            props8.Dimension_Type = 'Radius'
            props8.Dimension_width_or_location = 'location'
            props8.Dimension_startlocation = endvertex
            props8.Dimension_endlocation = startvertex
            props8.Dimension_liberty = '3D'
            props8.Dimension_rotation = 0
            props8.Dimension_parent = obj.name
    
            props9 = layout.operator("curve.dimension", text = 'Add linear diameter')
            props9.Dimension_Change = False
            props9.Dimension_Type = 'Diameter'
            props9.Dimension_width_or_location = 'location'
            props9.Dimension_startlocation = endvertex
            props9.Dimension_endlocation = startvertex
            props9.Dimension_liberty = '2D'
            props9.Dimension_rotation = 0
            props9.Dimension_parent = obj.name
    
            props10 = layout.operator("curve.dimension", text = 'Add 3D diameter')
            props10.Dimension_Change = False
            props10.Dimension_Type = 'Diameter'
            props10.Dimension_width_or_location = 'location'
            props10.Dimension_startlocation = endvertex
            props10.Dimension_endlocation = startvertex
            props10.Dimension_liberty = '3D'
            props10.Dimension_rotation = 0
            props10.Dimension_parent = obj.name
    
        if len(vertex) == 2:
            startvertex = vertex[0]
            endvertex = vertex[1]
            if endvertex[0] < startvertex[0]:
                startvertex = vertex[1]
                endvertex = vertex[0]
    
            props1 = layout.operator("curve.dimension", text = 'Add linear dimension')
            props1.Dimension_Change = False
            props1.Dimension_Type = 'Linear-1'
            props1.Dimension_width_or_location = 'location'
            props1.Dimension_startlocation = startvertex
            props1.Dimension_endlocation = endvertex
            props1.Dimension_liberty = '2D'
            props1.Dimension_rotation = 0
            props1.Dimension_parent = obj.name
    
            props2 = layout.operator("curve.dimension", text = 'Add 3D dimension')
            props2.Dimension_Change = False
            props2.Dimension_Type = 'Linear-1'
            props2.Dimension_width_or_location = 'location'
            props2.Dimension_startlocation = startvertex
            props2.Dimension_endlocation = endvertex
            props2.Dimension_liberty = '3D'
            props2.Dimension_rotation = 0
            props2.Dimension_parent = obj.name
    
            props3 = layout.operator("curve.dimension", text = 'Add linear radius')
            props3.Dimension_Change = False
            props3.Dimension_Type = 'Radius'
            props3.Dimension_width_or_location = 'location'
            props3.Dimension_startlocation = startvertex
            props3.Dimension_endlocation = endvertex
            props3.Dimension_liberty = '2D'
            props3.Dimension_rotation = 0
            props3.Dimension_parent = obj.name
    
            props4 = layout.operator("curve.dimension", text = 'Add 3D radius')
            props4.Dimension_Change = False
            props4.Dimension_Type = 'Radius'
            props4.Dimension_width_or_location = 'location'
            props4.Dimension_startlocation = startvertex
            props4.Dimension_endlocation = endvertex
            props4.Dimension_liberty = '3D'
            props4.Dimension_rotation = 0
            props4.Dimension_parent = obj.name
    
            props5 = layout.operator("curve.dimension", text = 'Add linear diameter')
            props5.Dimension_Change = False
            props5.Dimension_Type = 'Diameter'
            props5.Dimension_width_or_location = 'location'
            props5.Dimension_startlocation = startvertex
            props5.Dimension_endlocation = endvertex
            props5.Dimension_liberty = '2D'
            props5.Dimension_rotation = 0
            props5.Dimension_parent = obj.name
    
            props6 = layout.operator("curve.dimension", text = 'Add 3D diameter')
            props6.Dimension_Change = False
            props6.Dimension_Type = 'Diameter'
            props6.Dimension_width_or_location = 'location'
            props6.Dimension_startlocation = startvertex
            props6.Dimension_endlocation = endvertex
            props6.Dimension_liberty = '3D'
            props6.Dimension_rotation = 0
            props6.Dimension_parent = obj.name
    
        if len(vertex) == 3:
            startvertex = vertex[0]
            endvertex = vertex[1]
            endanglevertex = vertex[2]
            if endvertex[0] < startvertex[0]:
                startvertex = vertex[1]
                endvertex = vertex[0]
    
            props1 = layout.operator("curve.dimension", text = 'Add Linear angle dimension')
            props1.Dimension_Change = False
            props1.Dimension_Type = 'Angular1'
            props1.Dimension_width_or_location = 'location'
            props1.Dimension_startlocation = startvertex
            props1.Dimension_endlocation = endvertex
            props1.Dimension_endanglelocation = endanglevertex
            props1.Dimension_liberty = '2D'
            props1.Dimension_rotation = 0
            props1.Dimension_parent = obj.name