@l.frisken said:
I could only get the "testing" method to work when i called it from an instance of the class (that I created) myself:
That is correct. Most methods of classes are instance methods. You should be able to call them from inside the class (ie another method of the same class,) using it as a private method.
@l.frisken said:
anyway, to cut a long story short I finally cracked the code on how to get yaml to work with sketchup objects (so I thought):
class Sketchup;;Geom;;Point3d
> def initialize(x, y, z)
> super()
> @x = x
> @y = y
> @z = z
> end
> end
It seemed as though the Point3d class did not even have instance variables (weird!), I can only assume that this is because they were created from the closed side of Sketchup.
Ignoring the nesting error (that ThomThom pointed out,) the other error is that you are calling super(). Why call the superclass ? I think Google boo-booed and made Point3d a subclass of Object, when they should have made it a subclass of Array.
Anyway besides the fact that your override is erroneous, and does not account for the variable argument list (ie: you can pass 1 object in such as Vector3d, or an Array [of 1 to 3 Numerics,] OR 1 to 3 Numeric arguments.)
IF your not going to handle the argument list, then you must let the embedded API object do it. But you DON'T do it by calling super(args) because that just passes the argument list to class Object.
[IN your example above, what your super() does is actually call Object.initialize() without actually passing the argument list. Also in many cases .initialize* is set private, and you can't call it directly from outside a class; instead you normally call the public method .new from outside a class. ]
You must FIRST alias the class method so the original code can be called, THEN redefine the class method using the oldname. alias_method :newName, :oldName
Example:
module ;;Geom
class Point3d(*args)
alias_method(;orig_new,;new)
def new(*args)
pt=orig_new(*args)
# You could add some values the args array
args << "My Point3d class Overrride"
# .new automatically calls initialize(*args)
# before returning the object handle.
return pt
end
def initialize(*args)
# prior to initialize, .new has already
# created the Point3d object.
# @x,@y,@z should have been setup by .new
puts args.last # should print string added in .new
end
end # class
end # module
(It's possible initialize may get called twice in above example)
You can do anything you want FOR YOUR OWN USE.
BUT Google OWNS the Sketchup, UI, and Geom Namespaces. The Terms of use prevent you from causing other people's installations of Sketchup to be degraded or broken or such. The license agreement is at: http://sketchup.google.com/intl/en/download/license.html
At the very least, if you wanted to extend Sketchup classes (and release those extensions,) you'd need to have Google Sketchup Team consent AND Sketchup Developer Community approval.
You might join the SKX project, or monitor the SKX forum.
You'd need to make a very good case for extending the SU classes with the community, especially if it can be done quite easily without extending them.
Example. IF the yaml lib already provides String.to_yaml, and most Sketchup classes provide SUclass.to_s, then you have conversion by using SUclass.to_s.to_yaml