Grasshopper

algorithmic modeling for Rhino

Hi to all,

I know how to place a normal component by the InstantiateNewObject() Method, but I don't get it how to call a Panel or an other "Primitive" (like boolean, integer, number, ...)-Component.

Hope somebody can help me.

Nice greets

Alex

Views: 1443

Replies to This Discussion

The same way really, InstantiateNewObject() with either the GUID of a panel or a panel instance.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

So if I want to place a Panel at 0, 0 on the canvas the only thing I have to write is:

 Dim attachmentpoint As PointF
    attachmentpoint.X = 0
    attachmentpoint.Y = 0

    Instances.ActiveCanvas.InstantiateNewObject("59e0b89a-e487-49f8-bab8-b5bab16be14c", attachmentpoint, False)

But this does not work?! I don't know how to declare the GUID of the panel ?

PS: Or how can I declinate a Panel? There is no way to declare it as GH_Component, or?

PPS: Sorry, and how can I write something into the Panel from VB-Component?

"59e0b89a-e487-49f8-bab8-b5bab16be14c" is not a guid, it is a string. You have to actually pass in a guid, i.e.

Instances.ActiveCanvas.InstantiateNewObject( _

  New Guid("59e0b89a-e487-49f8-bab8-b5bab16be14c"), _

  New PointF(0,0), False)

 

There's an overload for InstantiateNewObject which accept an init_code, you can use this to set a content for panels:

Instances.ActiveCanvas.InstantiateNewObject( _

  New Guid("59e0b89a-e487-49f8-bab8-b5bab16be14c"), _

  "Some content string that will end up in the panel", _

  New PointF(0,0), False)

 

Ultimately, you could construct a GH_Panel beforehand, set all fields you want to set and use the InstantiateNewObject() overload which takes an IGH_DocumentObject instead of a Guid.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

PS: Or how can I declinate a Panel? There is no way to declare it as GH_Component, or?

A GH_Panel is not a GH_Component. It is in fact an IGH_Param. You can find (and construct) panels like this:

Dim panel As New Grasshopper.Kernel.Special.GH_Panel()

Once you have your panel, you can set properties and fill it with data.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

PPS: Sorry, and how can I write something into the Panel from VB-Component?

See attached.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

Good Morning David,

thank you for your fast replies. They helped a lot. Is it possible to change the size of the panel too?

Another small question. If I now want to place a bool Param on the canvas and fill it with true or false, how should I do that?

Dim bool As New Grasshopper.Kernel.Parameters.Param_Boolean
    bool.SetPersistentData(True)

    Instances.ActiveCanvas.InstantiateNewObject(bool.ComponentGuid, New PointF(0, 0), False)

This example doesn't work. How can I set True to the Param_Bool component? Is this also be done by the init_code in the InstantiateNewObject() or does this just except string?

Location and size of objects are maintained by the Attributes of the object. Adding new objects to the canvas during solution is a bit of a tricky business, which is why I had to schedule a solution inside the script:

owner.OnPingDocument().ScheduleSolution(0)

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

Thx for your help, but the vb-component in your gh-file makes an error.

in english:

Properties is no member of Grasshopper.Kernel.Special.GH_Panel (line 100)

Ah yes, that represents an SDK break in version 0.9.0015

You'll need to figure out what the appropriate calls are on 0.9.0014, and then unfortunately when 0.9.0015 arrives you'll need to change the code.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

And another problem.

As the Params are no components I can't get their outputs. How can I do that?

For example (with GH_Components):

Dim ghlastplacedcomp As GH_Component = actdoc.Objects.item(anzahlobj - 1)

          Dim ParamOutput As IGH_Param = ghlastplacedcomp.Params.Output(0)
          ParamInput.AddSource(ParamOutput)

Now how is this be done when the "ghlastplacedcomp" is a GH_Panel ?

GH_Panel is of type IGH_Param, so you can just call AddSource directly on the GH_Panel.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Sorry for beeing a pain in your neck..

But what do I make wrong??

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service