Duplicate Object

Hi,

I’m duplicating an object with:

Public Function Transform_Duplicate(ByVal GAs Guid) As Guid
        Dim Obj As New Rhino.DocObjects.ObjRef(G)
        Dim Dup As Rhino.Geometry.GeometryBase = Obj.Brep.Duplicate()
        Dim Att As DocObjects.ObjectAttributes = Obj.Object.Attributes
        Dim DupGuid As Guid = RhinoDoc.ActiveDoc.Objects.AddBrep(Dup, Att)

        Return DupGuid
End Function

but if fails. It worked before. Why is it not working anymore?
Any Ideas?

Try to see if your geometry is valid.

Dim err as String
If not Dup.IsValidWithLog(out err)
print err
End If

(ok obviously not valid VB code, but I hope you get the idea).

I first split the brep and replace the existing object. After this. The object cant be “Touched” anymore…

This is the Error:

Anny Ideas?

This is normally cause for concern. The split did not give valid geometry. Maybe it can be solved by calling SetTrimFlags. See http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Geometry_Brep_SetTrimIsoFlags.htm

Oke changed a the code a bit but still nothing. Am I using the SetTrimIsoFlags right?

    Public Function Transform_Duplicate(ByVal G As Guid) As Guid
        Dim Obj As New Rhino.DocObjects.ObjRef(G)
        Dim Dup As Rhino.Geometry.GeometryBase = Obj.Brep.Duplicate()
        Dim Att As DocObjects.ObjectAttributes = Obj.Object.Attributes
        Dim DupGuid As Guid = RhinoDoc.ActiveDoc.Objects.AddBrep(Dup, Att)

        Dim err As String = Nothing
        If Not Dup.IsValidWithLog(err) Then
            MsgBox(err)
            Obj.Brep.SetTrimIsoFlags()
            Dim Dup2 As Rhino.Geometry.GeometryBase = Obj.Brep.Duplicate()
            DupGuid = RhinoDoc.ActiveDoc.Objects.AddBrep(Dup2, Att)

            If Not Dup2.IsValidWithLog(err) Then
                MsgBox(err)
            End If
        End If

        Return DupGuid
    End Function

second error is:

So nothing changed…

P.S. I first edit the brep in a previous command. After this command I cant edit the object anymore.

 Dim GrPatroonObj As Geometry.BrepFace = New DocObjects.ObjRef(MyObjectGuid).Surface
Dim FaceList As New List(Of Geometry.Brep)
Dim Splitted As Geometry.Brep = GrPatroonObj.Split(CrvList.ToArray, doc.ModelAbsoluteTolerance)
If Splitted IsNot Nothing Then
                For y = 0 To Splitted.Faces.Count - 1
                    FaceList.Add(Splitted.Faces(y).DuplicateFace(False))
                Next
End If

Dim MyNewSrf As Geometry.Brep = Nothing
For Each itm As Geometry.Brep In FaceList
                If MyNewSrf Is Nothing Then
                    MyNewSrf = itm
                Else
                    If MyNewSrf.Trims.Count < itm.Trims.Count Then
                        If Functions.GetMinXBrep(GrPatroonOrSole) >= (Functions.GetMinXMyBrep(itm) - 1) Then
                            MyNewSrf = itm
                        End If
                    End If
End If
Next

doc.Objects.Replace(GrPatroonOrSole, MyNewSrf)

After this I cant edit the obj anymore.

Changed it to:

Dim Geometry As Geometry.BrepFace = New DocObjects.ObjRef(Sole).Brep.Faces(0)
Dim SoleCopyGuid As Guid = doc.Objects.AddBrep(Geometry.ToBrep)

Then it works. Why?

At this level, you shouldn’t have to deal with trim flags. So I am assuming this is an issue at our end.

How can I repeat the splitting error here?

I’ll send you a PM with a file and code.