# coding: utf-8
#
# Copyright © 2020 MSC.Software Corporation
#  
# Permission to use Scripts
#  
# Permission is granted to MSC.Software customers with valid licenses of the MSC Apex™ software 
# to use script files posted on this page (collectively “Scripts”) solely for customers’ own authorized 
# internal use in conjunction with licensed use of the MSC Apex software.  
# No other use is permitted.  No license to MSC Apex or other software is granted under this Permission.
#  
# SCRIPTS ARE PROVIDED ON AN "AS-IS" BASIS, WITH NO WARRANTIES OF ANY KIND.  USE OF THE SCRIPTS IS AT CUSTOMER'S SOLE RISK.
#  
# IN NO EVENT SHALL MSC.SOFTWARE CORPORATION, ITS AFFILIATES, SUBSIDIARIES, SUPPLIERS, AGENTS, REPRESENTATIVES OR EMPLOYEES BE LIABLE FOR ANY 
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, 
# STRICT LIABILITY, OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION USE OF THE SCRIPTS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
#  
# Customer shall indemnify, defend and hold MSC.Software Corporation, its affiliates, subsidiaries, suppliers, agents, 
# employees or representatives (collectively, “Indemnified Parties”) harmless from and against any third-party claims 
# brought against Indemnified Parties rising out of or in connection with Customer’s use of the Scripts.
#

import apex
from apex.construct import Point3D, Point2D

apex.setScriptUnitSystem(unitSystemName = r'''mm-kg-s-N''')
applicationSettingsGeometry = apex.setting.ApplicationSettingsGeometry()
applicationSettingsGeometry.createGeometryInNewPart = apex.setting.CreateGeometryInNewPart.CurrentPart
applicationSettingsGeometry.geometryTessellationIsWatertight = False
applicationSettingsGeometry.geometryEdgeTesselationTolerance = apex.setting.GeometryTessellationTolerance.Medium
applicationSettingsGeometry.geometryFaceTesselationTolerance = apex.setting.GeometryTessellationTolerance.Medium
apex.setting.setApplicationSettingsGeometry(applicationSettingsGeometry = applicationSettingsGeometry)
model_1 = apex.currentModel()

# 
# Start of recorded operations
# 

def doSketch_1():
    part_1 = model_1.getCurrentPart()
    if part_1 is None:
        part_1 = model_1.createPart()
    sketch_1 = part_1.createSketchOnGlobalPlane(
        name = 'Sketch 1',
        plane = apex.construct.GlobalPlane.XY,
        alignSketchViewWithViewport = True
    )


    rectangle_1 = sketch_1.createRectangle3Point(
        name = "Rectangle 1",
        location = Point2D( -4.000000000000000e+01, 1.000000000000000e+02 ),
        orientationPoint = Point2D( 4.000000000000000e+01, -6.000000000000000e+01 ),
        heightPoint = Point2D( 1.3599999999999997e+02, -1.200000000000000e+01 )
    )

    return sketch_1.completeSketch( fillSketches = True )

newbodies = doSketch_1()

_target = apex.EntityCollection()
part_2 = apex.getPart( pathName = "Model/Part 1" )
surface_1 = part_2.getSurface( name = "Surface 1" )
_ids = '1'
_target.extend( surface_1.getFaces( ids = _ids ) )
result = apex.geometry.pushPull(
    target = _target,
    method = apex.geometry.PushPullMethod.Normal,
    behavior = apex.geometry.PushPullBehavior.Extrude,
    removeInnerLoops = False,
    createBooleanUnion = False,
    distance = 1.4264872670173645e+02,
    direction = [ 0.0, 0.0, 1.000000000000000 ]
)

_target = apex.EntityCollection()
part_2 = apex.getPart( pathName = "Model/Part 1" )
solid_1 = part_2.getSolid( name = "Solid 1" )
_target.append( solid_1 )
_featureMeshTypes = apex.mesh.FeatureMeshTypeVector()
result = apex.mesh.createSolidMesh(
    name = "",
    target = _target,
    meshSize = 10.,
    elementOrder = apex.mesh.ElementOrder.Quadratic,
    refineMeshUsingCurvature = True,
    elementGeometryDeviationRatio = 0.10,
    elementMinEdgeLengthRatio = 0.20,
    autoimprove = True,
    growFaceMeshSize = False,
    faceMeshGrowthRatio = 1.5,
    coarsenMeshInternally = True,
    interiorCoarseningFactor = 10.,
    ignoreBadEdges = True,
    collapseShortElementEdges = False,
    edgeLengthCollapseLimit = 0.5,
    createFeatureMeshes = False,
    featureMeshTypes = _featureMeshTypes,
    createLayeredMesh = False,
    thinSectionThreshold = 20.,
    numLayers = 2,
    projectMidsideNodesToGeometry = True
)

# 
# Macro recording stopped on Jul 20, 2020 at 14:46:04
# 
