Grasshopper

algorithmic modeling for Rhino

Hi everyone,

I am trying to script Karamba in IronPython with GhPython. New to it. I am having a few issues starting with this one:

I cannot find the way to output the correct Karamba type. The consistent error I get when calling Karamba via node-in-code or via the Karamba Assembly:

Data conversion failed from Goo to Element

Data conversion failed from Goo to Model

and so on.

Attached is a file comparing an IronPython attempt to translate the Karamba GH component MeshToShell. Note: To run the script, karamba.gha should be located in the same folder.

How can I unwrap Goo and output the correct Karamba type?

Also, I could not find yet good examples of Karamba implementations in IronPython besides the one included in the Hackers Guide 1.1.0 -which does not go through all the steps needed for a simple analysis-. It would be great to know if there is any limitation that I should be aware of while trying to script Karamba this way.

Thank you!

Inés

Views: 723

Attachments:

Replies to This Discussion

I wonder if Karamba.Utilities.ToGH or FromGH can help somehow? I gave it a try with no luck:

import clr
clr.AddReferenceToFile("karamba.gha")
import Karamba.Elements as kElements
import Karamba.Models as kModels
import Karamba.Utilities as kUtil

elemShellAssembly = kElements.GrassShell(mesh)

listElem = []
listElem.append(elemShellAssembly)

print type(listElem)

print type(listElem[0])

newElem = kUtil.ToGH.Values(listElem)

Which raises this exception:

<type 'list'>
<type 'GrassShell'>
Runtime error (ArgumentTypeException): expected List[Curve], got list
Traceback:
line 23, in script

Which brings 2 more questions:

- Is this exception a miscommunication between C# List and IronPython list?

- Since .ToGH allows .Values(List<GrassShell>), why it looks for a List[Curve]?

Lost here. Any hint would be greatly appreciated!!

Inés

File!

Attachments:

Dear Inés,

sorry for my late reply - I was on holiday.

One has to wrap the 'GrassShell'-object in a Grasshopper wrapper object - 'GH_Element' in this case (see attached definition).

For each Karamba object which can float around in a GH definition there is a corresponding GH_... object.

You can use most Karamba components directly in your code: the GUI-components are named e.g. 'Component_MeshToShell_GUI'. The work is done in static methods - e.g. 'public static void solve(List<Point3d> in_nodes, List<Mesh> in_meshes, double limit_dist, List<String> in_ids, List<Color> in_colours, out List<Point3d> out_points, out List<GrassShell> out_shells, out String info)' of the class 'Component_MeshToShell'.

The C# part of Karamba can be decompiled using e.g. ILSpy (which is free). With this tool you can see how the Karamba components perform their work.

Best,

Clemens

Attachments:

Karamba.Utilities.ToGH is used to create the GH-wrappers about the items of a list, FromGH removes them (see attached file).

Best,

Clemens

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