Omit hide operation on undo stack after calling Drawingelement::visible=false

Hi,

I have a problem in my plugin caused by calling Drawingelement::visible=false. For some purpose, I would like to hide a lot of groups by calling visible=false. However, this will littering the undo stack by adding a lot of “undo hide” command.

I would like to ask, if it’s possible to omit the the hide operation on the undo stack?

Thanks,

Han

You can wrap the operations into one using Model#start_operation(true) and Model#commit_operation. You can’t exclude it from the undo stack though.

I wanted to exclude hiding/showing myself when working with animations several years ago but it just can’t be done. You can however move groups and components without registering it to the undo stack using the move! method if you need to for an animation.

Nah~ I have just figured out how to do this. I have wrapped the all the ·group.visible=false commands into the same loop. And before the loop call model.start_operation 'name', true, false, true after it call model.commit_opeartion. The last true in the start_operation will make this op transparent, that is not visible in the undo stack. This feature is included in Sketchup 2016 as the sketchup doc says.

Transparent operations are added to the undo stack but merged with the previous operation. If the user undos the previous operation yours will also be undone.

Thanks, I see… So the problem, as you described, can not be solved perfectly. But fortunately, in my case, I do not quite care about the transparent operation being undo. So this is a walk around of my problem.

Can I ask what you are doing? (Why are you hiding entities and trying to omit the undo stack?)
Maybe the better solution is a different one…

I have a scene with aerial cameras seeing the ground. After clicking on the camera, it will enter the corresponding match photo scene using that camera. And I only want to show the right camera, which sees
object I’m selected, so the other cameras are hidden.

However, as you see it, there are a lot of individual cameras and thus many “undo hide” command is pushed into my undo stack. I do not find a way to get through this, and the only walk around is to make all the hide transparent to the following command.

I wouldn’t recommend using a transparent to previous operator unless the operation is triggered specifically by the previous one using observers. Using transparent to previous operators that aren’t triggered directly after another operator can generate unexpected results. If the user e.g. undos drawing an edge or changing a material color they do not expect the cameras to suddenly get visible out of nowhere.

Thanks for this suggestion. I think this is also the recommend way to use transparent op in the ruby doc. Maybe I will group the hide and make them not transparent and undo in a single op.

1 Like

Yes, I think that would be the better solution.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.