Grasshopper

algorithmic modeling for Rhino

Hey,

I know it had been already done but I can't find the solution. I recently started VB.Net and I am still struggling with it.

I try to make a culling pattern to dispatch an array of lines intersecting an other array of lines (could be breps surface....). It is for a shading studies.

Please anyone can help me to debug it?

here the script in VB



Sub RunScript(ByVal x As List(Of OnLine), ByVal y As List(Of OnLine))

Dim i As Integer
Dim j As Integer
Dim N As Integer
Dim LBool As New List(Of Boolean)
Dim test As Boolean

For i = 0 To x.Count() - 1
LBool.Add(False)
Next

For i = 0 To x.Count() - 1

For j = 0 To y.Count() - 1
'
N = 0

Dim intsec As Boolean
Dim crvs() As IOnCurve
Dim pt As On3dPointArray

intsec = RhUtil.RhinoIntersectBreps(x(i), y(j), 0.01, crvs, pt)
Dim intCount As Int32 = Pt.sizeofarray

If Not intsec = False Then N = N + 1


Next

If N = 0 Then

test = False
Else
test = True

End If

LBool(i) = test

Next
A = LBool

End Sub

Views: 590

Attachments:

Replies to This Discussion

A little hard for me to follow what's going on here, but I think I may know what you're issue is. The fact that the RhinoIntesectsBreps method returns a boolean is somewhat misleading and its not a good idea to depend on it, which is what it looks like you might be doing. The initial impression of that method is that if its true than there was an intersection, and if its false, then there wasn't one. As confusing as that is, that's not what the returned boolean value is actually representing. It will only return false is something prevents the method from actually running as expected, so one of the inputs wasn't a brep or one of the breps was bad or something. It will return true in all other cases, even if the breps in question don't actually intersect, because it was actually able to go and find if there was an intersection.

It looks like you're looking for whether there was actually a result from the intersection (ie points and/or curves were created), so if that's the case, then you are much better off checking the curves and points to see if they are filled with any values. If either of them are, then you've got a valid intersection. If both arrays are empty, then there is no valid intersection.

HTH

One last syntax thing.... If Not intsec = False Then... is a double negative. This is somewhat confusing and completely unnecessary. The following syntax is much quicker and easier to understand... If intsec Then... because the variable is a boolean there's no need to check its assignment or anything since it is true or false... And if you want to do something when its false, just through Not there in front of it... If Not intsec Then...
Thanks Damien,

I have to admit that the syntax is a bit confused because I tried all kind of variable test. I apologize, I should clean a bit better the code.

So if I understand, I should not use RhinoIntersectBreps method as a test. I should test if it created some points or not.

intsec = RhUtil.RhinoIntersectBreps(x(i), y(j), 0.01, crvs, pt)
Dim intCount As Int32 = Pt.count()


and then test if intcount is different to 0

Is it what you were suggested?

I actually tried this but it always returned me an error. As it is in french I'll try a translation:

0- warning : the variable 'crvs' is passed by reference before a value had been assigned. An exception of Null reference could happen at the executive moment

0- same warning for 'pt'

1- Script exception: impossible to cast an 'RMA.OpenNURBS.OnLine' object kind in an 'RMA.OpenNurbse.IOnBrep' one


I am sorry to bother you with such simple things, I'm used of VBA not VB.Net and I am still learning the basic.

But as I have to finish this study for my boss I asked some help on this forum.

As attached file is the GHX I used
Attachments:
Yes, you can testing intcount is a way to do this.

As to your errors...
0 - this is a warning because in some cases it doesn't mean anything. Essentially you're using a variable that has nothing in it, which can cause things to fail. In this case, you don't need anything in it, since the method will simply fill that variable back up and you can use it afterwords. Since seeing this annoys me I usually do something like this, which will more or less tell the scripting engine "I know there's nothing in there"

Dim myRefVariable as SomeType = Nothing

1 - Not sure why I didn't catch this before, but you're using lines when you're trying to intersect Breps, which just plain won't work. The best method to switch over to is OnUtil.ON_IntersectLineLine. Its syntax is a bit more simple, and it will give you the parameter of the intersection as opposed to points/curves. Just use the PointAt method to work with it. Example below where x and y are both OnLines.

Dim xA, xB As Double
OnUtil.ON_IntersectLineLine(x, y, xA, xB, doc.absoluteTolerance, True)
A = x.PointAt(xA)
Thanks a lot Damien

It works!!!!

I guess it seems I am overreacting but I am so glad it works.
For some reason its not letting me edit my comment...Anyway, one last thing. Using that method, if the lines don't intersect, the parameters for each line will still be outputted. So if they don't intersect, one of the resulting parameters will be at the end of its line. You should check and see if the resulting point from the PointAt function is equal to either the start or the end point. The following if statement should take care of it...


If Not (ptA = x.from Or ptA = x.To) _
And Not (ptB = y.from Or ptB = y.To) Then
A = ptA
End If
Here is the result

thanks again Damian

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service