Skip to content
This repository was archived by the owner on Jan 6, 2021. It is now read-only.

Commit 996b41d

Browse files
committed
minimum changes to later get compilation to work
1 parent ece83a8 commit 996b41d

5 files changed

Lines changed: 46 additions & 18 deletions

File tree

Component/PythonComponent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ protected override void SetScriptTransientGlobals()
4343
case DocStorage.InGrasshopperMemory:
4444
case DocStorage.AutomaticMarshal:
4545
{
46-
m_py.ScriptContextDoc = m_document;
47-
m_marshal = new OldComponentIOMarshal(m_document, this);
48-
m_py.SetVariable(DOCUMENT_NAME, m_document);
49-
m_py.SetIntellisenseVariable(DOCUMENT_NAME, m_document);
46+
m_py.ScriptContextDoc = g_document;
47+
m_marshal = new OldComponentIOMarshal(g_document, this);
48+
m_py.SetVariable(DOCUMENT_NAME, g_document);
49+
m_py.SetIntellisenseVariable(DOCUMENT_NAME, g_document);
5050
break;
5151
}
5252
case DocStorage.InRhinoDoc:

Component/ScriptingAncestorComponent.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ namespace GhPython.Component
1818
public abstract class ScriptingAncestorComponent : SafeComponent
1919
{
2020
static bool g_resources_unpacked = false;
21+
internal static GrasshopperDocument g_document = new GrasshopperDocument();
22+
2123
private readonly StringList m_py_output = new StringList(); // python output stream is piped here
22-
internal static GrasshopperDocument m_document = new GrasshopperDocument();
24+
2325
internal ComponentIOMarshal m_marshal;
2426
protected PythonScript m_py;
2527
private PythonCompiledCode m_compiled_py;
@@ -80,7 +82,7 @@ private static void UnpackScriptResources()
8082
// if we get to here, we need to unpack the resources
8183
if (!Directory.Exists(settings_directory))
8284
Directory.CreateDirectory(settings_directory);
83-
string ghpython_package_dir = Path.Combine(settings_directory, "lib", "ghpython");
85+
string ghpython_package_dir = Path.Combine(settings_directory, "lib", "gh_python");
8486
if (Directory.Exists(ghpython_package_dir))
8587
Directory.Delete(ghpython_package_dir, true);
8688
Directory.CreateDirectory(ghpython_package_dir);
@@ -127,7 +129,6 @@ protected override void Initialize()
127129
m_py = PythonScript.Create();
128130
if (m_py != null)
129131
{
130-
//UnpackScriptResources();
131132
SetScriptTransientGlobals();
132133
m_py.Output = m_py_output.Write;
133134
m_py.SetVariable("__name__", "__main__");
@@ -139,6 +140,11 @@ protected override void Initialize()
139140
m_py.ContextId = 2; // 2 is Grasshopper
140141

141142
m_env.LoadAssembly(typeof(GH_Component).Assembly); //add Grasshopper.dll reference
143+
m_env.LoadAssembly(typeof(ZuiPythonComponent).Assembly); //add GHPython.dll reference
144+
145+
UnpackScriptResources();
146+
147+
m_env.AddGhPythonPackage();
142148
}
143149
}
144150
#endregion
@@ -320,6 +326,8 @@ private static Param_String ConstructOutOutputParam()
320326

321327
protected override void SafeSolveInstance(IGH_DataAccess da)
322328
{
329+
m_env.DataAccessManager = da;
330+
323331
if (m_py == null)
324332
{
325333
da.SetData(0, "No Python engine available. This component needs Rhino v5");
@@ -333,7 +341,7 @@ protected override void SafeSolveInstance(IGH_DataAccess da)
333341

334342
var rhdoc = RhinoDoc.ActiveDoc;
335343
var prevEnabled = (rhdoc != null) && rhdoc.Views.RedrawEnabled;
336-
344+
337345
try
338346
{
339347
// set output variables to "None"
@@ -424,7 +432,7 @@ protected override void SafeSolveInstance(IGH_DataAccess da)
424432

425433
private bool AddLocalPath(out string path)
426434
{
427-
string probe_location = m_document.Path;
435+
string probe_location = g_document.Path;
428436
if (string.IsNullOrWhiteSpace(probe_location)) { path = null; return false; }
429437

430438
probe_location = Path.GetDirectoryName(probe_location);
@@ -533,8 +541,24 @@ protected virtual void SetScriptTransientGlobals()
533541

534542
private void OnDocSolutionEnd(object sender, GH_SolutionEventArgs e)
535543
{
536-
if (m_document != null)
537-
m_document.Objects.Clear();
544+
if (g_document != null)
545+
g_document.Objects.Clear();
546+
}
547+
548+
internal void RemoveAllVariables()
549+
{
550+
var variables = m_py.GetVariableNames().ToArray();
551+
552+
for (int i = 0; i < variables.Length; i++)
553+
{
554+
var variable = variables[i];
555+
556+
if (string.IsNullOrWhiteSpace(variable)) continue;
557+
if (variable.StartsWith("_")) continue;
558+
if (variable == DOCUMENT_NAME || variable == PARENT_ENVIRONMENT_NAME) continue;
559+
560+
m_py.RemoveVariable(variables[i]);
561+
}
538562
}
539563

540564
#endregion
@@ -815,5 +839,9 @@ protected override void Dispose(bool disposing)
815839
}
816840
}
817841
#endregion
842+
843+
#region Properties Access
844+
internal PythonScript PythonScript { get { return m_py; } }
845+
#endregion
818846
}
819847
}

Component/ZUIPythonComponent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ protected override void SetScriptTransientGlobals()
144144
{
145145
base.SetScriptTransientGlobals();
146146

147-
m_py.ScriptContextDoc = m_document;
148-
m_marshal = new NewComponentIOMarshal(m_document, this);
149-
m_py.SetVariable(DOCUMENT_NAME, m_document);
150-
m_py.SetIntellisenseVariable(DOCUMENT_NAME, m_document);
147+
m_py.ScriptContextDoc = g_document;
148+
m_marshal = new NewComponentIOMarshal(g_document, this);
149+
m_py.SetVariable(DOCUMENT_NAME, g_document);
150+
m_py.SetIntellisenseVariable(DOCUMENT_NAME, g_document);
151151
}
152152

153153
public override Guid ComponentGuid

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717

1818

1919
// [0.5.1.0] 6 August 2012 S. Baer - updated version numbers as minor update to be compatible with GH 0.9
20-
[assembly: AssemblyVersion("0.5.101.0")]
21-
[assembly: AssemblyFileVersion("0.5.101.0")]
20+
[assembly: AssemblyVersion("0.6.0.1")]
21+
[assembly: AssemblyFileVersion("0.6.0.1")]

package/components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def function_description(description, params):
9090
return '\n'.join(rc)
9191

9292
import sys, types, re
93-
core_module = sys.modules['ghpython.components']
93+
core_module = sys.modules['gh_python.components']
9494
translate_from = u"|+-*\u2070\u00B9\u00B2\u00B3\u2074\u2075\u2076\u2077\u2078\u2079"
9595
translate_to = "X__x0123456789"
9696
transl = dict(zip(translate_from, translate_to))

0 commit comments

Comments
 (0)