TAGGED: geometry, scripting, spaceclaim
-
-
June 12, 2023 at 1:08 pm
ramiromena
SubscriberDear Ansys Learning Forum Community,
I am trying to select a specific face in a geometry. The easiest way to do this task is by knowing in advance the index of the face of interest. However, this option lacks of scalability if my geometry is modified or generated in a different order. This solution is referred as Option 1.
So, other option is to use the FilterByArea method. This works fine as long as your faces have a unique area, otherwise, you will select multiple faces instead of only one. This solution is referred as Option 2.
Then, by searching the available options, there is the FilterByBoundingBox method where you can select a face that intersects with a previously defined box. This method looks as the most generic so that you can control the way a face is selected. However, due to the lack of documentation in SpaceClaim or the absence of a similar example, I am not able to use this method properly. Maybe is due to an error in the syntax or in my understanding of the method. Please, could you help me? This solution is referred as Option 3.
Attached you will find a minimal working example (MWE) with the implementation of Option 1, 2 and 3. This last one is currently not working as is the one I am interested the most. Feel free to add/modify its content.
However, if you know a better solution to select a specific face (i.e based on its normal or another feature, feel free to share your valuable know-how)
As always, thank you for your help.
Best regards,
Ramiro
#####
"""
Minimal Working Example MWE
Author: Ramiro MENA ANDRADE
Date: 2023-06-12
Script to generate a Cube of dimensions Cube_X, Cube_Y and Cube_Z
and select faces based on three different methods:
- Option1: When the index of the face is known in advance (not useful to fully automatize a code)
- Option2: By using FilterByArea method (not useful if more than one face has the same area)
- Option3: By using FilterByBoundingBox method (could be useful, but I do not know how to write the proper syntax)
"""
# Python Script, API Version = V19
#*************************************
# Part 1: Geometry definition (dimensions in mm)
#*************************************
Cube_X= 10
Cube_Y= 20
Cube_Z= 5
pointA = [0,0]
pointB = [Cube_X,0]
pointC = [Cube_X,Cube_Y]
tol = 0.01 #define a tolerance
area = Cube_X*Cube_Y #calculate the area
#%%
#*********************************
#Part2: Geometry generation
#*********************************
sectionPlane = Plane.PlaneXY
result = ViewHelper.SetSketchPlane(sectionPlane, None)
# EndBlock
# Set New Sketch
result = SketchHelper.StartConstraintSketching()
# EndBlock
# Sketch Rectangle
point1 = Point2D.Create(MM(pointA[0]),MM(pointA[1]))
point2 = Point2D.Create(MM(pointB[0]),MM(pointB[1]))
point3 = Point2D.Create(MM(pointC[0]),MM(pointC[1]))
result = SketchRectangle.Create(point1, point2, point3)
# Solidify Sketch
mode = InteractionMode.Solid
result = ViewHelper.SetViewMode(mode, None)
# EndBlock
# Extrude 1 Face
selection = FaceSelection.Create(GetRootPart().Bodies[0].Faces[:])
options = ExtrudeFaceOptions()
options.ExtrudeType = ExtrudeType.Add
result = ExtrudeFaces.Execute(selection, MM(Cube_Z), options)
# EndBlock
#%%
#************************************************
#Part 3: Selection of faces by different methods
#*************************************************
# OPTION 1: Create Named Selection Group (Top)
# PROBLEM: YOU NEED TO KNOW IN ADVANCE THE INDEX OF THE FACE
primarySelection = FaceSelection.Create(GetRootPart().Bodies[0].Faces[0])
secondarySelection = Selection.Empty()
result = NamedSelection.Create(primarySelection, secondarySelection)
result = NamedSelection.Rename("Group1", "Option1")
# EndBlock
#OPTION 2: Create a named selection by using FilterByArea
#PROBLEM: FOR THIS CASE, MULTIPLE FACES CAN HAVE THE SAME AREA, SO YOU CAN NOT SELECT A SPECIFIC FACE
comp = Selection.Create(GetRootPart())
faces = comp.ConvertToFaces().FilterByArea(MM2(area-tol),MM2(area+tol))
faces.CreateAGroup('Option2')
#OPTION 3: Create a named selection by using FilterByBoundingBox Method
#PROBLEM: I DO NOT KNOW THE PROPER SYNTAX FOR USING THIS METHOD CORRECTLY
#Create Points
min_point = Point.Create(MM(pointA[0]), MM(pointA[1]), MM(0))
max_point = Point.Create(MM(pointC[0]), MM(pointC[1]), MM(0))
#Create a Box
mbox = Box.Create(min_point, max_point)
#Apply the Filter to a face (fface means filtered face)
fface = comp.ConvertToFaces().FilterByBoundingBox(mbox)
fface.CreateAGroup('Option3') -
June 14, 2023 at 11:49 am
Aniket
Ansys EmployeeHi Ramiro,
First of all very well-written question! Kudos for that! There was an issue in older APIs of FilterByBoundingBox which is fixed in 2023 R1.
so something, as follows, would work in 2023R1:
from SpaceClaim.Api.V23 import *
PartSel = Selection.Create(GetRootPart())
faces = PartSel.ConvertToFaces()
BoundingBox = Box.Create(MM(-30),MM(-30),MM(-30),MM(30),MM(30),MM(30))
facesInBoundingBox = faces.FilterByBoundingBox(BoundingBox)You may want to upgrade to 2023R1.
If that's not possible, possibly you can loop through faces and check their centroid such as:
GetRootPart().Bodies[0].Faces[0].EvalMid().Point
-Aniket
-
June 14, 2023 at 12:24 pm
ramiromena
SubscriberHi Aniket.
Thank you for your positive feedback and for your quick reply. Currently I do not have the 2023R1 version, but I am glad to know that there is a solution in the future version. In the meantime, the hint of using the centroid is super useful.
I will proceed to update my script and kudos for you too :).
Cheers,
Ramiro
-
- You must be logged in to reply to this topic.

Boost Ansys Fluent Simulations with AWS
Computational Fluid Dynamics (CFD) helps engineers design products in which the flow of fluid components is a significant challenge. These different use cases often require large complex models to solve on a traditional workstation. Click here to join this event to learn how to leverage Ansys Fluids on the cloud, thanks to Ansys Gateway powered by AWS.

Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.

Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
- How to work with STL file?
- Rotate tool in ANSYS Design Modeler
- section plane
- Using Symmetry in DesignModeler and Expanding the Results
- ANSYS FLUENT – Operation would result in non manifold bodies
- drawing a geometry by importing a table of points
- material properties
- Coordinates orientation
- “contact pair has no element in it.” how to resolve this problem
- Parameters not imported into Workbench 18.2 from Solidworks/Inventor
-
7626
-
4442
-
2953
-
1427
-
1322
© 2023 Copyright ANSYS, Inc. All rights reserved.