Site Tools


Differences

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

Link to this comparison view

developer:scriptsamples:offsetmeshsolidify [2015/09/14] (current)
Line 1: Line 1:
 +====== Offsetting Meshes ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //​Demonstrates how to offset and solidify a mesh.//
  
 +=====Question=====
 +I am writing a RhinoScript that should generate a closed mesh as a result of a base mesh and an offset. Rhino'​s **OffsetMesh** does this task very well if you use the **solidify** option. RhinoScript'​s **MeshOffset** function does not have this option. How can I create a solid mesh with RhinoScript?​
 +
 +=====Answer=====
 +You are correct - RhinoScript'​s **MeshOffset** function does not have a **solidify** option. Until it does, you can accomplish what you want by simply scripting Rhino'​s **OffsetMesh** command, instead of calling RhinoScript'​s **MeshOffset** function.
 +
 +=====Example=====
 +The following example function will offset a mesh by scripting Rhino'​s **OffsetMesh** command.
 +
 +<code vb>
 +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''​
 +' Offset and solidify a mesh object
 +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''​
 +Function OffsetMeshSolidify(strMesh,​ dblDistance)
 +  ​
 +  ' Declare local variables
 +  Dim arrSaved, strCommand
 + 
 +  ' Save any selected objects
 +  arrSaved = Rhino.SelectedObjects
 + 
 +  ' Unselect all objects
 +  Rhino.UnSelectAllObjects
 + 
 +  ' Select the mesh
 +  Call Rhino.SelectObject(strMesh)
 + 
 +  ' Script the OffsetMesh command
 +  strCommand = "​_-OffsetMesh _CapMeshes=_Yes " & CStr(dblDistance) & " _Enter"​
 +  Call Rhino.Command(strCommand,​ 0)
 + 
 +  ' Get the results of the command
 +  If Rhino.LastCommandResult = 0 Then
 +    OffsetMeshSolidify = Rhino.LastCreatedObjects()(0)
 +  Else
 +    OffsetMeshSolidify = Null
 +  End If
 + 
 +  ' Unselect all objects
 +  Rhino.UnSelectAllObjects
 + 
 +  ' If any objects were selected before calling
 +  ' this function, re-select them
 +  If IsArray(arrSaved) Then Rhino.SelectObjects(arrSaved)
 +  ​
 +End Function
 +</​code>​
 +
 +=====Test=====
 +You can test the above function with the following code.
 +<code vb>
 +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''​
 +' This procedure tests the OffsetMeshSolidify function
 +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''​
 +Sub TestOffsetMeshSolidify()
 +  ​
 +  ' Declare local constants and variables
 +  Const rhMesh = 32
 +  Dim strMesh, dblDistance,​ strOffset
 +  ​
 +  ' Select a mesh to offset
 +  strMesh = Rhino.GetObject("​Select mesh to offset",​ rhMesh, True)
 +  If IsNull(strMesh) Then Exit Sub
 +    ​
 +  ' Get the offset distance
 +  dblDistance = Rhino.GetReal("​Offset distance",​ 1.0)
 +  If IsNull(dblDistance) Then Exit Sub
 +  If (dblDistance = 0.0) Then Exit Sub
 +  ​
 +  ' Call our mesh offsetting function...
 +  strOffset = OffsetMeshSolidify(strMesh,​ dblDistance)
 +    ​
 +End Sub
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer RhinoScript}}
developer/scriptsamples/offsetmeshsolidify.txt ยท Last modified: 2015/09/14 (external edit)