Calling Methods from Installed Plugins

Hello,

I’ve created a plugin that creates a face and a path that I want to extrude the face along using the Eneroth Upright Extruder extension. I can use the extension easily enough from the Sketchup application, but I want to call the

self.extrude(extrusion, path, vectorUpright=nil)

method defined in the Eneroth Upright Extruder module(module Ene_uprightExtruder). I guessed that I could do something like this:

	for extension in Sketchup.extensions
		if "Eneroth Upright Extruder" == extension.name
			extension.extrude([], [])
		end
	end

but, I get the error

> Error: #<NoMethodError: undefined method `extrude' for #<SketchupExtension:0x7a2176c>>

when I execute my script from the Sketchup plugins menu. So SketchupExtension is not an instance of Ene_uprightExtruder. How do I get the instance, so that I can call the extrude method?

Thank You.

I think I’ve sorted this one out… I’m new to Ruby so I didn’t realize that methods could be called directly on modules. The solution was to require the model in my script:

require "ene_uprightExtruder.rb"

and then simply call the method like this:

Ene_uprightExtruder.extrude(face,path)

at least I think that will work.

When a method is defined within a (class or module) namespace and is prefixed with self., it means the method is to be a class method or module function respectively.

The ruby keyword self refers to the class or module during the definition load if it can be evaluated, or is actually within the body of a class method or module function.

The hard thing to understand is that in a class definition, any references to self within the bodies of instance method definitions, (which will be evaluated later after each instance gets instantiated,) will refer to the specific instance that owns it.

[quote=“rnistuk, post:1, topic:2156, full:true”]
So SketchupExtension is not an instance of Ene_uprightExtruder[/quote]

By now I’m sure you’re wondering why you ever thought it would be. :wink:

The SketchupExtension class instances are informational collections of properties (ie, a specification,) that helps developers distribute and control properties for plugins. And allows users to see the properties of, and toggle (on/off) the loading of extensions (via the Preferences dialog, Extensions panel.)

They themselves are not THE extension, but do load THE extension.

So Ene_uprightExtruder is an extension for SketchUp, that creates a SketchupExtension instance, to “publish” it’s properties so they can be displayed in the “Preferences” dialog > “Extensions” panel, and load the extension if it’s checked.

The Ruby world has a similar feature to it’s Gem class, which is a Gem::Specification. (But these are not integrated into the SketchUp “Preferences” dialog.