Site Tools


Differences

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

Link to this comparison view

developer:scriptsamples:cutplane [2015/09/14] (current)
Line 1: Line 1:
 +====== Scripting the CutPlane Command ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //​Demonstrates how to script the CutPlane command using RhinoScript.//​
  
 +=====Question=====
 +Can someone tell me how to execute the CutPlane command from RhinoScript?​
 +
 +=====Answer=====
 +Consider the following example function:
 +
 +<code vb>
 + ​Function CreateCutPlane(objs,​ p0, p1)
 +
 +   '​ Declare local variables
 +   Dim saved, s0, s1, cmd
 +
 +   '​ Set default return value  ​
 +   ​CreateCutPlane = Null
 +
 +   '​ For speed, turn of screen redrawing
 +   ​Rhino.EnableRedraw False
 +
 +   '​ Save any selected objects
 +   saved = Rhino.SelectedObjects
 +
 +   '​ Unselect all objects
 +   ​Rhino.UnSelectAllObjects
 +
 +   '​ Select the objects to create the cut plane through
 +   ​Rhino.SelectObjects objs
 +
 +   '​ Script the cutplane command
 +   s0 = Rhino.Pt2Str(p0,,​True)
 +   s1 = Rhino.Pt2Str(p1,,​True)
 +   cmd = "​_CutPlane " & s0 & s1 & "​_Enter"​
 +   ​Rhino.Command cmd, 0
 +
 +   '​ Get the object created by CutPlane
 +   ​CreateCutPlane = Rhino.FirstObject
 +
 +   '​ 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 TestCutPlane
 +
 +   '​ Declare local variables
 +   Dim objs, p0, p1, obj
 +
 +   '​ Pick the objects to cut
 +   objs = Rhino.getobjects("​Select objects for cut plane"​)
 +   If Not IsArray(objs) Then Exit Sub
 +
 +   '​ Pick start of cut plane    ​
 +   p0 = Rhino.GetPoint("​Start of cut plane"​)
 +   If Not IsArray(p0) Then Exit Sub
 +
 +   '​ Pick end point of cut plane    ​
 +   p1 = Rhino.GetPoint("​End of cut plane",​ p0)
 +   If Not IsArray(p1) Then Exit Sub
 +
 +   '​ Call our function ​   ​
 +   obj = CreateCutPlane(objs,​ p0, p1)
 +   If Not IsNull(obj) Then
 +     ​Rhino.Print obj
 +   End If
 +
 + End Sub
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer RhinoScript}}
developer/scriptsamples/cutplane.txt ยท Last modified: 2015/09/14 (external edit)