From 46aa73b579d67d22053b9b637f1160a8e6196642 Mon Sep 17 00:00:00 2001 From: Dale Fugier Date: Fri, 2 Nov 2018 08:29:19 -0700 Subject: [PATCH] Updated sample. --- rhinopython/SampleSerialization.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/rhinopython/SampleSerialization.py b/rhinopython/SampleSerialization.py index e146d8d8..51dc98d6 100644 --- a/rhinopython/SampleSerialization.py +++ b/rhinopython/SampleSerialization.py @@ -5,6 +5,7 @@ ################################################################################ import clr import System +import System.Collections.Generic.IEnumerable as IEnumerable import Rhino import rhinoscriptsyntax as rs import scriptcontext as sc @@ -35,18 +36,38 @@ def BytesToGeometryBase(bytes): # Main function ################################################################################ def SampleSerialization(): - id = rs.GetObject('Select object') + + # Select baseeobject + base_id = rs.GetObject('Select object') + base_obj = rs.coercerhinoobject(base_id) + + # Select object to embed + id = rs.GetObject('Select object to embed') geometry = rs.coercegeometry(id) print(geometry) + # Convert geometry to bytes bytes = GeometryBaseToBytes(geometry) print(bytes) - new_geometry = BytesToGeometryBase(bytes) + # Add bytes to base object's dictionary + key = 'test' + base_obj.Attributes.UserDictionary.Set.Overloads[str,IEnumerable[System.Byte]](key ,bytes) + + # Get bytes from base object + new_bytes = base_obj.Attributes.UserDictionary.GetBytes(key) + print(new_bytes) + + # Convert bytes to geometry + new_geometry = BytesToGeometryBase(new_bytes) print(new_geometry) + # Add geometry to document new_id = sc.doc.Objects.Add(new_geometry) print(new_id) + + # Remove bytes from dictionary + base_obj.Attributes.UserDictionary.Remove(key) ################################################################################ # Check to see if this file is being executed as the "main" python