Grasshopper

algorithmic modeling for Rhino

Hello, I am trying to send geometry from grasshopper via tcpip; When I try to serialize some GeometryBase type objects (LineCurves) it raises the execption ... Would you tell me what is the problem? Thanks in advance...


Exception :
value cannot be null;  parameter name : source

   위치: System.Runtime.InteropServices.Marshal.CopyToManaged(IntPtr source, Object destination, Int32 startIndex, Int32 length)    위치: System.Runtime.InteropServices.Marshal.Copy(IntPtr source, Byte[] destination, Int32 startIndex, Int32 length)    위치: Rhino.Runtime.CommonObject.SerializeWriteON_Object(IntPtr pConstOnObject, SerializationInfo info, StreamingContext context)    위치: Rhino.Runtime.CommonObject.GetObjectData(SerializationInfo info, StreamingContext context)    위치: System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)    위치: System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)    위치: System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)    위치: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)    위치: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)    위치: Strauto.Generation.GHCOM_SAP2KRemote.BuildGeometry() 파일 C:\Users\pc\Documents\Visual Studio 2008\Projects\Strauto\Strauto\Interface Components\GHCOM_SAP2KRemote.cs:줄 160

 


 My Source codes are....

 


 List<GeometryBase> _Geoms;

.....


FileStream fs = new FileStream("DataFile.dat", FileMode.Create);//temp stream;
BinaryFormatter formatter = new BinaryFormatter();                

try                

{      

                               formatter.Serialize(fs, _Geoms);
}                

catch (SerializationException e)                

{                   _logbuilder.AppendFormat("Failed to serialize. Reason: " + e.Message);                                    

}              

catch(Exception ex)                

{                  

 _logbuilder.AppendFormat("Failed to serialize. Reason: " + ex.Message);                

Views: 1216

Replies to This Discussion

Hi Sangsu,

The following code works fine in Rhino5.  Are you running Rhino 4 or Rhino 5?


string filename = "C:\\MyDataFile.dat";
LineCurve lc = new LineCurve(Point3d.Origin, new Point3d(10, 11, 12));
Mesh m = Mesh.CreateFromSphere(new Sphere(Point3d.Origin, 6), 10, 10);

var list = new System.Collections.Generic.List();
list.Add(lc);
list.Add(m);

var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using (var fs = new System.IO.FileStream(filename, System.IO.FileMode.Create))
{
formatter.Serialize(fs, list);
fs.Close();
}
using (var fs = new System.IO.FileStream(filename, System.IO.FileMode.Open))
{
object o = formatter.Deserialize(fs);
var retrieved_list = o as System.Collections.Generic.List;
fs.Close();
}

I am using Rhino4 on windows 7 64bit.

I tried your sample and it worked well.

It seems that the curves I have have some faults... they are from other grasshopper components and they have some user strings. I will try step by step to find out what is the cause of the problem.

 

Thanks.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service