Site Tools


Differences

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

Link to this comparison view

developer:scriptsamples:splitbrep [2015/09/14] (current)
Line 1: Line 1:
 +====== Scripting the Split Command ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //​Demonstrates how to script the Split command using [[developer:​rhinoscript|RhinoScript]].//​
 +
 +=====Question=====
 +Can someone tell me how to execute the Split command from RhinoScript?​ My problem is that I do not know how to pass the object and the cutting plane to the Split command.
 +
 +=====Answer=====
 +Consider the following example function:
 +
 +<code vb>
 +Function DoBrepSplit(brep,​ cutter)
 +
 +   '​ Declare local variables
 +   Dim saved, cmd
 +
 +   '​ Set default return value  ​
 +   ​DoBrepSplit = Null
 +
 +   '​ For speed, turn of screen redrawing
 +   ​Rhino.EnableRedraw False
 +
 +   '​ Save any selected objects
 +   saved = Rhino.SelectedObjects
 +
 +   '​ Unselect all objects
 +   ​Rhino.UnSelectAllObjects
 +
 +   '​ Select the brep
 +   ​Rhino.SelectObject brep
 +
 +   '​ Script the split command
 +   cmd = "​_Split _SelID " & cutter & " _Enter"​
 +   ​Rhino.Command cmd, 0
 +
 +   '​ By preselecting the brep, the results of 
 +   '​ Split will be selected. So, get the selected ​
 +   '​ objects and return them to the caller.
 +   ​DoBrepSplit = Rhino.SelectedObjects
 +
 +   '​ Unselect all objects
 +   ​Rhino.UnSelectAllObjects
 +
 +   '​ If any objects were selected before calling
 +   '​ this function, re-select them
 +   If IsArray(saved) Then Rhino.SelectObjects(saved)
 +
 +   '​ Don't forget to turn redrawing back on
 +   ​Rhino.EnableRedraw True
 +
 + End Function
 +
 +</​code>​
 +The function above can be test using the following simple subroutine:
 +
 +
 +<code vb>
 + Sub TestSplitBrep
 +
 +  ' Declare local variables
 +   Dim brep, cutter, pieces, i
 +
 +   '​ Pick the brep to split
 +   brep = Rhino.GetObject("​Select surface or polysurface to split",​ 8 + 16)
 +   If IsNull(brep) Then Exit Sub
 +
 +   '​ Pick the cutting brep
 +   ​cutter = Rhino.GetObject("​Select cutting or polysurface to split",​ 8 + 16)
 +   If IsNull(cutter) Then Exit Sub
 +
 +   '​ Call our special splitter ​   ​
 +   ​pieces = DoBrepSplit(brep,​ cutter)
 +   If IsArray(pieces) Then
 +     For i = 0 To UBound(pieces)
 +       ​Rhino.Print pieces(i)
 +     Next
 +   End If
 +
 + End Sub
 +
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/splitbrep.txt ยท Last modified: 2015/09/14 (external edit)