Grasshopper

algorithmic modeling for Rhino

Hi Everyone;

Firstly thanks to everyone for always giving a hand, and to the great Mr Rutten for creating this wonderful tool.

But, I'm not only writing to show my gratitude, but as usual, to see if there is any help around :)

I'm trying to handle blocks in GH through scripting, I know there are plugins, but I prefer to learn to code these type of things.

Placing them in the document seems pretty straight forward, there are several threads here explaining how to do it. I used this one.

Dim blockTable As docobjects.Tables.InstanceDefinitionTable = doc.InstanceDefinitions
Dim block As docObjects.InstanceDefinition = blockTable.Find(BlockName, True)

Dim xform As Transform =Define whatever transformation you need here

A = doc.Objects.AddInstanceObject(block.Index, xform)

Where it gets trickier for me if when you're trying to extract the geometry from the block. The geometries inside them are Rhino.Geometry.InstanceReferenceGeometry. So basically a Goo object in GH which I cant use.

I found a script in this thread.

I edited it to find them by name not layer and put them in trees.

Private Sub RunScript(ByVal t As Boolean, ByVal BlockName As String, ByRef A As Object)

If T Then

Dim GeoOutput As New DataTree(Of GeometryBase)

'Gets all the blocks in the doc
Dim BlockInstanceList As List(Of RhinoObject) = RhinoDocument.Objects.FindByObjectType(ObjectType.InstanceReference).ToList

'Gets the block definitions
Dim BlockDefinitionList As Tables.InstanceDefinitionTable = RhinoDocument.InstanceDefinitions

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

'Gets the objects in the block, which are stored inside the block definitions table
Dim Blockobjects As List(Of RhinoObject) = BlockDefinitionList(i).GetObjects().ToList


'Goes through all the blocks
For j As Integer = 0 To BlockInstanceList.Count - 1

Dim Block As InstanceObject = BlockInstanceList(j)

'Checks to Select by the blocks name
If block.InstanceDefinition.Name = BlockName Then
Dim pthj As New GH_Path(j)


Dim XForm As Transform = Block.InstanceXform

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

Dim objX As GeometryBase = Blockobjects(k).DuplicateGeometry

objX.Transform(XForm)
GeoOutput.Add(objX, pthj)
Next

End If


Next


Next

A = GeoOutput
End If
End Sub

It works perfectly, but I don't understand the part where the geometry is extracted

It uses a transformation called InstanceXform which I'm not familiar with, and then it runs through the instance table applying it to extract the geometry.

If anyone is familiar with this part of the SDK any help would be greatly appreciated.

Also; this extracts the Geometry but not the base point of the block, I guess that lives somewhere else, but it is not easily accessible.

Thanks again for all the help

Views: 1755

Replies to This Discussion

Thank you

There are some plugins that you can use. If you tend to use the codes then you have to shift the programme towards the handling of the block in the c shifting. I will suggest you have the plugins as the plugins will save your time as well. I have also used the plugins and activated them by backing up on my email account. Sometimes I have to recover Gmail password to get the plugins files back.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service