Split Mesh Returns Nothing


#1

Hi,

I got a part of a plugin that doest work somehow.
If it doesnt split I return the original but it also says it does not exist. Sometimes. Not always

  • Extrude is a Solid
  • Mesh is to trim Mesh
Private Function CreateTrim (Byval Mesh as geometry.Mesh, Byval Extrude as Guid)

Dim NewSrf As Geometry.Brep = New DocObjects.ObjRef(Extrude).BrepDim ElementObjRef As New DocObjects.ObjRef(Mesh)Dim ElementMesh As Geometry.Mesh = ElementObjRef.MeshDim Splitted As Geometry.Mesh() = ElementMesh.Split(Rhino.Geometry.Mesh.CreateFromBrep(NewSrf))
            
Dim MyMesh As Guid = Mesh
                     
If Splitted IsNot Nothing Then
                                For Each Splits As Geometry.Mesh In Splitted
                                    If Splits IsNot Nothing Then
                                        Dim AddedMesh As Guid = doc.Objects.AddMesh(Splits)
                                        If AddedMesh <> Nothing Then
            
                                                        
Dim maxZMesh As Double = Functions.GetMaxZMesh(AddedMesh)  'Get Boundingbox.Max.Z
                                            Dim maxZDupplicate As Double = Functions.GetMaxZBrep(Extrude) 'Get Boundingbox.max.z
            
If maxZDupplicate >= maxZMesh And DocMesh.Mesh.Vertices.Count > 250 Then
                                                doc.Objects.Delete(MyMesh, True)
                                                MyMesh = AddedMesh
                                            Else
                                                doc.Objects.Delete(AddedMesh, True)
                                            End If
                                        End If
                                    End If
                                Next
            
If MyMesh <> Mesh Then
                                    doc.Objects.Delete(Mesh, True)
                                End If
                            End If
        
        doc.Objects.Delete(Extrude, True)
        Return MyMesh
        End Function

Cant get the box too work so it is a bit messy. Sorry for that.
Anyone knows whats going wrong?


(Menno Deij - van Rijswijk) #2

Use three backticks followed by “vb” on an empty line to start VB code formattting

```vb
type code here
```

End with three backticks to close code formatting.

for example

Private Function CreateTrim(Byval Mesh as Geometry.Mesh, Byval Extrude as Guid)

Very easy :wink:


#3

Oke that worked. Somehow its still a bit messy because I removed and added some enters. But for next time I know what to do.

@menno anny idea what is going wrong here?
Does it not split sometimes? Because it does run throught the

For Each Splits As Geometry.Mesh In Splitted

And it does return a Guid but it says it cant find the Returned Guid somehow.


(Menno Deij - van Rijswijk) #4

I don’t know, your code is a bit messy :smile: but I do see this line

Dim AddedMesh As Guid = doc.Objects.AddMesh(Splits)
If AddedMesh <> Nothing Then

A Guid is a value type, and you should check success like this

Dim AddedMesh As Guid = doc.Objects.AddMesh(Splits)
If AddedMesh <> Guid.Empty Then 'Guid is a value type, Guid.Empty is returned when Add is not successful.

#5

It seems it doesnt always split the mesh. Any Idea why that happens?
They are overlapping

Oke cleaned it up a bit:

Private Function TrimSides(ByVal Dupplicate As Guid, ByVal Mesh As Guid, ByVal doc As RhinoDoc)

            RhinoApp.RunScript("-_SelID " & Dupplicate.ToString & " _ExtrudeSrf _DeleteInput=Yes _Solid=Yes _Cap=_Yes _D w0,0,0 w0,0,-1 100 _enter", False)

            Dim Extrude As Guid = doc.Objects.MostRecentObject.Id
            Dim NewSrf As Geometry.Brep = New DocObjects.ObjRef(Extrude).Brep

            Dim ToTrimMesh As New DocObjects.ObjRef(Mesh)
            Dim ElementMesh As Geometry.Mesh = ToTrimMesh.Mesh
            Dim Splitted As Geometry.Mesh() = ElementMesh.Split(Rhino.Geometry.Mesh.CreateFromBrep(NewSrf))

            Dim MyMesh As Guid = Mesh

            If Splitted IsNot Nothing Then
                For Each Splits As Geometry.Mesh In Splitted
                    If Splits IsNot Nothing Then
                        Dim AddedMesh As Guid = doc.Objects.AddMesh(Splits)
                        If AddedMesh <> Guid.Empty Then
                            Dim DocMesh As New DocObjects.ObjRef(AddedMesh)
                         
                            Dim maxZMesh As Double = Functions.GetMaxZMesh(AddedMesh) 'Get Boundingbox.Max.Z
                            Dim maxZDupplicate As Double = Functions.GetMaxZBrep(Extrude) + 2 'Get Boundingbox.Max.Z

                            If maxZDupplicate >= maxZMesh And DocMesh.Mesh.Vertices.Count > 250 Then
                                doc.Objects.Delete(MyMesh, True)
                                MyMesh = AddedMesh
                            Else
                                doc.Objects.Delete(AddedMesh, True)
                            End If
                        End If
                    End If
                Next
                If MyMesh <> Mesh Then
                    doc.Objects.Delete(Mesh, True)
                End If
            End If
            doc.Objects.Delete(Extrude, True)
            Return MyMesh
End Function

P.S. its trimming in the horizontal direction not the top. Dont know if i need to rotate the screen for this…