Mesh individual elements one at a time with different triangle edge length
Hello
One thing I couldn't find in the manual is how to mesh different objects with different triangle edge lengths?
What I am trying to do is mesh different objects differently because I have some large cubes that don't need a very fine mesh
but I also have some cubes that are very small that need a much smaller mesh size
What I am trying to do is something like this based on a previous post:
-- for loop that will create many cubes here base on index i
temp_cube = project.Geometry:AddCuboid(cf.Point(x_pos_list, y_pos_list, 0), length_, length_, length_)
MeshSettings = project.Mesher.Settings
properties_m = MeshSettings:GetProperties()
properties_m.MeshSizeOption = cf.Enums.MeshSizeOptionEnum.Custom
properties_m.TriangleEdgeLength = SOME_STRING_BASED_ON_CUBE_SIZE -- ex: '0.1' or '0.2', etc
MeshSettings:SetProperties(properties_m)
project.Mesher:Mesh(temp_cube)
-- end of for loop
where the last command project.Mesher:Mesh(temp_cube) only meshes the temp_cube in question and doesn't mesh any other objects
also I have access to the cube number in this loop in case that is useful
Answers
-
Search in the ExampleGuide.pdf for 'local mesh'
0 -
If you prefer using a for loop like shown above to loop over geometry parts (instead of setting local mesh sizes), you can use MeshSelective:
project.Mesher:MeshSelective({temp_cube},{})
0 -
I tried these variations:
-- for loop with index i that creates many cubes here
mesh_length = '0.2'
mesh_length_ = 0.2
if (length<0.25)
then
mesh_length = '0.01'
mesh_length_ = 0.01
end
cube_count = cube_count + 1
temp_cube = project.Geometry:AddCuboid(cf.Point(x_pos_list-length_, y_pos_list, 0), length_, length_, length_)for key,value in pairs(temp_cube.Faces) do -- also tried temp_cuge.Edges
value.LocalMeshSize = mesh_length_
endproject.Mesher:MeshSelective({temp_cube} ,{})
-- for loop with index i that enes here
And a couple variations of the following:
-- for loop with index i that creates many cubes here
mesh_length = '0.2'
mesh_length_ = 0.2
if (length<0.25)
then
mesh_length = '0.01'
mesh_length_ = 0.01
end
cube_count = cube_count + 1
temp_cube = project.Geometry:AddCuboid(cf.Point(x_pos_list-length_, y_pos_list, 0), length_, length_, length_)
MeshSettings = project.Mesher.Settings
properties_m = MeshSettings:GetProperties()
properties_m.MeshSizeOption = cf.Enums.MeshSizeOptionEnum.Custom
properties_m.TriangleEdgeLength = mesh_length
MeshSettings:SetProperties(properties_m)
project.Mesher:MeshSelective({temp_cube} ,{})-- also tried with the previous project.Mesher:Mesh()
-- for loop with index i that enes here
Unfortunatly in all these cases it seems that the smallest cubes don't mesh finely though, the smallest cube in one simulation for example had only 12 triangles dspite it's length being 0.18. My goal is to get it so that each cube will mesh to at least 5 triangles per face
0 -
Please attach an example cfx
0 -
Ok
The measurement attempt cfx file is mosty a blank file used to generate a lot of other files
measurmen attempt 1 lua is the corresponding lua script
the Cad_138_..... stuff.cfx is one of the output example files that gets generated in the results folder
0 -
-
Is there a way to do this via lua script?
I am planning to generate about 1,000 to 10,000 .cfx files in the results folder with random cubes as defined in lua script in the last post
Edit:
Also just as a thought, could the issue be that I'm not using some variation of the command(I'm not sure how to use it):
value.LocalMeshSizeEnabled = true in the for loop from the previous post:
for key,value in pairs(temp_cube.Faces) do -- also tried temp_cuge.Edges
value.LocalMeshSize = mesh_length_
end0 -
Yes, the setting can be applied using a Lua script.
If you are not familiar with the API, please refer to the Example Guide for the Introduction to Application Automation. You can also use macro recording in CADFEKO to record the scripting equivalent of performing steps in the user interface - look for 'Macro Recording' in the User Guide.
For the option shown above, refer to the CADFEKO API documentation. Go to the Face object. It has the properties LocalMeshSize and LocalMeshSizeEnabled.
An alternative could be meshing the cubes one-by-one, which is what you initially set out to do. But then you have to change the mesh size for each cube if you want the cubes to have different mesh sizes! Either set local mesh sizes and mesh the whole model once (using Mesh), or mesh the cubes one-by-one (with MeshSelective) using different mesh sizes for each meshing operation.
In the script you attached above, you are using a custom mesh size of 0.2 (and in the other comment two values: 0.01 and 0.2). It would be fairly easy to vary the mesh size based on the cube length with something like:
mesh_size = tostring(Length_list[cube_index]/2)
Note: You did not iterate over the cubes in the attached script, so maybe follow the option of setting a local mesh size for each cube and meshing the model once.
0 -
the for loop creates cubes one at a time I guess that's what I meant,
Edit:
I have a for loop: for i = 1, 6 do
and buried inside of it is: temp_cube = project.Geometry:AddCuboid(cf.Point(x_pos_list-length_, y_pos_list, 0), length_, length_, length_)
and after creating each cube I want to mesh it individually
You wrote:
'An alternative could be meshing the cubes one-by-one, which is what you initially set out to do. But then you have to change the mesh size for each cube if you want the cubes to have different mesh sizes! Either set local mesh sizes and mesh the whole model once (using Mesh), or mesh the cubes one-by-one (with MeshSelective) using different mesh sizes for each meshing operation.'
That's the issue I've been having, when I run the script in the many configurations I've tried, the script produces cubes but the meshing is not local to the cubes based on size.
I've been trying to either set local mesh sizes and mesh the whole thing at the end, but the smallest cubes still don't have the mesh I wrote into the script (0.01) versus the mesh for the other cubes which is 0.2
this is what I tried when I tested:
for key,value in pairs(temp_cube.Faces) do -- also tried temp_cuge.Edges
value.LocalMeshSize = mesh_length_
endbut it didn't produce cubes with different mesh sizes based on the length of the cubes when I ran it
Also I tried the other method which is:
MeshSettings = project.Mesher.Settings
properties_m = MeshSettings:GetProperties()
properties_m.MeshSizeOption = cf.Enums.MeshSizeOptionEnum.Custom
properties_m.TriangleEdgeLength = mesh_length -- Based on cube size
MeshSettings:SetProperties(properties_m)
project.Mesher:MeshSelective({temp_cube} ,{})But again the cubes don't seem to mesh differently depending on their length
I can't seem to figure out why this is?
Edit 2:
perhaps I'm just missing a simple command like:
project.Geometry.LocalMeshSizeEnabled = true
but I can't figure out if that's the case or how to use this command
0 -
Maybe the code explains it better.
It might not do exactly what you want, but it should illustrate the concept.
0 -
Thank you MvdM it workes!
I ran your script and it worked, the issue with my script looks like was in the line properties_m.TriangleEdgeLength = mesh_length
not in any weird settings that I thought the issue might be in
now I instead set the triangle edge length to = length_/5 it generates a fine mesh for all of the cubes!
0