https://linen.dev logo
Join Discord
Powered by
# freecad-salome-etc
  • m

    muehhlllerr

    07/09/2025, 8:09 AM
    thanks for your help
  • o

    otaolafr

    07/09/2025, 8:09 AM
    okey, now is readable, what you want to do exactly?
  • m

    muehhlllerr

    07/09/2025, 8:12 AM
    I have a main Geometry I export from CAD and I wana create a stl for snappy that has individual regions as solids. So I export these subregions from cad as well to use them to group the faces in the meshing module of salome.
  • m

    muehhlllerr

    07/09/2025, 8:12 AM
    This now works with this code snipped it can be used like
  • m

    muehhlllerr

    07/09/2025, 8:12 AM
    Copy code
    blades = geompy.CreateGroup(mainGeometry, geompy.ShapeType["FACE"])
    loopAndGroup(blades,mainGeometry,subGeometry)
  • m

    muehhlllerr

    07/09/2025, 8:13 AM
    where within the loopAndGroup call the subGeometry is exploded into its faces and then for each face the coinciding sections are added
  • o

    otaolafr

    07/09/2025, 8:13 AM
    so, you want: create a volume groups ie., regions and the surface groups ie., patches
  • m

    muehhlllerr

    07/09/2025, 8:14 AM
    yes exactly
  • m

    muehhlllerr

    07/09/2025, 8:14 AM
    that now all works just the creation of the volume groups made huge problems
  • o

    otaolafr

    07/09/2025, 8:14 AM
    and how you want to identify the volume groups and the surface?
  • o

    otaolafr

    07/09/2025, 8:15 AM
    with a coordinate (like if the point is inside the region is => region1 etc? with a external file of a surface?
  • m

    muehhlllerr

    07/09/2025, 8:17 AM
    with an external file, I have a .brep file, which contains just the subsurface of the main geometry which I wana have as a patch later
  • o

    otaolafr

    07/09/2025, 8:18 AM
    so to be sure: you have: 1. brep file with region1 and 2 2. several brep files for each patch either of region1 or region2
  • o

    otaolafr

    07/09/2025, 8:20 AM
    so: fluidAndSolid.brep patch0Fluid.brep, patch1Fluid.brep, ...., patch0Solid.brep, patch1Solid.brep, .... etc (i used fluid /solid as the region names)
  • m

    muehhlllerr

    07/09/2025, 8:28 AM
    yeah thats it and the goal is to in the end have a surface mesh in salome with mesh regions according to the patches, so I can individually export them.
  • o

    otaolafr

    07/09/2025, 8:29 AM
    okey, last question, is it really complex the geometry?
  • m

    muehhlllerr

    07/09/2025, 8:45 AM
    One of them is yeah
  • m

    muehhlllerr

    07/09/2025, 8:45 AM
    Or lets say one of the patches is
  • m

    muehhlllerr

    07/09/2025, 8:45 AM
    And thats also the one which was problematic which I guess makes sense
  • o

    otaolafr

    07/09/2025, 8:46 AM
    give me a sec
  • o

    otaolafr

    07/09/2025, 8:59 AM
    Copy code
    import os
    pathOfFiles='/home/franco/Downloads/testSalome'
    tolerance=1e-07
    if not os.path.exists(pathOfFiles):
        print('error pathOfFiles('+pathOfFiles+') does not exist. Stopping script')
        stop
    regionNames = [name for name in os.listdir(pathOfFiles) if os.path.isdir(os.path.join(pathOfFiles, name))]
    patchNames=[[] for _ in regionNames]
    patchObjects=[[] for _ in regionNames]
    for nRegion,regionName in enumerate(regionNames):
        patchNames[nRegion] = [f for f in os.listdir(os.path.join(pathOfFiles, regionName)) if f.endswith('.brep') and os.path.isfile(os.path.join(os.path.join(pathOfFiles, regionName), f))]
        patchObjects[nRegion]=[geompy.ImportBREP(os.path.join(pathOfFiles, regionName,patchName)) for patchName in patchNames[nRegion]]
    
    
    regions=[geompy.MakeSolid([geompy.MakeShell(patchObjectsOfRegion)]) for patchObjectsOfRegion in patchObjects]
    completeGeometry = geompy.MakeGlueFaces(geompy.MakeCompound(regions), tolerance)
    
    groups=[[geompy.CreateGroup(completeGeometry, geompy.ShapeType['FACE']) for patch in listOfPatchs] for listOfPatchs in patchObjects]
    groupsObjects=[[geompy.GetInPlace(completeGeometry, patch, True) for patch in listOfPatchs] for listOfPatchs in patchObjects]
    [[geompy.UnionList(group , [groupsObjects[nRegion][nGroup]] )   for nGroup,group in enumerate(groups[nRegion])] for nRegion in range(len(regionNames))]
    
    
    groupsVolume=[geompy.CreateGroup(completeGeometry, geompy.ShapeType['SOLID']) for region in regionNames]
    groupsVolumeObjects=[geompy.GetInPlace(completeGeometry, region, True) for region in regions]
    [geompy.UnionList(groupsVolume[nRegion] , [groupsVolumeObjects[nRegion]]) for nRegion in range(len(regionNames))]
  • o

    otaolafr

    07/09/2025, 8:59 AM
    and if you want to publish them:
    Copy code
    geompy.addToStudy(completeGeometry,'completeGeometry')
    [[geompy.addToStudyInFather( completeGeometry, group, patchNames[nRegion][nGroup].replace('.brep',''))   for nGroup,group in enumerate(groups[nRegion])] for nRegion in range(len(regionNames))]
    [geompy.addToStudyInFather( completeGeometry, groupsVolume[nRegion], regionName)   for nRegion,regionName in enumerate(regionNames)]
  • o

    otaolafr

    07/09/2025, 8:59 AM
    so the structure of the pathFiles should look like this:
  • o

    otaolafr

    07/09/2025, 9:00 AM
    Copy code
    .
    ├── multiRegionBrep.py
    ├── region0
    │   ├── Face_10.brep
    │   ├── Face_1.brep
    │   ├── Face_3.brep
    │   ├── Face_5.brep
    │   ├── Face_6.brep
    │   └── Face_8.brep
    └── region1
        ├── Face_11.brep
        ├── Face_2.brep
        ├── Face_4.brep
        ├── Face_6.brep
        ├── Face_7.brep
        └── Face_9.brep
    i did only the geometry py. need to go back to work, from what i did you should have enought to continue alone
  • o

    otaolafr

    07/09/2025, 9:01 AM
    keep in mind that when you export the stls, the Face_6 (face in common) you will get the wrong normal for one of the regions so you need to flip them before exporting the second region
  • o

    otaolafr

    07/09/2025, 9:03 AM
    so you dont need to import extra things.
  • o

    otaolafr

    07/09/2025, 9:04 AM
    the approach that i did is the 'correct' one. creating the solid regions in salome. if it is too complex it might fail. if that is the case, the script can be adapted to have imported the complete solid, but would not recommend this.
  • o

    otaolafr

    07/09/2025, 9:04 AM
    also face_6 is in the two regions
  • m

    muehhlllerr

    07/09/2025, 9:09 AM
    oh perfect thank you that looks really good. Ill think ill get it running based on that Ill report back ❤️
  • o

    otaolafr

    07/09/2025, 9:09 AM
    (y)