# coding: utf-8
# Macro created by MSC Apex Iberian Lynx Feature Pack 2 PRE - Version CLR:668688
# Macro created on Aug 30, 2019 at 15:34:06
# 
# Macro Name = 
# 
# Macro Description = 
# 
# Macro Hot Key = 
# 
# This script creates a "bubble" - a sphere at the selected location.
# This is for defeaturing difficult geometry.
#
# Initialize environment for macro execution
# 

import apex
from apex.construct import Point3D, Point2D
import math

def main(dict={}):

	apex.disableShowOutput()

	apex.setScriptUnitSystem(unitSystemName = r'''mm-t-s-N-deg''')
	model_1 = apex.currentModel()
	
	rad = float(dict["diameter"])/2.0
	
	data = dict["data"]
	
	_selected = apex.selection.getCurrentSelection()

	parts = model_1.getParts()
	partnames = []

	for part in parts:
		partnames.append(part.getName())

	if 'bubble_temp' not in partnames:
		model_1.createPart(name = "bubble_temp")
		
	model_1.setCurrentPart("bubble_temp")

	for data in _selected:
	
		xpos = data.getLocation().getX()
		ypos = data.getLocation().getY()
		zpos = data.getLocation().getZ()
		
		result = apex.geometry.createSphereByLocationOrientation(
			name = 'Sphere',
			description = '',
			radius = rad,
			origin = apex.Coordinate( xpos, ypos, zpos ),
			orientation = apex.construct.createOrientation(alpha=0.0, beta=0.0, gamma=0.0)
			)