Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
markersize = 2 * 2.5
triangle = [[0, 0], [-1, 1], [1, 1]]
triangle = [[0, 0], [-1, 1], [1, 1]]
for co in triangle:
co[0] = int(co[0] * markersize * 3) + ar12d[0]
co[1] = int(co[1] * markersize * 3) + ar12d[1]
bgl.glColor4f(0.4, 0.15, 0.75, 1.0)
bgl.glBegin(bgl.GL_TRIANGLE_FAN)
for x,y in triangle:
bgl.glVertex2f(x,y)
bgl.glEnd()
triangle = [[0, 0], [-1, 1], [1, 1]]
for co in triangle:
co[0] = int(co[0] * markersize * 3) + ar22d[0]
co[1] = int(co[1] * markersize * 3) + ar22d[1]
bgl.glColor4f(0.4, 0.15, 0.75, 1.0)
bgl.glBegin(bgl.GL_TRIANGLE_FAN)
for x,y in triangle:
bgl.glVertex2f(x,y)
bgl.glEnd()
# AR NUMERICAL DISTANCE:
display_distance_between_two_points(region, rv3d, NP020PA.ar13d, NP020PA.ar23d)
#DRAWING END:
bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
np_print('06a_DRAW_ArrayTrans_FINISHED',';','flag = ', NP020PA.flag)
# Restoring the object selection and system settings from before the operator activation. Deleting the helpers after successful translation, reseting all viewport options and reselecting previously selected objects:
class NPPARestoreContext(bpy.types.Operator):
bl_idname = "object.np_pa_restore_context"
bl_label = "NP PA Restore Context"
bl_options = {'INTERNAL'}
def execute(self, context):
np_print('07_CleanExit_START',';','flag = ', NP020PA.flag)
flag = NP020PA.flag
selob = NP020PA.selob
take = NP020PA.take
place = NP020PA.place
bpy.ops.object.select_all(action='DESELECT')
take.select_set(True)
place.select_set(True)
if NP020PA.prevob != None:
prevob = NP020PA.prevob
nextob = NP020PA.nextob
if prevob is not selob:
for i, ob in enumerate(prevob):
bpy.ops.object.delete('EXEC_DEFAULT')
lenselob = len(selob)
for i, ob in enumerate(selob):
bpy.context.view_layer.objects.active = ob
NP020PA.take = None
NP020PA.place = None
NP020PA.takeloc3d = (0.0,0.0,0.0)
NP020PA.placeloc3d = (0.0,0.0,0.0)
NP020PA.prevob = None
NP020PA.nextob = None
NP020PA.dist = None
NP020PA.mode = 'MOVE'
NP020PA.flag = 'NONE'
NP020PA.ardict = {}
NP020PA.deltavec = Vector ((0, 0, 0))
NP020PA.deltavec_safe = Vector ((0, 0, 0))
bpy.context.tool_settings.use_snap = NP020PA.use_snap
bpy.context.tool_settings.snap_element = NP020PA.snap_element
bpy.context.tool_settings.snap_target = NP020PA.snap_target
bpy.context.space_data.pivot_point = NP020PA.pivot_point
bpy.context.space_data.transform_orientation = NP020PA.trans_orient
if NP020PA.acob is not None:
bpy.context.view_layer.objects.active = NP020PA.acob
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
bpy.ops.object.mode_set(mode = NP020PA.edit_mode)
np_print('07_CleanExit_FINISHED',';','flag = ', NP020PA.flag)
return {'FINISHED'}
'''
# Defining the settings of the addon in the User preferences / addons tab:
class NPPAPreferences(bpy.types.AddonPreferences):
# this must match the addon name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __name__
dist_scale = bpy.props.FloatProperty(
name='Unit scale',
description='Distance multiplier (for example, for cm use 100)',
default=100,
min=0,
step=1,
precision=3)
suffix = bpy.props.EnumProperty(
name='Unit suffix',
items=(("'","'",''), ('"','"',''), ('thou','thou',''), ('km','km',''), ('m','m',''), ('cm','cm',''), ('mm','mm',''), ('nm','nm',''), ('None','None','')),
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
default='cm',
description='Add a unit extension after the numerical distance ')
badge = bpy.props.BoolProperty(
name='Mouse badge',
description='Use the graphical badge near the mouse cursor',
default=True)
badge_size = bpy.props.FloatProperty(
name='size',
description='Size of the mouse badge, the default is 2.0',
default=2,
min=0.5,
step=10,
precision=1)
col_line_main_DEF = bpy.props.BoolProperty(
name='Default',
description='Use the default color',
default=True)
col_line_shadow_DEF = bpy.props.BoolProperty(
name='Default',
description='Use the default color',
default=True)
col_num_main_DEF = bpy.props.BoolProperty(
name='Default',
description='Use the default color',
default=True)
col_num_shadow_DEF = bpy.props.BoolProperty(
name='Default',
description='Use the default color',
default=True)
col_line_main = bpy.props.FloatVectorProperty(name='', default=(1.0, 1.0, 1.0, 1.0), size=4, subtype="COLOR", min=0, max=1, description = 'Color of the measurement line, to disable it set alpha to 0.0')
col_line_shadow = bpy.props.FloatVectorProperty(name='', default=(0.1, 0.1, 0.1, 0.25), size=4, subtype="COLOR", min=0, max=1, description = 'Color of the line shadow, to disable it set alpha to 0.0')
col_num_main = bpy.props.FloatVectorProperty(name='', default=(0.1, 0.1, 0.1, 0.75), size=4, subtype="COLOR", min=0, max=1, description = 'Color of the number, to disable it set alpha to 0.0')
col_num_shadow = bpy.props.FloatVectorProperty(name='', default=(1.0, 1.0, 1.0, 1.0), size=4, subtype="COLOR", min=0, max=1, description = 'Color of the number shadow, to disable it set alpha to 0.0')
def draw(self, context):
layout = self.layout
split = layout.split()
col = split.column()
col.prop(self, "dist_scale")
col = split.column()
col.prop(self, "suffix")
split = layout.split()
col = split.column()
col.label(text='Line Main COLOR')
col.prop(self, "col_line_main_DEF")
if self.col_line_main_DEF == False:
col.prop(self, "col_line_main")
col = split.column()
col.label(text='Line Shadow COLOR')
col.prop(self, "col_line_shadow_DEF")
if self.col_line_shadow_DEF == False:
col.prop(self, "col_line_shadow")
col = split.column()
col.label(text='Numerical Main COLOR')
col.prop(self, "col_num_main_DEF")
if self.col_num_main_DEF == False:
col.prop(self, "col_num_main")
col = split.column()
col.label(text='Numerical Shadow COLOR')
col.prop(self, "col_num_shadow_DEF")
if self.col_num_shadow_DEF == False:
col.prop(self, "col_num_shadow")
split = layout.split()
col = split.column()
col.prop(self, "badge")
col = split.column()
if self.badge == True:
col.prop(self, "badge_size")
col = split.column()
col = split.column()
'''
# This is the actual addon process, the algorithm that defines the order of operator activation inside the main macro:
def register():
#bpy.utils.register_class(NPPAPreferences)
#bpy.utils.register_module(__name__)
bpy.app.handlers.scene_update_post.append(NPPA_scene_update)
NP020PointArray.define('OBJECT_OT_np_pa_get_context')
NP020PointArray.define('OBJECT_OT_np_pa_get_selection')
NP020PointArray.define('OBJECT_OT_np_pa_get_mouseloc')
NP020PointArray.define('OBJECT_OT_np_pa_add_helpers')
NP020PointArray.define('OBJECT_OT_np_pa_prepare_context')
for i in range(1, 3):
for i in range(1, 10):
NP020PointArray.define('OBJECT_OT_np_pa_run_translate')
NP020PointArray.define('OBJECT_OT_np_pa_nav_translate')
NP020PointArray.define('OBJECT_OT_np_pa_prepare_next')
NP020PointArray.define('OBJECT_OT_np_pa_array_translate')
NP020PointArray.define('OBJECT_OT_np_pa_restore_context')
def unregister():
#pass
#bpy.utils.unregister_class(NPPAPreferences)
#bpy.utils.unregister_module(__name__)
bpy.app.handlers.scene_update_post.remove(NPPA_scene_update)