Grasshopper

algorithmic modeling for Rhino

Hi,

I would like to ask how to add Locator  for Kangaroo2 inside c# component correctly:

For now this does not work, but also does not make error:


      //Input Mesh
      //GH_ObjectWrapper output = new GH_ObjectWrapper((object) m);
      //GoalList.Add(new Locator(output));

I attache script with printscreen below.

Kind Regards,

Petras

Views: 603

Attachments:

Replies to This Discussion

Hello Petras,

You should not pass a Mesh object directly to "new GH_ObjectWrapper" as the Mesh will be ignored. The correct way to do it is to first construct a GH_Mesh object from the Mesh object, then pass the GH_Mesh to GH_ObjectWrapper.

GH_Mesh ghMesh = new GH_Mesh(m);

GH_ObjectWrapper ghObjectWrapper = new GH_ObjectWrapper(ghMesh);

GoalList.Add(new Locator(ghObjectWrapper));

or, condensing to only 1 line of code:

GoalList.Add(new Locator(new GH_ObjectWrapper(new GH_mesh(m))));

Dear Long Nguyen,

Thank you for a reply.

But there is a different issue.

If I just attach a Locator Goal from Kangaroo2 component itself I get the same behaviour.

No error but and Kangaroo stops working.

GoalList.Add((Locator) Show); //Is this a proper way to add Locator goal to goal list?

I attached the .gh file too.

Kind Regards,

Petras

Attachments:

Hello Petras

Two points: 

The first point is that, in my previous post, I forgot to call AssignPIndex for the Locator goal. Whenever you create a goal you always need to call AssignPIndex before starting the PhysicalSystem stepping. Normally the Kangaroo solver component does this for you automatically. But here you are creating your own solver (i.e. the so-called PhysicalSystem), hence you are responsible for calling AssignPIndex for EVERY goal being added to the PhysicalSystem yourself.

GH_Mesh ghMesh = new GH_Mesh(m);

GH_ObjectWrapper ghObjectWrapper = new GH_ObjectWrapper(ghMesh);

Locator locator = new Locator(ghObjectWrapper);

PS.AssignPIndex(locator, 0.001);

GoalList.Add(locator);

Now your mesh should be displayed correctly :)


The second point is that your GoalList.Add((Locator) Show) did not work because the casting (Locator) Show will fail. Because for some reason that I do not yet understand, the C# Script component treat the Locator class from the KangaroolSolver.dll as a different class from the Locator class of the Show object. I guess we need David Rutten's knowledge to explain this :)

 

Hello again Petras.

The second point I made above was due to my own mistake. Probably you do not have to worry about that. 

Anyway, getting the Locator goal from the show component should work fine. The only thing you were missing was, again, the AssignPIndex call

Locator locator = (Locator) Show;

PS.AssignPIndex(locator, 0.001);

GoalList.Add(locator);

I hope it will work for you

File attached :)

Attachments:

Dear Long Nguyen,

Thank you for a response and explanation.

I tried both options and they work fine (also casting of Locator).

Kind Regards,

Petras

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