How to change the "solid name" of stl file without opening it?
Dear all,
I have a stl file which contains two solid patches. This stl file needs to be sent to snappyHexMesh for meshing. The stl file is in ascii format and I need to change the solid patch names. Currently, it is in default name as "solid ascii". How do I change it without opening it? Since, I have huge mesh data, I need it to be automated rather than editing it manually. Any leads will be appreciated. Regards, Sunag R A. |
I suppose you can leave it as is and rename the patches in snappy. Under geometry regions you define individual patches like
Code:
TANK_INLET {name TANK_INLET;} |
Dear AtoHM,
Thank you for the suggestion. If I am correct, this should be the one which you are referencing to? Below is the sample snippet from snappyHexMesh. geometry { mesh.stl { type triSurfaceMesh; name mesh.stl; regions { ascii { name patch1; } ascii { name patch2; } } } }; Since both the solid names are named as "ascii" in stl file, how does the snappyHexMesh recognizes which one is "patch1" and "patch2" correctly.? Regards, Sunag R A. |
That won't work then I guess.
What stl file sizes are we talking here? |
I use sed:
Code:
sed -i '/solid/s/ascii/new_name/g' geom.stl To test the find/search/replace works as intended, you can test it before making the change with the following sed -n '/solid/s/ascii/new_name/p' geom.stl This will print only the lines it will modify without changing the file. The "-n" means only show altered lines and the "p" at the end means print. If it returns what you want, then use edit in place. This is my go to resource for using sed: http://www.pement.org/sed/sed1line.txt |
Idd, I was about to propose using sed or whatever to modify the file then.
|
Dear Chris,
Thank you so much for the find/search/replace option. This is really useful. I have one question related to this. 1. I first checked with sed -n '/solid/s/ascii/new_name/p' geom.stl and it printed four lines (replacing ascii) as expected. a. solid new_name b. endsolid new_name c. solid new_name d. endsolid new_name 2. Then, I used in-place (-i) to replace ascii with, say "patch". This replaced the above 4 "new_name" with patch. But, since there are two solids in the stl file, I want new_name in a,b to be replaced with say "patch" and new_name in c,d with say "patch2".. How can I use this method to replace each "ascii" separately..? Regards, Sunag R A. |
Maybe Chris knows how to get some return from sed once it replaced something and then u can switch what to replace, but I assume it doesn't work.
I traversed, read, edited stl files with Python usually, which is always a thing of seconds for me. In your case I would create a list = ['solid1', 'solid2'] and a counter, then go through the lines with a for loop. On the first occurrance of solid, counter = 0, replace with list[0], add 1 to counter, go further to the second occurrance and replace with list[1]. You can directly use the counter to get the list entry. Even works for any amount of solids, just increase the list size. Some pseudo code / real code: Code:
lines = readSTL |
Dear AtoHM,
Thank you so much for the brief code. Regards, Sunag R A. |
All times are GMT -4. The time now is 04:45. |