Monday, July 26, 2010

Run RhinoScript in C# component in Grasshopper

To run a Rhinoscript in C# component in Grasshopper:

for example:
RMA.Rhino.RhUtil.RhinoApp().RunScript("-_Render");

Thursday, July 15, 2010

Sun Path

Sunpath Diagrams: DayLighting

image after SunPath Diagram


Live Architecture Network:Sun angle calculation and visualization

Irregular Grid

Think about the following examples from GH3D:








GH3D Links:
1. unevenly-divided-surface
2. irregular-diagrid

Switch UV coordinates

GH3D Link:
http://www.grasshopper3d.com/forum/topics/switch-uv-coordinates

1. Scripting:
If srf Is Nothing Then
Return
End If
srf.Transpose()
A = srf

2. using component:

GH2Revit, Digital Project

original GH3D link: export-to-digital-project
http://www.grasshopper3d.com/forum/topics/export-to-digital-project

Grasshopper3d to Autodesk Robot - CableNet:
http://www.geometrygym.blogspot.com/

from GH to Revit via CSV file:
http://theprovingground.wikidot.com/revit-csv

Generate Multiple tree Paths dynamically




GH versions (0.6.0059):

dynamaxtion.ghx
dynamaxtion2.ghx

Image data from Viewport

Link : http://www.grasshopper3d.com/forum/topics/how-to-get-the-image-data-such

Private Sub RunScript(ByRef A As Object)
RMA.Rhino.RhUtil.RhinoApp().RunScript("-_ViewCaptureToClipboard _Enter")

Dim img As Image = Windows.Forms.Clipboard.GetImage()

Dim bmp As New Bitmap(20, 20, Imaging.PixelFormat.Format24bppRgb)
Dim grp As Graphics = Graphics.FromImage(bmp)
grp.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
grp.DrawImage(img, 0, 0, 20, 20)

Dim R As int32 = 0
Dim G As int32 = 0
Dim B As Int32 = 0

For i As Int32 = 0 To bmp.Width - 1
For j As Int32 = 0 To bmp.Height - 1
Dim col As Color = bmp.GetPixel(i, j)
R += col.R
G += col.G
B += col.B
Next
Next

R = Convert.ToInt32(R / 400)
G = Convert.ToInt32(G / 400)
B = Convert.ToInt32(B / 400)

A = Color.FromArgb(R, G, B)
End Sub


Screen Capture a Viewport
http://wiki.mcneel.com/developer/sdksamples/screencaptureview

Disable Customized Component Preview

In the constructor of the component, set the Hidden property to True.

C#:
public Component_Name()
  : base("BlahBlahBlah", "Blah", "Life is visceral.", "Cat", "Pan")
  {
    this.Hidden = true;
  }

Link: http://www.grasshopper3d.com/forum/topics/component-disabled-preview

Data Tree

have a look in these two examples - they show how to read or make a tree. Like Thomas is saying, you will need the component from here to open the file correctly.

Attachments: gh-trees.ghx, 61 KB

Contour component with paths

GH3D links: http://www.grasshopper3d.com/forum/topics/suggestion-contour-component

Private Sub RunScript(ByVal S As OnGeometry, ByVal G As Double, ByVal D As OnLine, ByVal L As Boolean, ByRef C As Object, ByRef P As Object)

If S IsNot Nothing AndAlso G > 0 Then
Dim continp As New MRhinoContourInput
Dim GeoArr(0) As OnGeometry
GeoArr(0) = S

continp.m_geom = GeoArr
continp.m_interval = G
If D IsNot Nothing Then
continp.m_basept = D.from
continp.m_endpt = D.To
Else
continp.m_basept = New On3dPoint(0, 0, 0)
continp.m_endpt = New On3dPoint(0, 0, 1)
End If
continp.m_limit_range = L
continp.m_JoinCurves = 1

Dim Crvs() As OnCurve = Nothing
Dim pline() As OnPolyline = Nothing
Dim pts As ArrayOn3dPoint = Nothing

Dim check As New Boolean
check = RhUtil.MakeRhinoContours(continp, pline, Crvs, pts)
If check Then
C = Crvs
P = pline
Else print("Contour Failed. SDK function returned an Error.")
End If
Else print("Invalid/Null Input(s)")
End If
End Sub

objects by Layers


GH3D links:

more can be found : Rhino .NET Framework SDK



Bake object to specific layers:

Private Sub RunScript(ByVal obj As Brep, ByVal lay As String, ByVal col As Color, ByRef A As Object)
 Dim lay_index As Int32 = doc.Layers.Find(lay, True)
 If (lay_index < 0) Then
  lay_index = doc.Layers.Add(lay, col)
 End If

 Dim att As New DocObjects.ObjectAttributes()
 att.LayerIndex = lay_index

 A = doc.Objects.AddBrep(obj, att)
End Sub