Dividing mesh into hexagonal sections

Dividing mesh into hexagonal sections

cmcampbellNDCUJ
Enthusiast Enthusiast
5,810 Views
19 Replies
Message 1 of 20

Dividing mesh into hexagonal sections

cmcampbellNDCUJ
Enthusiast
Enthusiast

Hi, I'm looking for a way to divide a large mesh body into smaller hexagonal sections. Currently I've used a drawing of a hexagonal grid below the ground plane of the mesh body to create a honeycomb pattern of planes that run perpendicular to the ground plane. I then edit the mesh and use the "plane cut" command to cut the hexagonal sections. This is a tedious repetitive process and I would like to find a way to automate it.  

 

Ideally I'd like to create sections from any drawing on the ground plane, but failing that, a script that could create hexagonal sections of w specified size would be a huge boon. Any help would be appreciated!

0 Likes
Accepted solutions (1)
5,811 Views
19 Replies
Replies (19)
Message 2 of 20

kandennti
Mentor
Mentor

Hi @cmcampbellNDCUJ .

 

I don't think the "plane cut" of mesh is provided by the API.
Therefore, I have used text commands to split the mesh.

 

 

All of them are in Japanese, but I used "plane cut" to divide the specified meshes into less than 10000 pieces each, and finally converted them to BRepBody.

https://kantoku.hatenablog.com/entry/2021/04/27/171136 

 

However, it is difficult to split into hexagons.
I can't think of a good way to do it.

 

0 Likes
Message 3 of 20

cmcampbellNDCUJ
Enthusiast
Enthusiast

Thanks @kandennti, this is helpful. I'll try it out. Is there a way to set the angle? I'm thinking that splitting the mesh into equilateral triangles and then reassembling them into hexagons might be workable.

0 Likes
Message 4 of 20

kandennti
Mentor
Mentor

@cmcampbellNDCUJ .

 

I feel like it is possible if we use the construction plane of the angle we want.

It never occurred to me to create and combine triangles.


It will take some time, but I'll give it a try.

0 Likes
Message 5 of 20

kandennti
Mentor
Mentor

I was able to divide the triangular surface.
Here is a video of me trying it out with the attached data.

 

 

I used "Split Faces" for PlaneCut so that I don't lose sight of the MeshBody I am processing.

1.png

 

I'm having trouble processing from here.
I wanted to Combine Face Groups for later processing, but I couldn't figure out how to select the Face Groups.

2.png

 

I have a function to do "All Face Groups" in Separate.

def execMeshExtract(
    target: adsk.fusion.MeshBody):

    app: adsk.core.Application = adsk.core.Application.get()
    ui :adsk.core.UserInterface = app.userInterface
    sels :adsk.core.Selections = ui.activeSelections

    sels.clear()
    sels.add(target)
    app.executeTextCommand(u'Commands.Start ParaMeshExtractCommand')

    app.executeTextCommand(u'Commands.SetString infoType infoTypeAllFaceGroups')
    app.executeTextCommand(u'Commands.SetBool infoPreserveSourceBody 0')

    app.executeTextCommand(u'NuCommands.CommitCmd')

 

I also have a function to do a mesh Combine.

def execMeshCombine(
    target: adsk.fusion.MeshBody,
    tools: list):

    app: adsk.core.Application = adsk.core.Application.get()
    ui :adsk.core.UserInterface = app.userInterface
    sels :adsk.core.Selections = ui.activeSelections

    sels.clear()
    app.executeTextCommand(u'Commands.Start ParaMeshCombineCommand')

    app.executeTextCommand(u'UI.EnableCommandInput infoTargetBody')
    sels.add(target)

    for tool in tools:
        app.executeTextCommand(u'UI.EnableCommandInput infoToolBody')
        sels.add(tool)

    app.executeTextCommand(u'NuCommands.CommitCmd')

 

I haven't figured out how to find the mesh body to combine yet.

