Ansys Learning Forum › Forums › Discuss Simulation › 3D Design › SpaceClaim Script: Selection by FilterByBoundingBox › Reply To: SpaceClaim Script: Selection by FilterByBoundingBox
September 28, 2023 at 9:57 am
christian.scheffler
Subscriber
Hi Aniket,
unfortunately the FilterByBoundingBox method is not working for me in V23. But I agree with you, the x, y, z order is correct for your example above.
public static Box Create(
double minX,
double minY,
double minZ,
double maxX,
double maxY,
double maxZ
)
Please find a MWE below.
Probelm: In my case this does not limit the total set to the subset of faces.
Best regards
Christian
###
# Python Script, API Version = V23
#*************************************
# Geometry definition (dimensions in mm)
#*************************************
width= 2
length= 100
number_of_arms = 3
#*********************************
#Part2: Geometry generation
#*********************************
# 3 Arms
# Set Sketch Plane
sectionPlane = Plane.PlaneXY
result = ViewHelper.SetSketchPlane(sectionPlane, None)
# EndBlock
# Sketch Rectangle
point1 = Point2D.Create(MM(width/2),MM(0))
point2 = Point2D.Create(MM(-width/2),MM(0))
point3 = Point2D.Create(MM(-width/2),MM(length))
result = SketchRectangle.Create(point1, point2, point3)
# EndBlock
# Solidify Sketch
mode = InteractionMode.Solid
result = ViewHelper.SetViewMode(mode, Info4)
# EndBlock
# Rotieren über Z-Griff
selection = BodySelection.Create(GetRootPart().Bodies[:])
anchor = CoordinateSystem1
axis = Move.GetAxis(anchor)
options = MoveOptions()
options.CreatePatterns = True
angle=360/number_of_arms
result = Move.Rotate(selection, axis, DEG(angle), options, Info13)
# EndBlock
# Circle
# Set Sketch Plane
sectionPlane = Plane.PlaneXY
result = ViewHelper.SetSketchPlane(sectionPlane, Info6)
# EndBlock
# Sketch Circle
origin = Point2D.Create(0,0)
result = SketchCircle.Create(origin, MM(10))
# EndBlock
# Solidify Sketch
mode = InteractionMode.Solid
result = ViewHelper.SetViewMode(mode, Info7)
# EndBlock
# Copy Elements out of Components (Pattern)
selection = BodySelection.Create(GetRootPart().Components[0].Components[0].Content.Bodies[0])
result = Copy.Execute(selection)
selection = BodySelection.Create(GetRootPart().Components[0].Components[1].Content.Bodies[0])
result = Copy.Execute(selection)
selection = BodySelection.Create(GetRootPart().Components[0].Components[2].Content.Bodies[0])
result = Copy.Execute(selection)
# EndBlock
# Delete Objects (Components)
selection = ComponentSelection.Create(GetRootPart().Components[:])
result = Delete.Execute(selection)
# EndBlock
# Rename
GetRootPart().Bodies[0].SetName("Circle")
GetRootPart().Bodies[1].SetName("Arm1")
GetRootPart().Bodies[2].SetName("Arm2")
GetRootPart().Bodies[3].SetName("Arm3")
# EndBlock
# Project to solid
selection = FaceSelection.Create(GetRootPart().Bodies[0].Faces[:])
target = FaceSelection.Create(GetRootPart().Bodies[1].Faces[:])
direction = Selection.Create(GetRootPart())
result = ProjectToSolid.Execute(selection, target, direction)
# EndBlock
# Project to solid
selection = FaceSelection.Create(GetRootPart().Bodies[0].Faces[:])
target = FaceSelection.Create(GetRootPart().Bodies[2].Faces[:])
direction = Selection.Create(GetRootPart())
result = ProjectToSolid.Execute(selection, target, direction)
# EndBlock
# Project to solid
selection = FaceSelection.Create(GetRootPart().Bodies[0].Faces[:])
target = FaceSelection.Create(GetRootPart().Bodies[3].Faces[:])
direction = Selection.Create(GetRootPart())
result = ProjectToSolid.Execute(selection, target, direction)
# EndBlock
#************************************************
#Part 3: Selection of faces by different methods
#*************************************************
PartSel1 = Selection.Create(GetRootPart())
Faces1 = PartSel1.ConvertToFaces()
PartSel2 = Selection.Create(GetRootPart().Bodies[0])
Faces2 = PartSel2.ConvertToFaces()
Faces = Selection.Difference(Faces1,Faces2)
BoundingBox = Box.Create(MM(-20),MM(-20),MM(-2),MM(20),MM(20),MM(2))
FacesInBoundingBox = Faces.FilterByBoundingBox(BoundingBox)
# FacesInBoundingBox contains all the faces of the 3 arms.
# Expected was a selection of the 3 faces underneath the circle ONLY
result = Delete.Execute(FacesInBoundingBox)