Skip to content

Commit

Permalink
Updated sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefugier committed Nov 2, 2018
1 parent 4ff937c commit 46aa73b
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions rhinopython/SampleSerialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 46aa73b

Please sign in to comment.