Grasshopper

algorithmic modeling for Rhino

I am just a beginner and GH seems like a really cool tool.

I want to use GH from with my own (C#) application. I can interact with Rhino via their interfaces and can instantiate GH this way. But how can I tell GH to simply "load a ghx file" without using the GH GUI? My hope is that after loading the ghx, the rest of the interaction can be done via input text files.

Its almost unbelivable that a software of this scale has no api/command line/COM/something to allow such an operation.

Did I miss something?

(I even tried looking for the GH window and "pressing CTRL-O" via the SendKey command but events seem to get to the Rhino window after all.

Tanir

Views: 3718

Replies to This Discussion

Hi Tanir,

Grasshopper exposes some functions via the RhinoScript language, but that hasn't been documented properly yet. Would this be sufficient for your needs?

You could also write a GHA file which hooks into Grasshopper, you could then communicate with this instance via WCF, but I've only ever written one WCF app, so this may not be a useful suggestion.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

"Grasshopper exposes some functions via the RhinoScript language, but that hasn't been documented properly yet. Would this be sufficient for your needs?"

Yes, that will be great :)

I also saw your following response to the post "Open a .gh automatically" of the February 14 :

Hi Manuel,

Grasshopper exposes a RhinoScript interface. The following methods are available:

IsEditorLoaded()
IsEditorVisible()
LoadEditor()
ShowEditor()
HideEditor()
EnableBanner()
DisableBanner()
IsSolverEnabled()
EnableSolver()
DisableSolver()
RunSolver(expireAll As Boolean)
OpenDocument(fileName As String)
CloseDocument()
CloseAllDocuments()
SaveDocument()
SaveDocumentAs(fileName As String)
AssignDataToParameter(parameterID As String, data As Object)
BakeDataInObject(objectID As String)

Please, please please could you put a small demo - just how to use "OpenDocument". I believe I could take it from there.

The RhinoScript could look like this:

Option Explicit

Call Main()

Sub Main()

  Dim GH : Set GH = Rhino.GetPluginObject("Grasshopper")

  GH.OpenDocument("C:\Users\User\Desktop\ExampleFile.gh")

  Set GH = Nothing

End Sub

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi Tanir

this is C# 4.0 to connect via COM, same as what David mentions:

var type = Type.GetTypeFromProgID("Rhino5.Application", true);
//http://www.rhino3d.com/5/rhinoscript/introduction/external_access.htm

dynamic rhinoComObj = Activator.CreateInstance(type);
rhinoComObj.Visible = true;

while (rhinoComObj.IsInitialized() == 0) Thread.Sleep(100);

rhinoComObj.RunScript("_Grasshopper", 0);
var gh = rhinoComObj.GetPlugInObject("b45a29b1-4343-4035-989e-044e8580d9cf", "00000000-0000-0000-0000-000000000000") as dynamic;

gh.OpenDocument(@"C:\Users\User\Desktop\ExampleFile.gh");

Thanks,

- Giulio
______________
giulio@mcneel.com

Thanx thanx thanx :)

Giulio it is possible in VB ? with Visual Studio 2010 and your class assembly wizard.

Thanks

Hi,

yes, it should be possible. This is in Vb.Net translated with developefusion's tools and a couple of small fixes --- but I'd suggest not to call this in SolveInstance. Please review well in advance where this code will run and triggered by what other code.

Also see that other discussion you started here.

Dim type1 = Type.GetTypeFromProgID("Rhino5.Application", True)
'http://www.rhino3d.com/5/rhinoscript/introduction/external_access.htm

Dim rhinoComObj As Object = Activator.CreateInstance(type1)
rhinoComObj.Visible = True

While rhinoComObj.IsInitialized() = 0
    Thread.Sleep(100)
End While

rhinoComObj.RunScript("_Grasshopper", 0)
Dim gh as Object = rhinoComObj.GetPlugInObject("b45a29b1-4343-4035-989e-044e8580d9cf", "00000000-0000-0000-0000-000000000000")

gh.OpenDocument("C:\Users\User\Desktop\ExampleFileID.gh")

Also, remember that normal objects (not MarshalByReference objects) need to be marshalled across AppDomains.

I hope this helps,

- Giulio
________________
giulio@mcneel.com

Thanks giulio,

There in no error in VS2010 but apparently nothing happens in rhinoceros.

here my function:

        Function ExecuterDefinition(ByVal Definition As RhinoDoc, ByVal mode As RunMode) As Result
            Rhino.RhinoApp.WriteLine("* * *")
            Rhino.RhinoApp.WriteLine("")

            Dim type1 = Type.GetTypeFromProgID("Rhino5.Application", True)
            'http://www.rhino3d.com/5/rhinoscript/introduction/external_access.htm

            Dim doc1
            doc1 = "C:\Program Files (x86)\Rhinoceros 4.0\Plug-ins\RhinoDeveloppements\RhinoBridges\ghx\PCRi_x64.ghx"

            Dim rhinoComObj As Object = Activator.CreateInstance(type1)
            rhinoComObj.Visible = True

            While rhinoComObj.IsInitialized() = 0
                Thread.Sleep(100)
            End While

            rhinoComObj.RunScript("_Grasshopper", 0)
            Dim gh As Object = rhinoComObj.GetPlugInObject("b45a29b1-4343-4035-989e-044e8580d9cf", "00000000-0000-0000-0000-000000000000")

            gh.OpenDocument(doc1)

            Return Rhino.Commands.Result.Success

        End Function

Thanks

- Giulio
________________
giulio@mcneel.com

If you add this code in the end, and point the above path to the attached file, you can test this sample.

gh.AssignDataToParameter("9de7f85f-7c54-4b36-be8c-af9ee0cf7168", "{1,2,3}") 'This is a point parameter
gh.RunSolver(True)

Thanks,

- Giulio
________________
giulio@mcneel.com

Attachments:

Giulio, thanks for your help,

Here my command in rhp plug-in

Hi simplify function for your comprehension.

Thanks a lot

Attachments:

Hi again

the code works here, and I need more information to understand what problem you are experiencing. Also, please, if this issue persists, would you start a new thread with the full explanation of what you are trying to do, any errors screenshots and a list of things you expect to happen?

Thanks,

- Giulio
__________________
giulio@mcneel.com

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service