Skip to content
Snippets Groups Projects
add_dimension.py 133 KiB
Newer Older
  • Learn to ignore specific revisions
  • def StartLocationUpdate(self, context):
    
        bpy.context.scene.cursor_location = self.Dimension_startlocation
    
        return
    
    # Add properties to objects
    def DimensionVariables():
    
        bpy.types.Object.Dimension = bpy.props.BoolProperty()
        bpy.types.Object.Dimension_Change = bpy.props.BoolProperty()
        bpy.types.Object.Dimension_Name = bpy.props.StringProperty(name = "Name",
                    description = "Name")
        #### 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')]
        bpy.types.Object.Dimension_Type = bpy.props.EnumProperty(name = "Type",
                    description = "Form of Curve to create",
                    items = Types)
        XYZTypes = [
                    ('TOP', 'Top', 'TOP'),
                    ('FRONT', 'Front', 'FRONT'),
                    ('RIGHT', 'Right', 'RIGHT'),
                    ('BOTTOM', 'Bottom', 'BOTTOM'),
                    ('BACK', 'Back', 'BACK'),
                    ('LEFT', 'Left', 'LEFT')]
        bpy.types.Object.Dimension_XYZType = bpy.props.EnumProperty(name = "Coordinate system",
                    description = "Place in a coordinate system",
                    items = XYZTypes)
        XYTypes = [
                    ('X', 'X', 'X'),
                    ('Y', 'Y', 'Y')]
        bpy.types.Object.Dimension_XYType = bpy.props.EnumProperty(name = "XY",
                    description = "XY",
                    items = XYTypes)
        XZTypes = [
                    ('X', 'X', 'X'),
                    ('Z', 'Z', 'Z')]
        bpy.types.Object.Dimension_XZType = bpy.props.EnumProperty(name = "XZ",
                    description = "XZ",
                    items = XZTypes)
        YZTypes = [
                    ('Y', 'Y', 'Y'),
                    ('Z', 'Z', 'Z')]
        bpy.types.Object.Dimension_YZType = bpy.props.EnumProperty(name = "YZ",
                    description = "YZ",
                    items = YZTypes)
        bpy.types.Object.Dimension_YZType = bpy.props.EnumProperty(name = "Coordinate system",
                    description = "Place in a coordinate system",
                    items = YZTypes)
        bpy.types.Object.Dimension_startlocation = bpy.props.FloatVectorProperty(name = "Start location",
                    description = "",
                    subtype = 'XYZ',
                    update = StartLocationUpdate)
        bpy.types.Object.Dimension_endlocation = bpy.props.FloatVectorProperty(name = "End location",
                    description = "",
                    subtype = 'XYZ')
        bpy.types.Object.Dimension_endanglelocation = bpy.props.FloatVectorProperty(name = "End angle location",
                    description = "End angle location",
                    subtype = 'XYZ')
        width_or_location_items = [
                    ('width', 'width', 'width'),
                    ('location', 'location', 'location')]
        bpy.types.Object.Dimension_width_or_location = bpy.props.EnumProperty(name = "width or location",
                    items = width_or_location_items,
                    description = "width or location")
        libertyItems = [
                    ('2D', '2D', '2D'),
                    ('3D', '3D', '3D')]
        bpy.types.Object.Dimension_liberty = bpy.props.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')]
        bpy.types.Object.Dimension_arrow = bpy.props.EnumProperty(name = "Arrow",
                    items = Arrows,
                    description = "Arrow")
        bpy.types.Object.Dimension_arrowdepth = bpy.props.FloatProperty(name = "Depth",
                        min = 0, soft_min = 0,
                        description = "Arrow depth")
        bpy.types.Object.Dimension_arrowlength = bpy.props.FloatProperty(name = "Length",
                        min = 0, soft_min = 0,
                        description = "Arrow length")
    
        #### Dimension properties
        bpy.types.Object.Dimension_resolution = bpy.props.IntProperty(name = "Resolution",
                        min = 1, soft_min = 1,
                        description = "Resolution")
        bpy.types.Object.Dimension_width = bpy.props.FloatProperty(name = "Width",
                        unit = 'LENGTH',
                        description = "Width")
        bpy.types.Object.Dimension_length = bpy.props.FloatProperty(name = "Length",
                        description = "Length")
        bpy.types.Object.Dimension_dsize = bpy.props.FloatProperty(name = "Size",
                        min = 0, soft_min = 0,
                        description = "Size")
        bpy.types.Object.Dimension_depth = bpy.props.FloatProperty(name = "Depth",
                        min = 0, soft_min = 0,
                        description = "Depth")
        bpy.types.Object.Dimension_depth_from_center = bpy.props.BoolProperty(name = "Depth from center",
                        description = "Depth from center")
        bpy.types.Object.Dimension_angle = bpy.props.FloatProperty(name = "Angle",
                        description = "Angle")
        bpy.types.Object.Dimension_rotation = bpy.props.FloatProperty(name = "Rotation",
                        description = "Rotation")
    
        #### 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')]
        bpy.types.Object.Dimension_units = bpy.props.EnumProperty(name = "Units",
                    items = Units,
                    description = "Units")
    
        bpy.types.Object.Dimension_add_units_name = bpy.props.BoolProperty(name = "Add units name",
                    description = "Add units name")
        bpy.types.Object.Dimension_offset = bpy.props.FloatProperty(name = "Offset",
                    description = "Offset")
    
    
        #### Dimension text properties
        bpy.types.Object.Dimension_textsize = bpy.props.FloatProperty(name = "Size",
                        description = "Size")
        bpy.types.Object.Dimension_textdepth = bpy.props.FloatProperty(name = "Depth",
                        description = "Depth")
        bpy.types.Object.Dimension_textround = bpy.props.IntProperty(name = "Rounding",
                        min = 0, soft_min = 0,
                        description = "Rounding")
        bpy.types.Object.Dimension_font = bpy.props.StringProperty(name = "Font",
                        subtype = 'FILE_PATH',
                        description = "Font")
    
        #### Materials properties
        bpy.types.Object.Dimension_matname = bpy.props.StringProperty(name = "Name",
                        default = 'Dimension_Red',
                        description = "Material name")
    
        #### Note text
        bpy.types.Object.Dimension_note = bpy.props.StringProperty(name = "Note",
                        default = 'Note',
                        description = "Note text")
        bpy.types.Object.Dimension_align_to_camera = bpy.props.BoolProperty(name = "Align to camera",
                    description = "Align to camera")
    
    
        #### Parent
        bpy.types.Object.Dimension_parent = bpy.props.StringProperty(name = "Parent",
                        default = '',
                        description = "Parent")
        bpy.types.Object.Dimension_appoint_parent = bpy.props.BoolProperty(name = "Appoint parent",
                    description = "Appoint parent")
    
    
    ################################################################################
    ##### REGISTER #####
    
    def Dimension_button(self, context):
        oper = self.layout.operator(Dimension.bl_idname, text = "Dimension", icon = "PLUGIN")
        oper.Dimension_Change = False
        oper.Dimension_width_or_location = 'width'
        oper.Dimension_liberty = '2D'
    
    def register():
        bpy.utils.register_module(__name__)
    
    
        bpy.types.VIEW3D_MT_curve_add.append(Dimension_button)
    
    
        DimensionVariables()
    
    def unregister():
        bpy.utils.unregister_module(__name__)
    
    
        bpy.types.VIEW3D_MT_curve_add.remove(Dimension_button)
    
    
    if __name__ == "__main__":
        register()