Grasshopper

algorithmic modeling for Rhino

Hi there,
I'm trying to input a tree (containing a mix of lines, meshes, etc) into my component,
then get all the points from this geometry,
move them to new positions,
and recreate the original geometry but with the updated positions,
then finally output the new geometry in the same Tree structure as it came in.
I got as far as registering a GeometryParam, with ParamAccess.tree, but am not sure how to proceed with getting all the individual items from this.
Any pointers on the best way to go about this would be greatly appreciated.
Thanks,
Daniel

Views: 1229

Replies to This Discussion

Hey Dan,

Here's the approach using the branched index map that I mentioned. It just requires that each geometry has a dedicated path to place it's points prior to flattening and removing duplicates. The rebuilt tree should be identical to the input so as long as the incoming assorted geometry is organized by type, you can be as specific as you like with rebuilding certain geometries.


Attachments:

Hi David,

 

Sorry, I should have specified - I'm talking about a compiled component.

So I'm looking particularly for examples of how to use DA.GetDataTree

 

Thanks anyway for the quick reply

oops. i completely missed the "custom component" part of the discussion title. i'll blame astigmatism.

Dim data As Data.GH_Structure(Of IGH_GeometricGoo) = Nothing

If (Not DA.GetDataTree(0, data)) Then Return

 

This should give you a tree with data types that implement IGH_GeometricGoo. These could for example be GH_Point, GH_Mesh, GH_Brep, and possibly even (in rare cases) GH_GeometricGooWrapper.

 

I think you can just compare every item type to GH_Point, then cast it and change the location.

 

btw. When you get a GH_Structure out of a parameter, you get a pointer to the *actual* data stored inside the param. So any changes made to the tree will propagate upstream. This is a bad thing. If you intend to change the tree, you should copy it first.

 

data = data.ShallowDuplicate()

 

Then iterate over all branches and items to modify your points:

 

For Each branch As List(Of IGH_GeometricGoo) In tree.Branches

For i As Int32 = 0 To branch.Count - 1

If (branch(i) Is Nothing) Then Continue For

If (TypeOf branch(i) Is GH_Point) Then

Dim pt As GH_Point = DirectCast(branch(i), GH_Point)

pt = New GH_Point(pt.Value + Rhino.Geometry.Vector3d.ZAxis)

branch(i) = pt

End If

Next

Next

 

--

David Rutten

david@mcneel.com

Delft, NL

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service