Message 6 of 20

cmcampbellNDCUJ
Enthusiast
Enthusiast

Hi @kandennti, Amazing work! Doing the plane cuts is the most time consuming task, so even selecting face groups manually and then combining them saves a lot of time.

 

However I am having difficulty creating closed meshes that I can use to make solid bodies out of each hexagon. Is there a simple way to do this? The plane cut command has an option to make a fill when you 'split bodies' but not when you 'split faces'.

 

Attached is the file I'm working with to illustrate the problem. I've run your script, selected and combined the face groups to make hexagons and then used the 'separate' command to make a separate body for each hexagon. The last step is to make these into closed meshes/solid bodies but this is where I get stuck. 

 

Thanks for all your work on this!

0 Likes
Message 7 of 20

kandennti
Mentor
Mentor

@cmcampbellNDCUJ .

 

I tried it with Split Body, but found that it was more prone to errors than Split Faces, and the script would quit if an error occurred.
I had to find the MeshBody after the split, and since I could not find a way to determine if an error occurred or not, I decided to abandon this method.

 

Instead, I came up with another method.
By creating a hexagonal MeshBody and making it Combine-Intersect with the desired MeshBody, we can get a closed MeshBody.
By using KeepTools, I will not lose sight of the desired MeshBody.

1.png

 

There is no guarantee that this method will get us to our goal, but I feel it has more potential than the first method.

Message 8 of 20

cmcampbellNDCUJ
Enthusiast
Enthusiast

@kandennti,

This looks promising. Is the idea to create a grid of the hexagonal mesh bodies similar to the one you show here and use a script to Combine-Intersect each hexagonal mesh with the desired mesh body? This rather than splitting the faces?

 

 

0 Likes
Message 9 of 20

JeromeBriot
Mentor
Mentor

@kandennti  a écrit :

Instead, I came up with another method.
By creating a hexagonal MeshBody and making it Combine-Intersect with the desired MeshBody, we can get a closed MeshBody.


This is the method I would try first.

 

To avoid intersection failures, you should add more triangles to the cutting part so the mesh densities are approximately the same. See "Tips and Tricks" at the end of this page on the Meshmixer documentation: https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2019/ENU/MSHMXR/files/GUID-355...).

 

Message 10 of 20

kandennti
Mentor
Mentor

@cmcampbellNDCUJ .

 

It is Combine-Intersectde, not Plane Cut.
I'm working on it now. It will not be completed immediately.

0 Likes
Message 11 of 20

kandennti
Mentor
Mentor

Thanks @JeromeBriot for the valuable information.

 

I'm not sure if it can handle the mesh density....

 

I've tried Meshmixer a little when it was unstable before the acquisition, but I haven't used the latest one.

Is it possible for Meshmixer to do automatic operations like macros?

 

I think it's better to use Mesh-specific software to handle Mesh.

0 Likes
Message 12 of 20

JeromeBriot
Mentor
Mentor

@kandennti  a écrit :

I'm not sure if it can handle the mesh density....


See the Remesh tool under MODIFY in the MESH workspace

 


@kandennti  a écrit :

Is it possible for Meshmixer to do automatic operations like macros?


AFAIK, there is an API: mm-api. But I think that you should ask the question in the Meshmixer forum

 


@kandennti  a écrit :

 

I think it's better to use Mesh-specific software to handle Mesh.


I agree but as mentioned on the Meshmixer homepage:

 


NEWS (September 2021): Fusion 360 now contains many of the great features you've grown to love in Meshmixer, with continual growth and improvements to its capabilities in mesh coming soon. While we have no current plans to retire Meshmixer, please note that the tool is no longer in development and will not be supported by Autodesk moving forward. As such, we encourage you to download a trial of Fusion 360 to continue getting the most out of what Autodesk has to offer in mesh capabilities, as well as much, much more.


 

Message 13 of 20

