Closing an open component API
-
I am unable to find the api to close a component that is open for editing; I've searched for terms that seem plausible like 'close_edit' and exit and clear and selection and so on and on. A list of methods is all very useful when you have a decent idea of what your target might be called but not so much fun otherwise. Simply searching the forums dumped so much on me that I almost fell asleep reading through it. I was anticipating something along the lines of "Sketchup.close_open_edit()'.
My ComponentScenes plugin can be used when a component is opened up and sub-components are selected. At the end of the function I'd like to close the edit because it seems confusing to have the edit context make the 'new' components created non-visible (depending upon the users settings for 'view>component edit' of course). One might argue that users should be aware of their own setup but I think it worth trying to be helpful. If it turns out to actually be helpful, of course.
-
https://developers.google.com/sketchup/docs/ourdoc/model#close_active
Assuming that
model=Sketchup.active_model
has been set earlier...If the user could be in the model OR a group/component context, then use '
close_active
' with a test, something like:
model.close_active unless model.entities==model.active_entities
To close ALL open edit contexts back to the base level of the
model.entities
use something like:
model.close_active until model.entities==model.active_entities
Of course you could try and find the view>component-edit boolean value and remember it, then set it to be 'on' and when your tool is done reset it to the remembered boolean value ?
-
Thanks; that's even pretty damn obvious once you know it. Good point about multiple levels of open as well; hadn't considered that.
Maybe it would be best to leave things as they are... -
@tim said:
A list of methods is all very useful when you have a decent idea of what your target might be called but not so much fun otherwise. ... I was anticipating something along the lines of "Sketchup.close_open_edit()'.
But there are only two methods that begin with "
close
..." in the API Method Index... and you know it's likely not the one for the
Webdialog
class. -
Beware!
Normally when you close a group/component using the SketchUp UI it is added to the Undo stack.
However,model.close_active
does not add the event to the undo stack so if the user invokes undo after using that method geometry shifts around as they are undone because the undo operation doesn't know the context and axis changes. -
@dan rathbun said:
But there are only two methods that begin with "
close
..." in theYeah but you know what it's like - you are searching for something for which you have no idea of the name, try all sorts of combinations - exit, stop, abandon, cancel, whatever - and when you give up and ask for help it's always the most embarrassingly obvious choice that you never even considered. This is why getting forgetful in older age is so infuriating.
"Um, strawberry-ish. Red thing. Flower?"
"Rose?"
"Yes - spectacles! Thank you!" -
@tim said:
Yeah but you know what it's like -
Yes I've been there.
Was just teasing.
And it takes awhile to get used to how they organized the API.
Advertisement