This was a demo for a company that produces pcbs. The geometry is generated, projected onto each other and then meshed.
Could use some improvement.
ClearAll()
# Create a very simple model
x = [200, 180, 180, 180,100]
z = [10 , 1, 1, 1, 3]
startHeight = 0
for i in range(len(x)):
blockName = 'B'+str(i)
BlockBody.Create(Point.Create(MM(-x[i]/2),MM(-x[i]/4),MM(startHeight)),Point.Create(MM(x[i]/2),MM(x[i]/4),MM(startHeight+z[i])))
selection = Selection.CreateByNames('Solid')
result = RenameObject.Execute(selection,blockName)
result = ComponentHelper.MoveBodiesToComponent(selection)
selection= Selection.CreateByNames('Component1')
result = RenameObject.Execute(selection,"B1")
startHeight= startHeight+z[i]
options = ShareTopologyOptions()
options.Tolerance = MM(0.2)
result = ShareTopology.FindAndFix(options)
########################################
myBodyDims = []
for body in GetRootPart().GetAllBodies():
x,y,z = body.Shape.GetExtremePoint(Direction.DirX,Direction.DirY,Direction.DirZ)
vol = body.Shape.Volume
myBodyDims.append([body.GetName(), x, y, z, vol])
myBodyDims = sorted(myBodyDims, key = lambda x: int(x[3]))
myFaces = {}
for i in range(len(myBodyDims)):
comp = GetRootPart().GetComponents(myBodyDims[i][0])[0]
bod = comp.GetAllBodies()[0]
for face in bod.Faces:
faceBoxCenter = face.Shape.GetBoundingBox(Matrix.Identity).Center[2]
if faceBoxCenter == myBodyDims[i][3]:
myFaces[myBodyDims[i][0]] = face#.Edges
print('found')
break
# if faceBoxCenter == 0:
# print('bottom found')
# myFaces['Bottom'] = face
## Project across bodies starting top to bottom ##
tempData = []
for a in myBodyDims[::-1]:
print(a[0])
t = str(a[1]) + str(a[2])+str(a[4])
if t not in tempData:
tempData.append(t)
print('project')
options = ProjectToSolidOptions()
options.ProjectThroughSolids = True
selection = Selection.Create(myFaces[a[0]])
target = Selection.Empty()
direction = Selection.Create(GetRootPart())
result = ProjectToSolid.Execute(selection, target, direction, options)
# Create/Edit Mesh
options = CreateMeshOptions()
options.SolidElementShape = ElementShapeType.Hexahedral
options.SurfaceElementShape = ElementShapeType.AllQuad
options.BlockingType = BlockingDecompositionType.Standard
options.ElementSize = MM(1)
options.MeshBasedDefeaturing = MeshBasedDefeaturingType.AutomaticallyDetermined
options.DefeatureSize = MM(0.0423407914095556)
options.ConnectTolerance = 0.02
options.GrowthRate = 1.8
options.MidsideNodes = MidsideNodesType.BasedOnPhysics
options.BlockMaterialOption = BlockMaterialOptionType.Body
#bodySelection = Selection.Create(Body1, Body2, Body3, Body4, Body5, Body6)
bodySelection = Selection.SelectAll()
sweepFaceSelection = Selection.Empty()
result = CreateMesh.Execute(bodySelection, sweepFaceSelection, options)
# EndBlock