Create Section Plane Programmatically?

YES. Module variables are @@vars. They are global to the module that they are defined in, however they must be declared (created) before they are ever used as a method parameter or within any expression being evaluated. So it is good to init them at the top of a module. (I usual do so just below local constant definitions.) Ex:

module SoAndSo

  # boolean module var:
  @@save_settings = true unless defined?(@@save_settings)

  # non-boolean module vars:
  @@max_pages ||= 5
  @@my_color  ||= Sketchup::Color.new("Red")
  @@my_color_name ||= "red"

end

This works as long as the module is not used as a mixin module to modify classes, because then the @@var(s) would become shared class variables, which have have a weird global inherited shared behavior that can trip up the unwary.

You should not be. There are two ways to use them.

  1. What you might be missing is that, … because a module is an instance of class Module it can have instance (@var) variables unique to that module alone. The Class class is a subclass of class Module, which adds instantiation and automatic initialization behavior (to classes) that can be used to create and initialize instance (@var) variables. But you can also do it manually by creating a method definition (call it “init” or “setup” or “reset”, whatever) that initializes all the @vars for a module, and then as the last statement in the module body before it’s end keyword, call this custom “init” method and all the @vars will now exist.

  2. The other way is to write a class definition (inside your plugin sub-module) which holds state including what model the class’ instance was instantiated for. In this class scenario it is common to have a @model instance variable referencing the model. Not common yet on Windows because only 1 model is ever open, but more common on Mac where multiple models can be open at the same time, and the user can switch between them whenever they wish. (There is now an observer callback that can be used to know when the user switches models on the Mac.)


It sounds to me like you have not read all the basic introductory “primers” on all the Core Ruby index pages. They are the pages in the “doc” subfolders here (from globals on down) …
http://ruby-doc.org/core-2.2.4/index.html


Also see my learning Ruby helpers for all the downloadable and online books and tutorials. The stuff is free. Read it. Print out chapters and leave in the toilet as study material.


Lastly, the SketchUp team has example extension consisting of files for you to study. You should do this as well. (They are called “Example Scripts” and “Utilities Tools” and are on their page in the Extension Warehouse.)