Model management via Ruby


#1

Hi all,

Looking to manage my (and my colleagues) models a bit more smoothly without the use of outliner (I’m OK with it, but it’s kinda scary to some of my colleagues) .

Simply I want to open a component for editing and leave it so by click on a toolbar button. For example if I click on the chimney button I want to open the component “chimney” (if one exists).

What do you all think? Possible?

Thanks for reading.

R


#2

So far as I know, the Ruby API has means to modify the entities of a component within a Ruby script, but has no way to instruct the GUI to open a component for editing there.


#3

… but the API does have a way of exiting the current nested context, and it is possible to create a button that will back out to the model context.

(But the close_active() method had a bug in it prior to SU14, so should only be used on 14+ versions.)

stopcmd = UI::Command::new("Stop All Editing") {
  model = Sketchup::active_model
  model.close_active until model.active_entities == model.entities
}

See the API docs on the UI::Command class for more, like assigning button images etc., adding the command reference to a toolbar or menu.


#4

Thanks both for the advice. Much as I feared, but you cannot win them all.

Cheers

R


#5

on a mac I can drill down into components if use Ruby to send ‘mouse double clicks’ until selected is a Face…

 def self.selected?
   Sketchup.active_model.selection[0].class == Sketchup::Face
 end

maybe there’s a win32 way of doing similar?

this could be on a ‘drill down’ button/menu item/shortcut key and run on first mouse down…

although not the same as your request, it requires only one button for all models, but the component is still chosen ‘visually’ as opposed to ‘Outliner’…

would this help?

john


#6

I do not see the point myself. Quicker to just double-click the object.


#7

you would think so, but on that particular Revit ifc import, manual double clicking gets hung at about three definitions in and can take many extra double clicks to get to the underlying face…

sending them programatically always works with one double click per level…

john


#8

It’s also “fragile” because the user can not move the mouse or rotate whilst the external script does its work. Would not generally recommend. I mean, if the Outliner is scary, then this is terrifying.