Beispiel #1
0
        public override void DocumentContextChanged(Grasshopper.Kernel.GH_Document document, Grasshopper.Kernel.GH_DocumentContext context)
        {
            base.DocumentContextChanged(document, context);
            if (context == Grasshopper.Kernel.GH_DocumentContext.Loaded)
            {
                //Rhino.RhinoDoc.ReplaceRhinoObject += RhinoDoc_ReplaceRhinoObject;

                timer          = new System.Windows.Forms.Timer();
                timer.Tick    += timer_Tick;
                timer.Enabled  = false;
                timer.Interval = 1;

                // register evens

                keyboardHook.KeyDown     = new RamGecTools.KeyboardHook.KeyboardHookCallback(keyboardHook_KeyDown);
                keyboardHook.KeyUp       = new RamGecTools.KeyboardHook.KeyboardHookCallback(keyboardHook_KeyUp);
                keyboardHook._activate   = new RamGecTools.KeyboardHook.activate(activate);
                keyboardHook._deactivate = new RamGecTools.KeyboardHook.deactivate(deactivate);
                keyboardHook.Uninstall();

                keyboardHook.Install();
                full = new mikity.visualize.fullScreen(DEV);
                full.deactivate();
                full.Show();
                full.resetGo();
                full.drift1();
                full.renewPlot(Drift1);
                full.onRF();
                if (!DEV)
                {
                    full.onNorm();
                    _normalize = true;
                }
                else
                {
                    full.offNorm();
                    _normalize = false;
                }
                full.onGeo();
                full.offVN();
                full.offIF();
            }
            if (context == Grasshopper.Kernel.GH_DocumentContext.Unloaded)
            {
                keyboardHook.Uninstall();
                keyboardHook.KeyDown -= new RamGecTools.KeyboardHook.KeyboardHookCallback(keyboardHook_KeyDown);
                keyboardHook.KeyUp   -= new RamGecTools.KeyboardHook.KeyboardHookCallback(keyboardHook_KeyUp);
                if (full != null)
                {
                    full.Close();
                    full = null;
                }
            }
        }
 public static void DocumentOverview(GH.Kernel.GH_Document doc)
 {
     if (doc != null)
     {
         foreach (GH.Kernel.GH_DocumentObject obj in doc.Objects)
         {
             string name = obj.Name;
             string uid  = obj.InstanceGuid.ToString();
             Rhino.RhinoApp.WriteLine("- " + name + " (" + uid + ")");
         }
     }
 }
Beispiel #3
0
        // Currently need a separate RunHelper function so the .NET runtime won't attempt to load the
        // Grasshopper assembly until after RhinoCore has been created. This should be "fixable" in a
        // future version of the RhinoInside nuget package
        static void RunHelper()
        {
            // Extract definition to sample location as executable
            var    assembly       = typeof(Program).Assembly;
            string dir            = System.IO.Path.GetDirectoryName(assembly.Location);
            string definitionPath = System.IO.Path.Combine(dir, "simple_def.gh");

            using (var resStream = assembly.GetManifestResourceStream("RunGrasshopper.simple_def.gh"))
                using (var outStream = new System.IO.FileStream(definitionPath, System.IO.FileMode.Create))
                {
                    resStream.CopyTo(outStream);
                }


            // Start grasshopper in "headless" mode
            var pluginObject = Rhino.RhinoApp.GetPlugInObject("Grasshopper") as Grasshopper.Plugin.GH_RhinoScriptInterface;

            pluginObject.RunHeadless();

            var archive = new GH_Archive();

            archive.ReadFromFile(definitionPath);

            using (var definition = new Grasshopper.Kernel.GH_Document())
            {
                archive.ExtractObject(definition, "Definition");
                foreach (var obj in definition.Objects)
                {
                    if (obj is Grasshopper.Kernel.IGH_Param param)
                    {
                        if (obj.NickName == "CollectMe")
                        {
                            param.CollectData();
                            param.ComputeData();
                            foreach (var item in param.VolatileData.AllData(true))
                            {
                                Line computedLine = Line.Unset;
                                if (item.CastTo(out computedLine))
                                {
                                    Console.WriteLine($"Got a line ... {computedLine}");
                                }
                            }
                        }
                    }
                }
            }
            Console.WriteLine("Done... press and key to exit");
            Console.ReadKey();
        }
Beispiel #4
0
 public override void RemovedFromDocument(Grasshopper.Kernel.GH_Document document)
 {
     base.RemovedFromDocument(document);
     keyboardHook.Uninstall();
     keyboardHook.KeyDown -= new RamGecTools.KeyboardHook.KeyboardHookCallback(keyboardHook_KeyDown);
     keyboardHook.KeyUp   -= new RamGecTools.KeyboardHook.KeyboardHookCallback(keyboardHook_KeyUp);
     if (full != null)
     {
         full.Close();
         full = null;
     }
     if (timer != null)
     {
         timer = null;
     }
 }
 public override void AddedToDocument(Grasshopper.Kernel.GH_Document document)
 {
     base.AddedToDocument(document);
     myControlBox.Show();
     myControlBox.setFunctionToCompute(() => { computeF(); });
     myControlBox.setFunctionToCompute2(() => { computeG(); });
     myControlBox.setFunctionForRadio1(() =>
     {
         if (ready)
         {
             hodgeStar(listLeaf, listBranch, listNode, myControlBox.coeff, myControlBox.sScale);
             ready = true;
             this.ExpirePreview(true);
         }
     });
     myControlBox.setFunctionToReflect(() => {
         zScale = Rhino.Geometry.Transform.Scale(Plane.WorldXY, 1, 1, myControlBox.zScale);
         hodgeStar(listLeaf, listBranch, listNode, myControlBox.coeff, myControlBox.sScale);
         this.ExpirePreview(true);
     });
 }
        /// <summary>
        /// Singleton
        /// </summary>
        public static SOGrasshopperController GetInstance(GH.Kernel.GH_Document ghDocument)
        {
#if DEBUG
            Rhino.RhinoApp.Write("Trying to make controlller... ");
#endif
            if (m_Instance == null)
            {
                lock (m_SyncRoot)
                {
                    if (m_Instance == null)
                    {
                        m_Instance = new SOGrasshopperController();
                        m_Instance.m_Controller = SOController.Instance;
#if DEBUG
                        Rhino.RhinoApp.Write("new... ");
#endif
                    }
                }
            }
#if DEBUG
            Rhino.RhinoApp.WriteLine("done");
#endif
            if (ghDocument != null)
            {
                if (!m_Instance.m_Registered)
                {
                    ghDocument.RaiseEvents     = true;
                    ghDocument.SolutionStart  += new GH.Kernel.GH_Document.SolutionStartEventHandler(ghDocument_SolutionStart);
                    ghDocument.SolutionEnd    += new GH.Kernel.GH_Document.SolutionEndEventHandler(ghDocument_SolutionEnd);
                    ghDocument.ObjectsAdded   += new GH.Kernel.GH_Document.ObjectsAddedEventHandler(ghDocument_ObjectsAdded);
                    ghDocument.ObjectsDeleted += new GH.Kernel.GH_Document.ObjectsDeletedEventHandler(ghDocument_ObjectsDeleted);
                    m_Instance.m_Registered    = true;
#if DEBUG
                    Rhino.RhinoApp.WriteLine("Events registered");
#endif
                }
            }
            return(m_Instance);
        }