Grasshopper

algorithmic modeling for Rhino

Hi David,

I have a custom class that contains fields of custom classes and these fields contain fields of custom classes. To deserialize them all have igh_goo implemented. But something is going wrong and GH not give me information (see image). How could I find out where the error is?

Another thing I do not understand is in order to filter the source of the error, I added a rhinoapp.writeline() lines but do not get any line of text in rhino. Why does this happen? They did not even get to read those lines? What is happening then?

This is the root of deserialization of all classes:

Public Function Read(reader As GH_IReader) As Boolean Implements GH_ISerializable.Read
Try
If reader.ChunkExists("Lindenmayer System") Then

RhinoApp.WriteLine(" EXISTE ")

Dim i As New Integer
Dim r As GH_IReader = reader.FindChunk("Lindenmayer System")
mGeneration = r.GetInt32("Generation")
mType = New List(Of LsystemType)
Dim CT As Integer = r.GetInt32("CountType")
For i = 0 To CT - 1
mType.Add(r.GetInt32("Type", i))
Next
mAxiom = r.GetString("Axiom")
Dim CR As Integer = r.GetInt32("CountRules")
mRules = New List(Of String)
For i = 0 To CR - 1
mRules.Add(r.GetString("Rule", i))
Next
mRulesManager = New RulesManager()
mRulesManager.Read(r)
Dim rp As GH_IReader = r.FindChunk("Production")
Dim CG As Integer = rp.GetInt32("Count")
Dim P As Grapheme() = New Grapheme(CG - 1) {}
For i = 0 To CG - 1
Dim rg As GH_IReader = rp.FindChunk("Graphemes", i)
Dim G As New Grapheme
G.Read(rg)
P(i) = G
Next
mProduction = New Queue(Of Grapheme)(P)
mSettings = New LSSettings()
mSettings.Read(r)
mParser = New LSParser(mRulesManager.RulesSymbol, Me)

RhinoApp.WriteLine(mAxiom)
For Each Ru As String In mRules
RhinoApp.WriteLine(Ru)
Next
RhinoApp.WriteLine("type count = " & mType.Count)
RhinoApp.WriteLine("mProd count = " & mProduction.Count)
Else
RhinoApp.WriteLine("NO EXISTE ")
End If
Return True

Catch ex As Exception
RhinoApp.WriteLine(ex.ToString)
Return False
End Try
End Function

Also attached the part of the xml which generates my code.

Thanks in advance.

attached the part of the xml.

Views: 609

Attachments:

Replies to This Discussion

have you tried doing a step-through debug in visual studio? Also this is just a wild guess but maybe don't use "RhinoApp.WriteLine" to do your debugging - my usual lazy way is to do a MessageBox.Show(). My speculative hunch is that somehow at the moment of deserialization the plug-in can't access RhinoApp - which is why you'd 1. be getting an error right away and 2. not seeing ANY output from the program. Could be totally wrong though. 

Thanks for the reply Andrew.

I can not do a stepped debug because I'm building a .dll, not directly a gha (which will come later). After two seconds begin compiling ends up.
I tried to replace rhinoapp.writeline by MessageBox.Show () and nothing appears. It was nice the idea but nothing.

I think the serialization is badly written and GH does not recognize it at read or something like that but I can not find the fault...

Public Function Write(writer As GH_IWriter) As Boolean Implements GH_ISerializable.Write
Try
Dim i As New Integer
Dim w As GH_IWriter = writer.CreateChunk("Lindenmayer System")
w.SetInt32("Generation", mGeneration)
w.SetInt32("CountType", mType.Count)
For i = 0 To mType.Count - 1
w.SetInt32("Type", i, mType(i))
Next
w.SetString("Axiom", mAxiom)
w.SetInt32("CountRules", mRules.Count)
For i = 0 To mRules.Count - 1
w.SetString("Rule", i, mRules(i))
Next
mRulesManager.Write(w)
Dim wp As GH_IWriter = w.CreateChunk("Production")
Dim P As Grapheme() = Production
wp.SetInt32("Count", P.Length)
For i = 0 To P.Length - 1
Dim wg As GH_IWriter = wp.CreateChunk("Graphemes", i)
P(i).Write(wg)
Next
mSettings.Write(w)

Return True
Catch ex As Exception
RhinoApp.WriteLine(ex.ToString)
Return False
End Try
End Function

you have GH Components (or params / "goo" types?) defined in a .dll rather than a GHA? Why? 


One thing I use to test my write method is to copy paste a component from GH into a text document - then you can view the xml that it's storing and see where the issue might be. 

No, I'm not defining GH_Component, only objects that implement igh_goo.
I want to make my plugin as modular as possible, and can be used from script components. I'm just doing the operative part and the gh shell in different dll (a .dll library and a .gha). And I think that's why I do not have to override the method because it directly implements the interface.

Could you temporarily pop the classes in question into a GHA for debugging purposes? I'm stumped. Ive never tried implementing GH_ISerializable directly.

Well, my doubts increase.
It seems that in a"GH_PersistentParam(of myType) deserialization works well (also in Gh_Component), but not outside it. For example, another component returns an object of that type, and I use a [Data] component to internalize it, I copy and paste, and that message still appears unable to deserialize.


What am I missing?

Also I'm just noticing - don't Read and Write have to be overrides? I'm not as familiar w vb.net syntax as I am w/ c# so maybe I'm missing something here. 

Yup, that should be set as Overrides in vb.net 

To add up to the debugging point, guessing the library is written in VS (also assuming VS 2015) : 

1. Set the application type as class library

2. Debug > Start external program: > Rhino 5

3. Run the debugger

4. Reference this library in gh with scripting component 

5. Call stuff from the lib with that script

That way gives you a proper set of debugging options. You can put breakpoints in VS, use the immediate window, set and get variables etc. I literally write everything GH-related that way now... and I'm also trying to keep everything modular.  

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