<commit_before>import bpy
from mathutils import Matrix
from collections import defaultdict
from .. import var
from . import (
	units,
	utility,
)


def gem_import():
	props = bpy.context.scene.jewelcraft
	tpe = props.import_gem_type
	cut = props.import_gem_cut
	size = props.import_gem_size

	data_to = asset_import(ob_name=cut.title(), mat_name=tpe.replace('_', ' ').title())
	bpy.ops.object.select_all(action='DESELECT')

	ob = data_to.objects[0]
	ob.data['gem'] = {'cut': cut}

	ob.location = bpy.context.scene.cursor_location
	to_size(ob, size)
	type_set(ob, tpe, data_to.materials)
	sce_link(ob, active=True)


def cut_replace():
	context = bpy.context
	props = context.scene.jewelcraft
	cut = props.import_gem_cut

	for obj in context.selected_objects:
		if obj.data.get('gem'):
			data_to = asset_import(ob_name=cut.title())

			ob = data_to.objects[0]
			ob.data['gem'] = {'cut': cut}

			append_to(ob, obj)
			to_size(ob, obj.dimensions[1])
			type_copy(ob, obj)

			bpy.context.scene.objects.unlink(obj)
			bpy.data.objects.remove(obj)
			sce_link(ob, active=True)


def type_replace():
	context = bpy.context
	tpe = context.scene.jewelcraft.import_gem_type

	data_to = asset_import(mat_name=tpe.replace('_', ' ').title())
	for ob in context.selected_objects:
		if ob.data.get('gem'):
			type_set(ob, tpe, data_to.materials)






def prongs_import():
	for obj in bpy.context.selected_objects:
		if obj.data.get('gem'):
			utility.ob_prop_style_convert(obj)
			cut = obj.data['gem']['cut']
			data_to = asset_import(ob_name=cut.title()+' Prongs', mat_name='Prongs')

			ob = data_to.objects[0]
			append_to(ob, obj)
			to_size(ob, obj.dimensions[1])
			material_assign(ob, 'Prongs', data_to.materials)
			sce_link(ob)


def single_prong_import():
	data_to = asset_import(ob_name='Single Prong', mat_name='Prongs')
	bpy.ops.object.select_all(action='DESELECT')

	ob = data_to.objects[0]
	ob.location = bpy.context.scene.cursor_location
	material_assign(ob, 'Prongs', data_to.materials)
	sce_link(ob, active=True)


def cutter_import(seat_only=False):
	suffix = ''
	if seat_only:
		suffix = ' (Seat only)'

	for obj in bpy.context.selected_objects:
		if obj.data.get('gem'):
			utility.ob_prop_style_convert(obj)
			cut = obj.data['gem']['cut']
			data_to = asset_import(ob_name=cut.title()+' Cutter'+suffix, mat_name='Cutter')

			ob = data_to.objects[0]
			append_to(ob, obj)
			to_dimensions(ob, obj)
			material_assign(ob, 'Cutter', data_to.materials)
			sce_link(ob)


def imitation_import():
	data_to = asset_import(ob_name='Imitation (3 prong)', mat_name='Prongs')
	bpy.ops.object.select_all(action='DESELECT')

	ob = data_to.objects[0]
	ob.location = bpy.context.scene.cursor_location
	material_assign(ob, 'Prongs', data_to.materials)
	sce_link(ob, active=True)


def make_dupliface():
	context = bpy.context
	data = bpy.data

	gem = False
	obs = []
	obs_app = obs.append
	for ob in context.selected_objects:
		if (ob.data and ob.data.get('gem')):
			gem = ob
			obs_app(ob)
		else:
			obs_app(ob)

	if gem:
		ob = gem
		name = ob.name+' '
	else:
		ob = obs[0]
		name = ''


	verts = [(-0.15,0.15,0), (0.15,0.15,0), (0.15,-0.15,0), (-0.15,-0.15,0)]
	faces = [(3,2,1,0)]


	offset = (ob.dimensions[0]+1, 0, 0)
	for i in range(len(verts)):
		verts[i] = tuple(x+y for x,y in zip(verts[i], offset))


	me = data.meshes.new(name+'Duplifaces')
	me.from_pydata(verts, [], faces)
	me.update()

	df = data.objects.new(name+'Duplifaces', me)
	df.location = ob.location
	df.dupli_type = 'FACES'
	context.scene.objects.link(df)

	for ob in obs:
		ob.parent = df
		ob.location = [0,0,0]
		apply_transforms(ob)



def select_dupli():
	context = bpy.context
	sce = context.scene
	gems_loc = []
	gems_name = []

	bpy.ops.object.select_all(action='DESELECT')

	loc_app = gems_loc.append
	name_app = gems_name.append
	for ob in context.visible_objects:<commit_msg>Make Dupli-Face: use origin_clear()<commit_after>import bpy
from mathutils import Matrix
from collections import defaultdict
from .. import var
from . import (
	units,
	utility,
)


