Skip to content

Commit 42a8ef4

Browse files
committed
changes necessary to create modern ipy components
1 parent a919b4e commit 42a8ef4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

componentize_ipy_v2.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import System
1616
import System.IO
1717

18-
GHPYTHON_SCRIPT_GUID = System.Guid("410755b1-224a-4c1e-a407-bf32fb45ea7e")
18+
# this GUID means "Modern IronPython interpreter"
19+
GHPYTHON_SCRIPT_GUID = System.Guid("97aa26ef-88ae-4ba6-98a6-ed6ddeca11d1")
1920
TEMPLATE_VER = re.compile("{{version}}")
2021
TEMPLATE_NAME = re.compile("{{name}}")
2122
TEMPLATE_GHUSER_NAME = re.compile("{{ghuser_name}}")
@@ -251,7 +252,6 @@ def create_ghuser_component(source, target, version=None, prefix=None):
251252
ghpython_root.SetBoolean(
252253
"MarshalOutGuids", ghpython_data.get("marshalOutGuids", True)
253254
)
254-
ghpython_root.SetString("CodeInput", code)
255255

256256
# ghpython_root.CreateChunk('Attributes')
257257
# for mf in ('Bounds', 'Pivot', 'Selected'):
@@ -315,7 +315,16 @@ def create_ghuser_component(source, target, version=None, prefix=None):
315315
elif po.get("graft", False):
316316
po_chunk.SetInt32("Mapping", 2)
317317

318-
# print(ghpython_root.Serialize_Xml())
318+
# this is new in Rhino8, istead of setting the code as a string, we set it as a base64 blob
319+
script = ghpython_root.CreateChunk("Script")
320+
code_base64 = base64.b64encode(code.encode("utf-8"))
321+
code_base64 = str(code_base64)
322+
script.SetString("Text", code_base64)
323+
script.SetString("Title", "IPy2")
324+
language_spec = script.CreateChunk("LanguageSpec")
325+
language_spec.SetString("Taxon", "*.ironpython.python")
326+
language_spec.SetString("Version", "2.*")
327+
319328
root.SetByteArray("Object", ghpython_root.Serialize_Binary())
320329

321330
System.IO.File.WriteAllBytes(target, root.Serialize_Binary())

0 commit comments

Comments
 (0)