Hello, I try to use the CreateFromBox method and I cant get breps by doing that. This is part my code:
Dim bbox = brep.GetBoundingBox(True)
Dim corner = bbox.GetCorners()
For i = dt To corner(4).Z Step dt
For j = 0 To 3 Step 1
cor(j) = corner(j).Z + dt1
Dim bb As New Rhino.Geometry.BoundingBox(corner(0).X, corner(0).Y, corner(0).Z, corner(j).X, corner(j).Y, cor(j))
Dim b As New Geometry.Box(bb)
Dim bbrep = Geometry.Brep.CreateFromBox(b)
RhinoApp.WriteLine(bbrep.ToString)
Dim inters As Brep() = Brep.CreateBooleanIntersection(brep, bbrep, 1)
Next
dt1 = dt1 + dt
Next
I get this error: “Value cannot be null.” from Dim inters As Brep() = Brep.CreateBooleanIntersection(brep, bbrep, 1). And RhinoApp.WriteLine(bbrep.ToString) give me “Object reference not set to an instance of an object.”
Can someone tell me how to solve this problem please?
Thanks.
Basic debugging involves testing if you get what you expect after creating new things. See the text "' < Test for null/Nothing > which I injected here and there in your code.
Try that first and ask more if you don’t see where things goes wrong.
Dim bbox = brep.GetBoundingBox(True)
' < Test for null/Nothing >
Dim corner = bbox.GetCorners()
' < Test for null/Nothing >
For i = dt To corner(4).Z Step dt
For j = 0 To 3 Step 1
cor(j) = corner(j).Z + dt1
Dim bb As New Rhino.Geometry.BoundingBox(corner(0).X, corner(0).Y, corner(0).Z, corner(j).X, corner(j).Y, cor(j))
' < Test for null/Nothing >
Dim b As New Geometry.Box(bb)
' < Test for null/Nothing >
Dim bbrep = Geometry.Brep.CreateFromBox(b)
' < Test for null/Nothing >
RhinoApp.WriteLine(bbrep.ToString)
' < Test for null/Nothing >
Dim inters As Brep() = Brep.CreateBooleanIntersection(brep, bbrep, 1)
' < Test for null/Nothing >
Next
dt1 = dt1 + dt
Next
Dim bb As New Rhino.Geometry.BoundingBox(corner(0).X, corner(0).Y, corner(0).Z, corner(j).X, corner(j).Y, cor(j))
If Not bb.IsValid Then
RhinoApp.WriteLine(“INVALID bb”)
Return Rhino.Commands.Result.Failure
End If
Dim b As New Geometry.Box(bb)
If Not b.IsValid Then
RhinoApp.WriteLine("INVALID b")
Return Rhino.Commands.Result.Failure
End If
Dim bbrep = Geometry.Brep.CreateFromBox(b)
If bbrep Is Nothing Then
RhinoApp.WriteLine("INVALID bbrep")
Return Rhino.Commands.Result.Failure
End If
if (bbox.IsDegenerate(doc.ModelAbsoluteTolerance) > 0) {
RhinoApp.WriteLine("the curve's bounding box is degenerate (flat) in at least one direction so a box cannot be created.");
You might find that the box is really degenerate …
If I read your code correctly, the first iteration of the loop seems to build a box using the same vertex twice and simply changing the second Z … ( but obviously I may be wrong )
You can easily verify that by printing the values before passing them to the constructor … no ?
Yes…That was the mistake, plus the second loop…
I think this is correct:
Dim bb As New Rhino.Geometry.BoundingBox(corner(0).X, corner(0).Y, corner(0).Z, corner(2).X, corner(2).Y, cor(j))