The following short example demonstrates sampling a Scan&Solve solution on a uniform grid of points and writing the values to a text file.
For conciseness, this example contains minimal error checking.
Option Explicit
Call Main()
Sub Main()
Dim objSnSPlugIn, strObject, arrBox, dblSpacing, queryPt, dblValue
Dim objFSO, objFile, strFileLocation
Dim x, y, z
On Error Resume Next
Set objSnSPlugIn = Rhino.GetPluginObject("SnSScript")
objSnSPlugIn.SetOutputOnOff False
'Prompt for the output filename
strFileLocation = Rhino.SaveFileName("Output Filename", "*.txt", "", "RS_Output.txt", "txt")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not IsNull(strFileLocation) Then
Set objFile = objFSO.CreateTextFile(strFileLocation, True)
End If
'Prompt for the solid and the sample spacing
strObject = Rhino.GetObject("Select a solid")
dblSpacing = Rhino.RealBox("Sample spacing", 0.1, "Enter sample spacing")
If Not IsNull(strObject) Then
arrBox = Rhino.BoundingBox(strObject)
If IsArray(arrBox) Then
For z = arrBox(0)(2) To arrBox(6)(2) Step dblSpacing
For y = arrBox(0)(1) To arrBox(6)(1) Step dblSpacing
For x = arrBox(0)(0) To arrBox(6)(0) Step dblSpacing
queryPt = Array(x, y, z)
'Sample the solution at the specified point and write to a file
dblValue = objSnSPlugIn.QuerySolutionValue(strObject, "DSPT", queryPt)
If Not isNull(objFile) Then
objFile.WriteLine x & "," & y & "," & z & ":" & dblValue
Else
Rhino.Print x & "," & y & "," & z & ":" & dblValue
End If
Next
Next
Next
End If
End If
End Sub
| Line # | Description |
|---|---|
| 1 | Only scripts with Option Explicit specified can be debugged in the RhinoScript editor (Monkey). |
| 4-8 | Declare variables before use. |
| 11 | Obtain a reference to the SnSScript plug-in, exit if an error occurs. |
| 12 | Turn off SnSScript command line output. |
| 22 | Prompt the user to select a solid from the Rhino document. The solid is identified by its GUID stored in strObject. |
| 23 | Prompt the user for a sample spacing. |
| 26 | Obtain the bounding box for the object. |
| 28-30 | Three nested loops to cover the bounding box. |
| 31 | Construct the query point. |
| 32 | Query the solution value at the point. |
| 34-38 | Write the value to a file or the command line if the file is not open. |