New Skx Sub Forum

Moderator: Jim

New Skx Sub Forum

Postby Jim » Thu Jun 18, 2009 4:08 pm

This is the first post in a new Ruby Sub-Forum called "Skx Extension Library"

Skx is a project to create an extension library for SketchUp's Ruby API.

My original intention was simply to organize all of the code snippets floating around the Ruby forum and on my computer, to document them, and to make them available as a versioned package so other scripts could take advantage of them. That remains one of the primary goals.

To facilitate collaboration (another primary goal), I set up the skx project on Google Code. Google Code was a mostly arbitrary decision selected because that is what some other people were using (citygen, SketchyPhysics, surdebug and others).

This forum is for documenting the design process and related discussions.
0
Hi

Jim 
Global Moderator
 

Re: New Skx Sub Forum

Postby •BTM » Fri Jun 19, 2009 1:23 am

I might be able to help, but i've got a few questions like; can the snippets use variables other than just local variables (@close_point, etc.) ? If so, I've got a snippet called 'closest_point', that is used to find the closest point from an array of points, to the Point3d object ( a is a point3d object, b is an array of points. a.closest_point b). The issue is that it uses variables, and I don't know if they can or not. :?


Code: Select all
#  Created by •BTM on 16/06/09.
#

class Geom::Point3d
   def closest_point a
   point = self
      a.each do |e|
         if point != e
         dist = self.distance e
         @close_dist = dist if not @close_dist
            if dist <= @close_dist
            @close_dist = dist
            @close_point = e
            end
         end
      end
   return @close_point
   end
      
   
end
0
Last edited by Jim on Fri Jun 19, 2009 1:37 am, edited 1 time in total.
Reason: use [code] tags for blocks of code

•BTM 
PluginStore Author
PluginStore Author
 

Re: New Skx Sub Forum

Postby thomthom » Fri Jun 19, 2009 7:35 am

Code: Select all
class Geom::Point3d
   def closest_point a
      point = self
      close_dist = nil # just init the variable here first - this should work.
      close_point = nil
      a.each do |e|
         if point != e
         dist = self.distance e
         close_dist = dist if not close_dist
            if dist <= close_dist
            close_dist = dist
            close_point = e
            end
         end
      end
   return close_point
   end
end


If you initialise the variable before the loop you can use then inside the loop and after the loop.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: New Skx Sub Forum

Postby •BTM » Fri Jun 19, 2009 10:28 am

Ah, thanks :thumb:
0

•BTM 
PluginStore Author
PluginStore Author
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Skx Extension Library

Who is online

Users browsing this forum: No registered users and 1 guest

Visit our sponsors: