Grasshopper

algorithmic modeling for Rhino

Somehow I don't get this castFrom Matrix to work...

Help would be appreciate

Best Richard

Yes and before you ask it's a squared matrix....

Public Function CastFrom(source As Object) As Boolean Implements IGH_Goo.CastFrom
If source Is Nothing Then Return False
 If

 ...
 ElseIf GetType(Matrix).IsAssignableFrom(source.GetType) Then
  Dim tmpMatrix As Matrix = DirectCast(source, Matrix)
  If Not tmpMatrix.IsSquare Return False
  Me.gM = New Meta.Numerics.Matrices.SymmetricMatrix(tmpMatrix.RowCount)
  For i As Integer = 0 To Me.dimension - 1
    For j As Integer = 0 To Me.dimension - 1
      Me.gM(i, j) = tmpMatrix.Item(i, j)
    Next
  Next
  Me.MT = graphMatrix.matrixType.unknow
  Return True
 End If
Return False
End Function

Views: 433

Replies to This Discussion

I tried to solve it and the code works when used in a VB Component.

But not when implemented as Parameter...

Any suggestions would be helpful

thx 

Richard

Attachments:

Can you post vb code I can actually compile in Visual Studio?

--

David Rutten

david@mcneel.com

Here is the complete CastFrom Code, did also attach the VB.NET file but to run it you would need meta.numerics

''' <summary>

''' Attempt a cast from generic object
''' </summary>
''' <param name="source"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function CastFrom(source As Object) As Boolean Implements IGH_Goo.CastFrom
If source Is Nothing Then Return False
If GetType(graphMatrix).IsAssignableFrom(source.GetType) Then
Dim gM As graphMatrix = DirectCast(source, graphMatrix)
Me.gM = gM.Matrix
Me.MT = gM.type
Return True
ElseIf GetType(Graph).IsAssignableFrom(source.GetType) Then
Dim G As Graph = DirectCast(source, Graph)
Dim gM As New graphMatrix(G)
Me.gM = gM.Matrix
Me.MT = gM.type
Return True
ElseIf GetType(Matrix).IsAssignableFrom(source.GetType) Then
Dim tmpMatrix As Matrix = DirectCast(source, Matrix)
If Not tmpMatrix.IsSquare Then
Return False
End If
Me.MT = GH_graphMatrix.matrixType.unknow
Me.gM = New Meta.Numerics.Matrices.SymmetricMatrix(tmpMatrix.RowCount)
For i As Integer = 0 To Me.dimension - 1
For j As Integer = 0 To Me.dimension - 1
Me.gM(i, j) = tmpMatrix.Item(i, j)
Next
Next
Return True
End If
Return False
End Function

I don't see a vb file attachment. It might also be helpful if you could elaborate on "Somehow I don't get this castFrom Matrix to work...". Is there a compiler error? A runtime error? If so, what is the error? Does it not work as expected? Have you put breakpoints in the code to see how the function behaves at runtime?

--

David Rutten

david@mcneel.com

Okay now I get it, sorry

The error I am getting is the GH Red component which tells me that he can not cast from matrix to GH_graphMatrix. No error while compiling. 

Attached a file but I don't know how helpfule it is.

thx

Richard

Attachments:

Yeah I can't examine that file for correctness without referencing SpiderWebLibrary and GH_SpiderWebLibrary (unless that's the same thing?).

Unfortunately the GH red error may mean that there was an exception you didn't handle or that it just couldn't find a conversion from the Grasshopper Matrix type to your type, so that doesn't really narrow it down.

I recommend putting a breakpoint on the first line in CastFrom() to see if the method gets called at all, and if it is, what exactly the source parameter is.

--

David Rutten

david@mcneel.com

I think I figured it out: 

I have to look for GH_Matrix not Matrix.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service