Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:addtorus [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Add Torus =====
 +
 +===== C# =====
 +<code c# addtorus.cs>​
 +public static Rhino.Commands.Result AddTorus(Rhino.RhinoDoc doc)
 +{
 +  const double major_radius = 4.0;
 +  const double minor_radius = 2.0;
 +
 +  Rhino.Geometry.Plane plane = Rhino.Geometry.Plane.WorldXY;​
 +  Rhino.Geometry.Torus torus = new Rhino.Geometry.Torus(plane,​ major_radius,​ minor_radius);​
 +  Rhino.Geometry.RevSurface revsrf = torus.ToRevSurface();​
 +  if (doc.Objects.AddSurface(revsrf) != Guid.Empty)
 +  {
 +    doc.Views.Redraw();​
 +    return Rhino.Commands.Result.Success;​
 +  }
 +  return Rhino.Commands.Result.Failure;​
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb addtorus.vb>​
 +Public Shared Function AddTorus(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result
 +  Const major_radius As Double = 4.0
 +  Const minor_radius As Double = 2.0
 +
 +  Dim plane As Rhino.Geometry.Plane = Rhino.Geometry.Plane.WorldXY
 +  Dim torus As New Rhino.Geometry.Torus(plane,​ major_radius,​ minor_radius)
 +  Dim revsrf As Rhino.Geometry.RevSurface = torus.ToRevSurface()
 +  If doc.Objects.AddSurface(revsrf) <> Guid.Empty Then
 +    doc.Views.Redraw()
 +    Return Rhino.Commands.Result.Success
 +  End If
 +  Return Rhino.Commands.Result.Failure
 +End Function
 +</​code>​
 +===== Python =====
 +<code python addtorus.py>​
 +import Rhino
 +import scriptcontext
 +import System.Guid
 +
 +def AddTorus():
 +    major_radius = 4.0
 +    minor_radius = 2.0
 +
 +    plane = Rhino.Geometry.Plane.WorldXY
 +    torus = Rhino.Geometry.Torus(plane,​ major_radius,​ minor_radius)
 +    revsrf = torus.ToRevSurface()
 +
 +    if scriptcontext.doc.Objects.AddSurface(revsrf)!=System.Guid.Empty:​
 +        scriptcontext.doc.Views.Redraw()
 +        return Rhino.Commands.Result.Success
 +    return Rhino.Commands.Result.Failure
 +
 +
 +if __name__=="​__main__":​
 +    AddTorus()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/addtorus.txt ยท Last modified: 2015/09/14 (external edit)