Accessing list of bodies, faces, edges


I currently have a workflow using the GUI in order to mesh some imported CAD model. My goal is to translate that workflow into a (possibly python since it is a language I am more comfortable with) script that is generic enough so it can handle roughly similar CAD models (by that I mean that some bodies in the CAD model will have the same names, some planes will be identical, etc. but there will be some differences).
So far, I have been able to record a full workflow for a specific CAD model, so this gives me an idea of how my script should be structured. However, I have some difficulties in making it more generic.
For example. Let's say that my imported file contained 6 bodies but I want to keep only 5 (for which I know the name).
I am looking to do something like this:
* obtain a list of all bodies in my model (no idea how to do this / which command to use)
* make some search in their name (I know how to do this in python)
* decide which one to delete (I know how to do this in python / simlab)
Another thing that I would like to do is how to access the selection list in python.
With a concrete example, I am:
* Using Inspect / Edges / by plane to select some edges (I know the command for this)
* Apply some mesh controls on those edges (I know the command for this as well)
My problem is that in a generic script you want to know which are the edges ids to pass to the second command (because MeshControl needs it).
One way that might work is to actually create a group when you do the inspect and use getEntityFromGroup to pass the result. But this seems quite complicated.
Any comments are more than welcome.
Answers
-
Altair Forum User said:
For example. Let's say that my imported file contained 6 bodies but I want to keep only 5 (for which I know the name).
I am looking to do something like this:
* obtain a list of all bodies in my model (no idea how to do this / which command to use)
* make some search in their name (I know how to do this in python)
* decide which one to delete (I know how to do this in python / simlab)
Hi Louis,
Apologies for the delay in replying back to this mail.
Currently there is a option in python to get the body ID's and not body names. That should be fixed I will report it to dev team.
In case you know the body name which has to be deleted ,you can Delete that body that would in turn be recorded in your script.
In case the body which has to be deleted its Body Name changes from model to model. You can parameterize the Body Name, so that every time you have a new Body name you can update your Parameter file that way your script would become generic.
Please let me know in case you have any doubts.
Thanks
Siddharth
0 -
Altair Forum User said:
Another thing that I would like to do is how to access the selection list in python.
With a concrete example, I am:
* Using Inspect / Edges / by plane to select some edges (I know the command for this)
* Apply some mesh controls on those edges (I know the command for this as well)
My problem is that in a generic script you want to know which are the edges ids to pass to the second command (because MeshControl needs it).
One way that might work is to actually create a group when you do the inspect and use getEntityFromGroup to pass the result. But this seems quite complicated.
Louis,
There are two methods to do this.
1. You can give the edge group as input to mesh control while you are recording the script. That way your script becomes generic. You would only have to create a Edge group which would be later taken as input for your mesh control.
2. You can create Group based mesh specification file, So every time you import a mesh spec it will look for that edge group and in turn the mesh control would be assigned to the entities present in that group.
I have attached videos for reference, hope this help.
Thanks
Siddharth
0 -
Altair Forum User said:
Currently there is a option in python to get the body ID's and not body names. That should be fixed I will report it to dev team.
Could you write that command name (the one for the ids) in any case? Because, I cannot find it in the documentation.
0 -
Altair Forum User said:
1. You can give the edge group as input to mesh control while you are recording the script. That way your script becomes generic. You would only have to create a Edge group which would be later taken as input for your mesh control.
I did that and it is correctly working for mesh control. However, the same 'trick' cannot be used for other commands. For example:
- 2D Create / Mesh
- Fill / Face
- 2D Create / Re-mesh
Those do not accept a group of faces as input.
Also, I cannot access the videos. I get the following error:
The page you are trying to access is not available for your account.
Error code: 2C171/1
0 -
Altair Forum User said:
Could you write that command name (the one for the ids) in any case? Because, I cannot find it in the documentation.
Hi Louis,
Currently we don't have a documentation for Python we are working on it.
Your command would be :
open the Python terminal in SimLab.
from hwx import simlab
simlab.getSelectedEntities('Body')
//press enter
Out[2]: (217, 163, 109, 55, 1)
//there are totally five bodies their id's are displayed as shown.
0 -
Altair Forum User said:
I did that and it is correctly working for mesh control. However, the same 'trick' cannot be used for other commands. For example:
- 2D Create / Mesh
- Fill / Face
- 2D Create / Re-mesh
Those do not accept a group of faces as input.
Did you try the utility function , Get entity from group . This will definitely take Face group as input to carryout the operations.
In help you have a sample function with sample script on how to use the Get entity from group function.
Thanks
Siddharth
0 -
Altair Forum User said:simlab.getSelectedEntities('Body')
This doesn't exist in Simlab 2017.2. Maybe in a dev version.
0 -
Oops .I am sorry yes you are right its not available in SimLab 2017.2
My apologies. Its in the development version.Thanks
Siddharth
0 -
Altair Forum User said:
Did you try the utility function , Get entity from group . This will definitely take Face group as input to carryout the operations.
In help you have a sample function with sample script on how to use the Get entity from group function.
Thanks a lot for pointing the sample script.
I knew about getEntityFromGroup but I could not really get how to use the result in the next function.
I saw that getEntityFromGroup was returning a tuple but I could not really understand how to strip it and inject it in the next command.
Generally speaking, it is really ugly though to have to concatenate it in a string that will be processed.
It would be better if single python commands were created instead of using a generic execute that can handle only one string.
Thus, you could send separate arguments that would be much easier to script.
Is there any plan to improve the python scripting support (I know it is quite recent)?
0 -
Currently this is the current behavior I need to check internally on why this is done .
We are developing Python interface at the same time also taking user feedback to improve it. Your feedback is always valuable to us
I will inform this to my development team and see if this part can be improved further.
Thanks
Siddharth
0 -
Concerning the first point that I wrote, it is now possible to use the following command:
OutputList = simlab.getChildrenInAssembly('model_name', 'model_name', 'ALLBODIES')
And this will return the names of all bodies in your model. I hope this can be useful for someone else as well.
0