Grasshopper

algorithmic modeling for Rhino

as the post says, how does one serialize a curve object to a an xml string that can be deserialized back to a curve object? Im lookign at the grasshopper gh_Curve type and there appears to be XML writer methods here but Im not an expert in this,

 

cheers

 

Views: 2493

Replies to This Discussion

I'm going to be working on a plugin that will have components with internalized meshes. It sounds like taking the mesh and generating an XML to be stored and converted in a component might be the way to go. Unfortunately the meshes I have are fairly large. They aren't crazy large, but they definitely aren't small. The XML that I generated was about 99 pages long in a word document for one of the meshes I tested. So it sounds like it may work, but I'm wondering if there is a better way to deal with serializing and deserializing meshes in GHA files.

P.S. I got an error when I plugged in these high-poly meshes. I haven't seen it since but it said that GH was going into ultra paranoid mode or something like that.

You may run into bugs with (de)serializing OpenNurbs geometry on Rhino4, it seems to work fine on Rhino5. That aside, the best way to store a mesh for long-term storage would be to create an open-nurbs byte array and compress that.

You'll find CommonObjectToByteArray() and ByteArrayToCommonObject() static methods in GH_Convert which you can use to get OpenNurbs compliant bytes representing the shape. You can also use the Compress() and Decompress() methods in GH_IO.Serialization.GH_Compression to zip/unzip a byte-array.

Byte arrays are easy to (de)serialize to whatever format you want, be it textual or binary. Xml is actually pretty good at storing byte-arrays in relatively little space, but you'r better off using some form of binary format with zero overhead.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I've been able to convert geometry to byte arrays using the scripts in this discussion, but I'm wondering if it's possible to take that byte array and move it to visual studio to put inside a new component? Can I somehow save the byte array to a text file and reference it in Visual Studio? If anyone knows of any good resources for that kind of thing I'd be much obliged.

thanks

-Brian

Don't use text files to store byte arrays, that won't end well. Best would be to use a streamwriter to write the bytes to a file directly and then put that file as a resource into your project.

You can use System.IO.File.WriteAllBytes

It is also possible to reliable store a byte array in xml data, but it would be an unnecessary roundabout way.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

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