Align axes with a face and reset axes

Really? I quoted the API documentation, and your making an assumption.

:spank: :spank: :ninny: :nanny: :poo: :poo:

:laughing:

Seriously,… the object hilighting and bounding boxes are two different things.

You taught me always to question what the API says.
Anyhow, it’s easy to test when I get back from my bike ride.

I know, just teasing.

I also tested it to be sure they hadn’t changed things when I wasn’t looking.

Yes, the Geom::BoundingBox class does not represent the selection bounds in the viewport. If you want to obtain the 3d points for that you can look at this extension I wrote that draws edges and faces matching the viewport bounding boxes: https://bitbucket.org/thomthom/draw-boundingbox/src

My tests show that you are right (again).
Also changing the axes has no effect on the bounding box coordinates. It’s always based on global coordinates. So bounding box is not as useful as I hoped.

Incidentally, this is another unfortunate case where the normal User UI terminology (see Preferences… Compatibility) clashes with API terminology.
Seems that whoever developed the API wasn’t a user, or maybe UI terminology changed (eg: Page vs Scene) changed.

Yea, the API class names matched in the old days, then the UI names diverged.
They could have created aliases for the new names, but decided it would clutter the docs.
ie

Sketchup::Scene = Sketchup::Page

is_a? (or kind_of?) and === seems to work as expected for the aliases.

1 Like

TT:
I’m working my way through thomthom/draw-boundingbox.
Also found source for TT_lib2 which is called twice.
Question: Is the logic in TT instance.rb still necessary? or are the bugs fixed?
I’m using licensing so I only need to support 15.0 and later.

Which logic? The one to obtain the definition?
For the definition in SU2015+: In theory no - in reality yes, because of rogue extensions which implement a bugged Sketchup::Group.definition method, overriding the one we added. That’s why I found I had to fall back to the old method in case of errors.

I think my users will be dealing with simple groups that they create themselves. So I’ll rely on the standard API Group.definition method. Which rogue extensions did you encounter? creating groups for what purpose?

How the group is created doesn’t matter for this issue. The issue is that some extensions define their own version of Sketchup::Group.definition - modifying the API namespace, which in turns affect the whole environment. If your user has such an extension installed you own extensions will fail. (This is why we are so strict on all extensions in Extension Warehouse confining all their code to their own namespace.)

Forgive my newby question:
But a rogue extension could do this to any class or method in the entire API(?).
So it seems futile for individual extensions to try to guard against the general problem.
Users need to be told to uninstall the offending extensions (if they can figure out which it is).

Yes. But it is also part of the power and beauty of Ruby.
It is much faster to test a new API method or feature by writing in Ruby than C. (IMHO at least. There is no compilation step.) Later when things are working, the Ruby can be rewritten into the C side of the API code.

There are introspective ways of determining this particular issue.

if RUBY_VERSION.to_f>1.8 &&
Sketchup::Group.instance_methods.include?(:definition)
  overridden = Sketchup::Group::new.method(:definition).source_location
  if overridden
    # the return value is a string "ruby_source_file:line_num"
    # use your own definition finder
    my_own = true
  else
    # the return value is nil, so the method is native C
    my_own = false
  end
  # get rid of the unreferenced group instance:
  GC.start
else
  # use your own definition finder
  my_own = true
end

if my_own
  def MyLib.get_definition(grp)
    grp.model.definitions.find {|d| 
      d.group? &&
      d.instances.include?(grp)
    }
  end
else
  def MyLib.get_definition(grp)
    grp.definition
  end
end

True this. In fact we had started a “Quarantine List” of just such extensions over on SketchUcation.

Also… a neat new idea for Ruby 2.0+ is refinements:
http://ruby-doc.org/core-2.0.0/doc/syntax/refinements_rdoc.html

It allows us to tweak classes for our own use, without affecting the code of others, or other code of ours.

Just need to say the above sample of determining if Group.definition() has been overridden, needs to happen after the load cycle is complete. There also exists the possibility of users loading extensions midstream (in the middle of a session.)