<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Code] Scarpino&#x27;s SphereUtil Sample ver 1.1.0]]></title><description><![CDATA[<p dir="auto">Here's slightly modified sphere drawing code from:<br />
<a href="http://forums.sketchucation.com/viewtopic.php?f" target="_blank" rel="noopener noreferrer nofollow ugc">[ Code ] Scarpino's SphereTool Sample</a></p>
<p dir="auto">This edition is a combo Library &amp; Mixin module.</p>
<p dir="auto">ver 1.0.0</p>
<ul>
<li>
<p dir="auto">initial posting (not tested)<br />
<strong>ver 1.1.0</strong></p>
</li>
<li>
<p dir="auto">draw_group() method: fixed call to draw()<br />
4th arg was passing a group object, instead of an entities object.</p>
</li>
</ul>
<pre><code># ---------------------------------------------------------
# file ; 'sphereutil.rb'
# by   ; Dan Rathbun
# ---------------------------------------------------------
# Example of combo Library/Mixin module, sphere utilities.
#  based on draw code from SphereTool example...
#  from "Automatic SketchUp" by Matthew Scarpino, pg 260.
# ---------------------------------------------------------
# Versions;
#
#   1.0.0  ;  02-09-2012
#
#   1.1.0  ;  02-10-2012
#          ~ draw_group() method; fixed call to draw()
#            4th arg now; sgrp.entities, was; sgrp.
#
# ---------------------------------------------------------

require('sketchup.rb')
 
module Scarpino  # &lt;-- Author's namespace

  module SphereUtil # &lt;-- plugin namespace
  
    ### CONSTANTS
    #
    VERSION = '1.1.0'

    # make the following methods work as library functions
    # and as instance methods when this module is mixed-in.
    module_function

    #  draw()
    #
    #  Args;
    #  center,    # [Geom;;Point3d] The sphere's center point.
    #  size = 1,  # if [Numeric] then the length of the radius,
    #             #   if [Geom;;Point3d] a point on the surface.
    #  segs = 24, # [Integer] number of segments used for surface.
    #  ents = Sketchup.active_model.active_entities, # [Entities]
    #  mod  = Sketchup.active_model  # [Sketchup;;Model]
    #
    #  Returns an array of entities belonging to the new sphere.
    #
    def draw(center, size=1, segs=24,
                  ents = Sketchup.active_model.active_entities,
                  mod  = Sketchup.active_model
                 )
      before = ents.to_a
      segs = segs.to_i
      # Draw the circles
      begin
        mod.start_operation('Draw Sphere')
          #
          if size.is_a?(Numeric)
            rad = size
          else
            rad = center.distance( size )
          end
          circle = ents.add_circle( center.position, [1, 0, 0], rad, segs )
          path = ents.add_circle( center.position, [0, 1, 0], rad + 1, segs )
          circle_face = ents.add_face( circle )
          # Extrude the sphere and erase the extrusion path
          circle_face.followme( path )
          ents.erase_entities( path )
          #
        mod.commit_operation
      rescue
        mod.abort_operation
        return nil
      else
        before - ents.to_a
      end
    end


    #  draw_group()
    #
    #  Args;
    #  center,    # [Geom;;Point3d] The sphere's center point.
    #  size = 1,  # if [Numeric] then the length of the radius,
    #             #   if [Geom;;Point3d] a point on the surface.
    #  segs = 24, # [Integer] number of segments used for surface.
    #  ents = Sketchup.active_model.active_entities, # [Entities]
    #  mod  = Sketchup.active_model
    #
    #  Returns a new group object enclosing the new sphere,
    #  within the given entities context.
    #
    def draw_group(center, size=1, segs=24,
                  ents = Sketchup.active_model.active_entities,
                  mod  = Sketchup.active_model
                 )
      sgrp = ents.add_group
      ret = draw(center,size,segs,sgrp.entities,mod)
      if ( ret.nil? || ret==[] ) &amp;&amp; sgrp.entities.length==0
        sgrp.entities.clear!
        ents.erase_entities( sgrp )
      else
        return sgrp
      end
    end


    ### RUN ONCE
    #
    unless file_loaded?(File.basename(__FILE__))
      file_loaded(File.basename(__FILE__))
    end

  end # module SphereUtil
end # module Scarpino
</code></pre>
]]></description><link>https://community.sketchucation.com/topic/133196/code-scarpino-s-sphereutil-sample-ver-1-1-0</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 06:25:56 GMT</lastBuildDate><atom:link href="https://community.sketchucation.com/topic/133196.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Feb 2012 22:26:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Code] Scarpino&#x27;s SphereUtil Sample ver 1.1.0 on Fri, 10 Feb 2012 08:41:08 GMT]]></title><description><![CDATA[<p dir="auto">Fixed a small booboo (see the docheader in file.)</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/john" aria-label="Profile: John">@<bdi>John</bdi></a>.. perhaps a good example tool, to make a path, might be a modified edition of the "Examples/linetool.rb"</p>
]]></description><link>https://community.sketchucation.com/post/1309413</link><guid isPermaLink="true">https://community.sketchucation.com/post/1309413</guid><dc:creator><![CDATA[Dan Rathbun]]></dc:creator><pubDate>Fri, 10 Feb 2012 08:41:08 GMT</pubDate></item><item><title><![CDATA[Reply to [Code] Scarpino&#x27;s SphereUtil Sample ver 1.1.0 on Thu, 09 Feb 2012 22:38:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/driven" aria-label="Profile: driven">@<bdi>driven</bdi></a> said:</p>
<blockquote>
<p dir="auto">With Mat's help, I attempted to have this one  work along the user drawn axis, so you could e.g. create a string of pearls.</p>
<p dir="auto">Could you add or suggest how that could be done?</p>
</blockquote>
<p dir="auto">I would suppose you would write a loop of some kind and call the lib methods <strong>x</strong> number of times, using the same radius, but incrementing the center point within the loop (2 * rad ?). The result would be a line of spheres.</p>
<p dir="auto">If you wished to write a <code> Tool</code>, where the user draws the path, you can mix in the methods using:</p>
<pre><code>module Driven
  class PearlPathTool

    require('Scarpino/sphereutil.rb')
    include(Scarpino;;SphereUtil)

    # now your tool has the mixin's methods

  end#class
end
</code></pre>
]]></description><link>https://community.sketchucation.com/post/1309336</link><guid isPermaLink="true">https://community.sketchucation.com/post/1309336</guid><dc:creator><![CDATA[Dan Rathbun]]></dc:creator><pubDate>Thu, 09 Feb 2012 22:38:57 GMT</pubDate></item></channel></rss>