Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:unrollsrf [2015/09/14] (current)
Line 1: Line 1:
 +====== Unrolling Surfaces and Polysurfaces ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //​Demonstrates how to unroll surfaces and polysurfaces using RhinoScript.//​
 +
 +=====Question=====
 +How can I script Rhino'​s **UnrollSrf** command using RhinoScript?​
 +
 +=====Answer=====
 +Currently, [[developer:​rhinoscript|RhinoScript]] does not have a method that is equivalent to Rhino'​s **UnrollSrf** command. But, th following function will unroll surfaces and polysurfaces.
 +
 +<code vb>
 + '​ Description:​
 + ' ​  ​Unroll a surface or polysurface.
 + '​ Parameters:
 + ' ​  ​strSurface - String, The identifier of the surface or polysurface to unroll.
 + ' ​  ​arrCurves ​ - Array, The identifiers of one or more curves to unroll.
 + ' ​  ​blnExplode - Boolean, Explode the resulting objects.
 + ' ​  ​blnLabels ​ - Boolean, Label the resulting objects with numbered dots.
 + '​ Returns:
 + ' ​  ​Array,​ The identifiers of the unrolled objects if successful.
 + ' ​  Null on error
 +
 + ​Option Explicit
 +
 + ​Function RhinoUnrollSurface(strSurface,​ arrCurves, blnExplode, blnLabels)
 +
 +   '​ Default return value  ​
 +   ​RhinoUnrollSurface = Null
 +
 +   '​ For speed, turn of screen redrawing
 +   Call Rhino.EnableRedraw(False)
 +
 +   '​ Save any selected objects
 +   Dim arrSaved : arrSaved = Rhino.SelectedObjects
 +
 +   '​ Unselect all objects
 +   ​Rhino.UnSelectAllObjects
 +
 +   '​ Select the surface to unroll
 +   ​Rhino.SelectObject strSurface
 +
 +   '​ Format curve string
 +   Dim i : i = 0
 +   Dim strCurves
 +   If IsArray(arrCurves) Then
 +     For i = 0 To UBound(arrCurves)
 +       ​strCurves = strCurves & " _SelId " & arrCurves(i)
 +     Next
 +     ​strCurves = strCurves & " _Enter"​
 +   End If
 +
 +   '​ Format explode string
 +   Dim strExplode : strExplode = " _Explode=_Yes"​
 +   If (blnExplode = False) Then strExplode = " _Explode=_No"​
 +
 +   '​ Format labels string
 +   Dim strLabels : strLabels = " _Labels=_No"​
 +   If (blnLabels = True) Then strLabels = " _Labels=_Yes"​
 +
 +  ' Script the command
 +   Dim strCommand : strCommand = "​_-UnrollSrf"​ & strExplode & strLabels & strCurves
 +   Call Rhino.Command(strCommand,​ 0)
 +
 +   '​ Return the results
 +   ​RhinoUnrollSurface = Rhino.LastCreatedObjects
 +
 +   '​ Unselect all objects
 +   ​Rhino.UnSelectAllObjects
 +
 +   '​ If any objects were selected before calling
 +   '​ this function, re-select them
 +   If IsArray(arrSaved) Then Rhino.SelectObjects(arrSaved)
 +
 +   '​ Don't forget to turn redrawing back on
 +   Call Rhino.EnableRedraw(True)
 +
 + End Function
 +</​code>​
 +
 +The following example script code demonstrates the use of the above function.
 +
 +<code vb>
 + Sub TestRhinoUnrollSurface()
 +
 +   Dim strSurface : strSurface = Rhino.GetObject("​Select surface or polysurface to unroll",​ 8 + 16)
 +   If IsNull(strSurface) Then Exit Sub
 +
 +   Dim strPrompt : strPrompt = "​Select curves on polysurface to unroll"​
 +   If Rhino.IsSurface(strSurface) Then strPrompt = "​Select curves on surface to unroll"​
 +
 +   Dim arrCurves : arrCurves = Rhino.GetObjects(strPrompt,​ 4)
 +
 +   Dim i, arrResults : arrResults = RhinoUnrollSurface(strSurface,​ arrCurves, True, False)
 +   If IsArray(arrResults) Then
 +     For i = 0 To UBound(arrResults)
 +       Call Rhino.Print(arrResults(i))
 +     Next
 +   End If
 +
 + End Sub
 +
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/unrollsrf.txt ยท Last modified: 2015/09/14 (external edit)