kandennti
Mentor
Mentor

Thank you,@JeromeBriot .

 

You know a lot about Mesh.
I don't think there is any documentation for mm-api, so it looks difficult.

 

I'll try to proceed with Fuison360 for now.

Message 14 of 20

kandennti
Mentor
Mentor

@cmcampbellNDCUJ .

 

It can now be processed as a closed MeshBody.

1.png

Since the code is still in the testing stage, I have attached only the data that I tested.

 

Message 15 of 20

cmcampbellNDCUJ
Enthusiast
Enthusiast

@kandennti this looks great!

0 Likes
Message 16 of 20

kandennti
Mentor
Mentor
Accepted solution

@cmcampbellNDCUJ .

 

I was working on a dialog, but Fusion360 crashed at the end of the process, so I decided to use selectEntity to select the elements.

 

After executing the script, please select or enter the elements in the following order
・'Select MeshBody.'
 The element that can be selected is MeshBody.

 

・'Select the entity that which the hexagon appears.'
 The following elements can be selected.
 ConstructionPlanes,PlanarFaces

 

・'Select the entity that indicates the horizontal direction.'
 The following elements are available for selection
 ConstructionPlanes,PlanarFaces,LinearEdges,SketchLines,ConstructionLines

 

・'Hexagon Size'
 Please use numerical values for input. The unit of length will be the unit set in the document.

 

This is what 'Horizontal Direction' and 'Hexagon Size' mean.

hexagon.png

 

Unfortunately, this is a very slow process. Try a smaller MeshBody with a larger Hexagon Size.

Message 17 of 20

cmcampbellNDCUJ
Enthusiast
Enthusiast

Thank you @kandennti! Even though the script takes time to run it is huge saving compared to the manual process..

Message 18 of 20

yosef.ali.omar
Participant
Participant

@kandennti I am having troubles with the code 

 

this part seems to bring errors 

it tells me syntax error which i dont understand how the def is constructed like this 

def  selectEnt (def selectEnt (    msg: str ,    filtterStr: str    )-> adsk.core.Selection:

    try : try :        sel = _ui.selectEntity (msg, filtterStr)
        return sel
     except :






@kandennti wrote:

Hi @cmcampbellNDCUJ .

 

I don't think the "plane cut" of mesh is provided by the API.
Therefore, I have used text commands to split the mesh.

 

 

All of them are in Japanese, but I used "plane cut" to divide the specified meshes into less than 10000 pieces each, and finally converted them to BRepBody.

https://kantoku.hatenablog.com/entry/2021/04/27/171136 

 

However, it is difficult to split into hexagons.
I can't think of a good way to do it.

 



return None

 

0 Likes
Message 19 of 20

kandennti
Mentor
Mentor
0 Likes
Message 20 of 20

yosef.ali.omar
Participant
Participant

@kandennti 

I am trying to use the function you wrote for Meshbodycutcommand but for some reason its not executing, there is no error or anything here is how i am calling your function in my script, I am using the api to first create a plane then choose a mesh then use the function to cut that mesh using the plane, but its not doing that and there is no error on the console 

 

 
   
       

 

 
        planes     = rootComp.constructionPlanes
        planeInput = planes.createInput()

        planeXY = rootComp.xYConstructionPlane
        offsetValue = adsk.core.ValueInput.createByReal(3.0)
        planeInput.setByOffset(planeXY,offsetValue)

        plane: adsk.fusion.ConstructionPlane = planes.add(planeInput)



         # mesh body
        msg: str = 'Choose a mesh body!'
        selFiltter: str = 'MeshBodies'
        sel: adsk.core.Selection = selectEnt(msg ,selFiltter)
        if not sel: return
        mesh:adsk.fusion.MeshBody = sel.entity
        # 
        

        cutcommand=fin()
        cutcommand._MeshPlaneCutCommand(mesh, plane)
            

 

 

       
0 Likes