def gem_import():
	props = bpy.context.scene.jewelcraft
	tpe = props.import_gem_type
	cut = props.import_gem_cut
	size = props.import_gem_size

	data_to = asset_import(ob_name=cut.title(), mat_name=tpe.replace('_', ' ').title())
	bpy.ops.object.select_all(action='DESELECT')

	ob = data_to.objects[0]
	ob.data['gem'] = {'cut': cut}

	ob.location = bpy.context.scene.cursor_location
	to_size(ob, size)
	type_set(ob, tpe, data_to.materials)
	sce_link(ob, active=True)


def cut_replace():
	context = bpy.context
	props = context.scene.jewelcraft
	cut = props.import_gem_cut

	for obj in context.selected_objects:
		if obj.data.get('gem'):
			data_to = asset_import(ob_name=cut.title())

			ob = data_to.objects[0]
			ob.data['gem'] = {'cut': cut}

			append_to(ob, obj)
			to_size(ob, obj.dimensions[1])
			type_copy(ob, obj)

			bpy.context.scene.objects.unlink(obj)
			bpy.data.objects.remove(obj)
			sce_link(ob, active=True)


def type_replace():
	context = bpy.context
	tpe = context.scene.jewelcraft.import_gem_type

	data_to = asset_import(mat_name=tpe.replace('_', ' ').title())
	for ob in context.selected_objects:
		if ob.data.get('gem'):
			type_set(ob, tpe, data_to.materials)






def prongs_import():
	for obj in bpy.context.selected_objects:
		if obj.data.get('gem'):
			utility.ob_prop_style_convert(obj)
			cut = obj.data['gem']['cut']
			data_to = asset_import(ob_name=cut.title()+' Prongs', mat_name='Prongs')

			ob = data_to.objects[0]
			append_to(ob, obj)
			to_size(ob, obj.dimensions[1])
			material_assign(ob, 'Prongs', data_to.materials)
			sce_link(ob)


def single_prong_import():
	data_to = asset_import(ob_name='Single Prong', mat_name='Prongs')
	bpy.ops.object.select_all(action='DESELECT')

	ob = data_to.objects[0]
	ob.location = bpy.context.scene.cursor_location
	material_assign(ob, 'Prongs', data_to.materials)
	sce_link(ob, active=True)


def cutter_import(seat_only=False):
	suffix = ''
	if seat_only:
		suffix = ' (Seat only)'

	for obj in bpy.context.selected_objects:
		if obj.data.get('gem'):
			utility.ob_prop_style_convert(obj)
			cut = obj.data['gem']['cut']
			data_to = asset_import(ob_name=cut.title()+' Cutter'+suffix, mat_name='Cutter')

			ob = data_to.objects[0]
			append_to(ob, obj)
			to_dimensions(ob, obj)
			material_assign(ob, 'Cutter', data_to.materials)
			sce_link(ob)


def imitation_import():
	data_to = asset_import(ob_name='Imitation (3 prong)', mat_name='Prongs')
	bpy.ops.object.select_all(action='DESELECT')

	ob = data_to.objects[0]
	ob.location = bpy.context.scene.cursor_location
	material_assign(ob, 'Prongs', data_to.materials)
	sce_link(ob, active=True)


def make_dupliface():
	context = bpy.context
	data = bpy.data

	gem = False
	obs = []
	obs_app = obs.append
	for ob in context.selected_objects:
		if (ob.data and ob.data.get('gem')):
			gem = ob
			obs_app(ob)
		else:
			obs_app(ob)

	if gem:
		ob = gem
		name = ob.name + ' '
	else:
		ob = obs[0]
		name = ''


	verts = [(-0.15,0.15,0), (0.15,0.15,0), (0.15,-0.15,0), (-0.15,-0.15,0)]
	faces = [(3,2,1,0)]


	offset = (ob.dimensions[0]+1, 0, 0)
	for i in range(len(verts)):
		verts[i] = tuple(x+y for x,y in zip(verts[i], offset))


	me = data.meshes.new(name+'Duplifaces')
	me.from_pydata(verts, [], faces)
	me.update()

	df = data.objects.new(name+'Duplifaces', me)
	df.location = ob.location
	df.dupli_type = 'FACES'
	context.scene.objects.link(df)

	for ob in obs:
		ob.parent = df
		apply_transforms(ob)
	bpy.ops.object.origin_clear()


def select_dupli():
	context = bpy.context
	sce = context.scene
	gems_loc = []
	gems_name = []

	bpy.ops.object.select_all(action='DESELECT')

	loc_app = gems_loc.append
	name_app = gems_name.append
	for ob in context.visible_objects:
{'fraction_non_alphanumeric': 0.1538560742842404, 'fraction_numerical': 0.012251741036884188, 'mean_word_length': 4.442105263157894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6465232', 'n_tokens_mistral': 3363, 'n_tokens_neox': 3107, 'n_words': 559}