-
-
February 10, 2023 at 5:24 pm
satri
SubscriberSuppose I have a model like this
Whose edge IDs are 5,6,7
suppose i want to remove the region inside edge 6 and edge 7.
If i use the GUI i would go to Design->Split Body and select edge 6 and click on the region marked as 'X' in the above figure.
Suppose i want to do that with python script how can i do this?
Note:
I tried to generate the code inside space claim and i got this
selection = BodySelection.Create(GetRootPart().Bodies[1])
result = Combine.RemoveRegions(selection)based on the code what i understand is it selected body 1 and deleted the selection.
suppose i want to just run the code and delete the region of circle 7 i don't think this will work because i don't know the following information
which edge to pick and which region of the edge do i pick to delete. So i don't know how to achieve this programmatically using the API. Please let me know how to achieve this?
-
February 15, 2023 at 2:13 am
mjmiddle
Ansys EmployeeI see you are using the Combine tool and seleting a body so edge selection is not involved. The RemoveRegions() method is done as the second part of a Combine operation that intersected some bodies. The is the same as just deleting a body after the intersection. A big challenge with scripting, which determines ultimately whether a process can be scripted or not is whether selections can be done without a graphical interface.
One way to handle this is to place edge/bodies/faces/vertices into named selections before the script runs, and the script will get entities in the named selections. Another way, which can sometimes get the desired entities in simple models, is to get based on a min/max XYZ value. You can get a bounding box or centroid of faces/edges/bodies and check XYZ values and only use those above or below a value you want. For vertices, you can get exact XYZ locations to check against min/max target values. You already know about the index method for selections, which is a type of selection by ID.
Also, to make scripting robust, which guarantees the right selection after operations, is to get the return value of an operation and then contnue to operate on it. For the Combine.RemoveRegions() operation that you showed, this always happens after a Combine.Intersect(). So get the result bodies like this:
targets = BodySelection.Create(GetRootPart().Bodies[0])
tools = BodySelection.Create(GetRootPart().Bodies[2])
options = MakeSolidsOptions()
result = Combine.Intersect(targets, tools, options)
newBodies = result.CreatedBodies
selection = BodySelection.Create(newBodies)
result = Combine.RemoveRegions(selection)Of course, you will have to get the original "targets" and "tools" bodies by some other method, such as index, named selection, max/min XYZ, or they may also be the result of a previous operation.
-
February 15, 2023 at 2:21 am
mjmiddle
Ansys EmployeeAnother method, when the result on an operation doesn't return anything useful, is to get a list of all bodies before an operation, then get a list after an operation, and loop through items comparing. Any items not in the first list are your new bodies. You can build a list and compare types directly. You don't need IDs. So you can directly compare DesignBody types, or DesignFaces, etc...
-
February 15, 2023 at 5:19 pm
satri
SubscriberI like the idea of using the named selection but i don't know how to execute that
I don't think this will work directly because i have only one body
targets = BodySelection.Create(GetRootPart().Bodies[0])
tools = BodySelection.Create(GetRootPart().Bodies[2])for this to work i believe i need to have two bodies.
I have a script that can create named selections for the edges.
so lets say in the above example itself i create a named selection called group5, group6 and group7
how would i go about this?
I have only one body.
I think this will be a clean process
- i will split the body based on the named selection of the edge
- Using the two bodies created bodies use the above commands you mentioned to remove the second body
(targets = BodySelection.Create(GetRootPart().Bodies[0])
tools = BodySelection.Create(GetRootPart().Bodies[2])
options = MakeSolidsOptions()
result = Combine.Intersect(targets, tools, options)
newBodies = result.CreatedBodies
selection = BodySelection.Create(newBodies)
result = Combine.RemoveRegions(selection)do you think this workflow will enable me to achieve what I am trying to do?
if this will work then the first question that i have is what commands do i use to split the body based on the named selection of the edges that will enable me to create two bodies. please let me know.
-
- 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
- Using Symmetry in DesignModeler and Expanding the Results
- section plane
- material properties
- ANSYS FLUENT – Operation would result in non manifold bodies
- drawing a geometry by importing a table of points
- Geometry scaling
- Parameters not imported into Workbench 18.2 from Solidworks/Inventor
- Coordinates orientation
-
3694
-
2558
-
1765
-
1234
-
590
© 2023 Copyright ANSYS, Inc. All rights reserved.