Grasshopper

algorithmic modeling for Rhino

Hi All,

I have a series of blocks with geometry on various different layers in a rhino file and I would like to select only geometry from within the blocks that is only on a certain layer. I've tried using the pipeline component but it looks like it ignores blocks.

So I started to write a vb node that is able to select the geometry that I want but it places it at the origin rather then in space where it is actually located in the rhino file. I've pasted the code below. 

Any help would be greatly appreciated. 

Dim LayTab As Rhino.DocObjects.Tables.LayerTable = rhinodocument.Layers


Dim blocks As rhino.DocObjects.Tables.InstanceDefinitionTable = rhinodocument.InstanceDefinitions

For i As Integer = 0 To blocks.Count - 1

     Dim block As Rhino.DocObjects.InstanceDefinition = blocks.item(i) 'get a single block
     Dim obj() As RhinoObject = block.GetObjects 'get the objects in the block


     For j As Integer = 0 To block.ObjectCount - 1
          Dim layIndex As Integer = obj(j).Attributes.LayerIndex 'get the layer index
          Dim lay As rhino.DocObjects.Layer = laytab.item(layindex) 'get the layer

          If obj(j).GetType.tostring = "Rhino.DocObjects.BrepObject" Then
               Dim rep As Brep = obj(j).DuplicateGeometry


               If lay.name = "Resi_Balcony" Then 'put the breps into their appropiate list
                    outbalcony.add(rep)
               Else If lay.Name = "Resi_slab" Then
                    outslab.add(rep)
               End If

          End If

     Next
Next

Cheers

[C]

Views: 2626

Replies to This Discussion

Hi Charles

you"ll have to get both, all the block instances and the block definitions in your file,

you can then get the objects in each definition and transform them to where all the block instances are.
(you can filter stuff by layer somewhere on the fly)

following script work on a component with no inputs  
change "Layer_XY" to your layername  

best Steffen

Private Sub RunScript(ByRef A As Object)


Dim LayerIX As Integer = RhinoDocument.Layers.Find("Layer_XY", True)

Dim GeoOutput As New List(Of GeometryBase)

Dim BlockInstanceList As List(Of RhinoObject) = RhinoDocument.Objects.FindByObjectType(ObjectType.InstanceReference).ToList
Dim BlockDefinitionList As Tables.InstanceDefinitionTable = RhinoDocument.InstanceDefinitions


For i As Integer = 0 To BlockDefinitionList.Count - 1

Dim Blockobjects As List(Of RhinoObject) = BlockDefinitionList(i).GetObjects().ToList


For j As Integer = 0 To BlockInstanceList.Count - 1

Dim Block As InstanceObject
Block = BlockInstanceList(j)
Dim XForm As Transform = Block.InstanceXform


For k As Integer = 0 To Blockobjects.Count - 1

'checks for the right layer
If Blockobjects(k).Attributes.LayerIndex = LayerIX Then

Dim objX As GeometryBase = Blockobjects(k).DuplicateGeometry
objX.Transform(XForm)
GeoOutput.Add(objX)

End If

Next

Next

Next

A = GeoOutput

End Sub

Thanks Steffen, with some minor edits it worked like a charm.

Cheers,

[C]

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