Cant install extention

Good day.
I am just a beginner in sketchup aip. but now i have some trobles. I cant install from extention manager
Door1TestOB.zip (1.1 KB)

  • loader file
require 'sketchup.rb'
require 'extensions.rb'

module Door1TestOB
  loader_path = File.join(File.dirname(__FILE__), 'Door', 'main.rb')
  ex = SketchupExtension.new('Create Window Example', loader_path)
  Sketchup.register_extension(ex, true)
end

door (main file)
require 'sketchup.rb'

module Door1TestOB
  module Door

    def self.create_window
      model = Sketchup.active_model
      model.start_operation('Create Window', true)
      
      entities = model.entities

      window_group = entities.add_group
      window_entities = window_group.entities

      window_width = 40.0
      window_height = 80.0
      frame_thickness = 3.0

      outer_frame_points = [
        [0, 0, 0],
        [window_width + frame_thickness * 2, 0, 0],
        [window_width + frame_thickness * 2, window_height + frame_thickness, 0],
        [0, window_height + frame_thickness, 0]
      ]

      outer_face = window_entities.add_face(outer_frame_points)

      inner_frame_points = [
        [frame_thickness, 0, 0],
        [window_width + frame_thickness, 0, 0],
        [window_width + frame_thickness, window_height, 0],
        [frame_thickness, window_height, 0]
      ]

      inner_face = window_entities.add_face(inner_frame_points)

      inner_face.erase!

      outer_face.pushpull(-0.5.inch)

      point = Geom::Point3d.new(0, 0, 0)
      vector = Geom::Vector3d.new(1, 0, 0)
      angle = 90.degrees 
      transformation = Geom::Transformation.rotation(point, vector, angle)

      window_group.transform!(transformation)
      
      model.commit_operation
    end

    unless file_loaded?(__FILE__)
      menu = UI.menu('Plugins')
      menu.add_item('Create Window Example') {
        self.create_window
      }

      file_loaded(__FILE__)
    end

  end 
end 

Please post your code correctly…

Comments in English help more than yours…

There are several simple problems with the zip file you shared for use as an extension:

  • Your zip is actually in rar format. The SketchUp Extension Manager (EM) understands only zip format. You will need to use a different archive utility that generates zip, or find out how to tell the one you have to generate zip. I had to use a utility that knows about rar to extract it.
  • The EM requires the archive to use the extension .rbz. Even though it is just a renamed zip, it must use .rbz not .zip. Just change the file extension to rbz after zipping.
  • The convention for structure of an extension rbz is that the base folder only contains the “registrar” Ruby (what you call loader.rb) and a subfolder. The name of the registrar is expected to be the same as the name of the subfolder (Door.rb in your case). This will not prevent your extension from loading and running, but will get it rejected if you submit it to the Extension Warehouse.

With those fixes, your code loaded and ran fine. It drew this:

A word of warning: the SketchUp Ruby API is notoriously quick about deleting an empty group. Always add something to a group’s entities immediately when you create the group (I often use a cpoint that I delete later), or create the group from an existing set of entities. Otherwise you may find the code failing randomly with an error about an invalid entity.

2 Likes

Thank you very much the problem was in rar file. I would never thought that the format of archive can be a problem. Thanks!!!

It is not necessary (and often disadvantages) to use an absolute path for the loader file.

The Ruby global array $LOAD_PATH (aliased as $:) is used to find the extension’s subfolder and loader file.

It is also suggested that the 2nd parameter of the SketchupExtension class new() constructor call not have a filetype extension (i.e., .rb, .rbe, etc.) See the explanation for the Sketchup::require method.

Example:

  • registrar file: "DisBond_Door1TestOB.rb"
  • extension folder: "DisBond_Door1TestOB"
# encoding: UTF-8
#
# registrar file: "DisBond_Door1TestOB.rb"

require 'sketchup' unless defined?(LanguageHandler)
require 'extensions' unless defined?(SketchupExtension)

module DisBond
  module Door1TestOB

    folder_path = File.basename(__FILE__, '.*')
    loader_path = File.join(folder_path, 'main')

    EXTENSION = SketchupExtension.new('Create Window Example', loader_path)

    EXTENSION.instance_eval do
      self.version     = '1.0.0'
      self.description = 'A window creation extension.'
      self.creator     = 'Dima'
      self.copyright   = '©2024, by author.'
    end

    Sketchup.register_extension(EXTENSION, true)

  end
end

It is also not necessary to place require "sketchup" at the top of every file.
It is already loaded by the time that any extensions begin to load.

As said earlier, do not use filetypes with the require method calls, as you do not know in the future whether these files will be in another format or encyrpted.

1 Like