Site Tools


Unrolling Surfaces and Polysurfaces

Developer: RhinoScript
Summary: Demonstrates how to unroll surfaces and polysurfaces using RhinoScript.

Question

How can I script Rhino's UnrollSrf command using RhinoScript?

Answer

Currently, RhinoScript does not have a method that is equivalent to Rhino's UnrollSrf command. But, th following function will unroll surfaces and polysurfaces.

 ' 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

The following example script code demonstrates the use of the above function.

 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


developer/scriptsamples/unrollsrf.txt ยท Last modified: 2014/01/23 (external edit)