You still need to do things the Ruby way, rather than say the JavaScript or Python way.
A few thoughts …
(1) In Ruby, constants are ALL_UPPERCASE.
Module and Class identifiers are CamelCase (aka SnakeCase.)
Method identifiers and Reference names are lower_case_divided_by_underscore.
(2) All of your extensions should be wrapped within a single toplevel author or company namespace module. So …
module REGROUP
… should be …
module ShaisNamepace # <--<<< Change to suit your needs
module Regroup
# code here
end
end
(3) Ruby uses 2 space indentation. Set your editor to replace tabs with 2 spaces so that code is indented properly when pasted into the forum.
(4) Encode your Ruby files as UTF-8 and insert a magic comment as the first line of each .rb file …
# encoding: UTF-8
(5) For best results (especially copy and pasting into forum or SketchUp’s Ruby Console,) … use Windows style Line endings (CR+LF).
(6) Ruby’s main paradigm is “readability”. Do not use frivolous parenthesis around conditional expressions. JavaScript and C requires it, Ruby does not.
if result == 2
… not …
if (result == 2)
Only use parenthesis if there are multiple terms and you must control the order of evaluation.
(7) Use modifier position for one-line conditional blocks to reduce lines and improve readability …
result = 1 if number > 1
… not …
if number > 1
result = 1
end
(8) The return reserved-keyword is not actually required as methods in Ruby always return the value of the last expression (or statement) evaluated.
def container_type(entity)
if entity.is_a?(Sketchup::Group)
3
elsif entity.is_a?(Sketchup::ComponentInstance)
number = entity.definition.count_used_instances
number > 1 ? 1 : 2
else
0
end
end
In the above example, the last statement evaluated is the if statement which returns the result of it’s evaluation, so the method will return the result of the if statement. There is no need to short-circuit the if statement using return statements.
The above would also be the same as …
def container_type(entity)
return if entity.is_a?(Sketchup::Group)
3
elsif entity.is_a?(Sketchup::ComponentInstance)
number = entity.definition.count_used_instances
number > 1 ? 1 : 2
else
0
end
end
Which I’m sure we’d all agree is a frivolous use of a return ?
(9) You can avoid the “self.” method qualification inside your module, by extending it with itself using extend. Ie (removing the unneeded number = reference assignment) …
module ShaisNamepace # <--<<< Change to suit your needs
module Regroup
extend self
def container_type(entity)
if entity.is_a?(Sketchup::Group)
3
elsif entity.is_a?(Sketchup::ComponentInstance)
entity.definition.count_used_instances > 1 ? 1 : 2
else
0
end
end
# more code here .. etc.
end
end
You might not (looking at the container_type method) realize that class Sketchup::Group is just a special subkind of ComponentInstance, so group’s also must have a ComponentDefinition that “owns” the entities collection.
This means that a group also has a #definition getter method.
But the API also defined a short-cut #entities method for group’s to get their definition’s entities collection.
For a group only …
group.entities == group.definition.entities
What issue are you having with the model’s axis ?
How are they “off” ? Coordinates ? or are they rotated away from the model axis ?
What does “rounded” mean ? We usually use this word with respect to decimal precision of coordinates.
What does “boxer” mean ? Do you mean the instance’s BoundingBox ?
You might need to post annotated images to explain what you mean if you do not yet know SketchUp “buzzwords” or terminology.