When manipulating an entity, I could carry out an analogous operation on it a number of instances, equivalent to rotating it by a random angle as much as 120 instances. After finishing these operations, if I need to return to the preliminary state, I would want to undo the operation 120 instances, however in follow, I can solely undo a most of 100 instances.
How can I merge these 120 operations into one? I do know that the final parameter of the start_operation perform can merge operations, but it surely nonetheless solely permits for a most of 100 operations to be merged.
Have you ever tried simply wrapping the 120 intermediate edits right into a single operation ?
You’ll be able to outline a block type methodology inside your extension submodule to simplify wrapping operations:
def wrap_as(op_name)
mannequin = Sketchup.active_model
mannequin.start_operation(op_name, true)
#
yield mannequin
#
mannequin.commit_operation
rescue => error
places error.examine
mannequin.abort_operation
finish
2 Likes
@DanRathbun’s snippet exhibits a neat method of wrapping a collection of steps as one operation. However remember that wrapping all of the edits in a single operation doesn’t protect them as particular person “undoable” steps. SketchUp has no assist for each sorts of undo on the identical collection of steps. If all you want is the majority undo, there’s the reply: don’t make every step an operation within the first place.
1 Like
Relating to the utmost variety of undo steps.
This describes a probable out of date characteristic. (… click on to increase …)
The default setting is 100
.
-
NOTE: The
"MaxUndo"
setting described beneath now not exists in v2023.
On Home windows previous to v18, the "MaxUndo"
attribute was inside the registry dB utilizing the "Preferences"
key, for the person SketchUp settings. (ex: HKCUSoftwareSketchUpSketchUp 2017Preferences
)
Since v18, it’s now inside the "SharedPreferences.json"
file ie:"Shared for All Computer systems"
> "Preferences"
> "MaxUndo"
The place
xx
is the present 12 months version …
On Home windows this file is within the Roaming %AppData%
path for the present SketchUp model.%AppData%/SketchUp/SketchUp 20xx/SketchUp/SharedPreferences.json
On Mac, this file is within the person App Assist path:~/Library/Utility Assist/SketchUp 20xx/SketchUp/SharedPreferences.json
These information have to be edited with SketchUp closed in any other case any modifications might be overwritten by SketchUp when it closes. The information are learn by SketchUp when it hundreds.
No assure that SketchUp nonetheless accepts the worth of this attribute though it has been within the desire settings for years (since v2016 not less than.)
At all times make a backup copy of those information earlier than trying handbook edits.
Unusual. I simply checked, and on my Mac that setting is current in SharedPreferences.json for all variations from 2018 by 2022, however is lacking in 2023! I by no means manually edited it into any of them (all are on the default 100), so why does 2023 omit the setting? Was there a change to the dealing with of the undo stack?
Sure. Similar on Home windows, the setting is now not there for v2023.
Maybe it has been orphaned for some time and was lastly eliminated as not working ?
Thanks in your resolution.
However what I’m doing is creating a customized instrument, just like the rotation instrument, each time the mouse strikes, the chosen entities will rotate to the brand new angle. These rotation steps are executed in onMouseMove
methodology, to allow them to’t be wrapped right into a single operation. After the person clicks the mouse button, the rotation is accomplished, and if the person desires to get better to the unique state, they’ll press Ctrl + Z.
The unique Sketchup rotation instrument can press Ctrl + Z as soon as to get better, however I don’t know what magic it has.
One workable strategy is to make use of Sketchup.undo(). On the primary mouse transfer after activation there’s an preliminary start_operation()/commit_operation(). Then with every mouse transfer you carry out an undo() which resets the goal geometry to its preliminary place after which one other start_operation()/commit_operation() with a brand new transformation in between. The results of all of this jerking about of the undo stack is that there’s solely ever one operation to undo irrespective of what number of instances the geometry is reworked…
.
At one level some time again I discovered that I wanted a solution to drag display screen textual content across the display screen with a Ruby Extension (which is form of the identical repeated transformation drawback). Right here’s the code and a brief display screen seize of the instrument in motion. sw_Screen_Text_Mover.rbz (13.3 KB)
Thanks, this resolution works! However it additionally makes this system rather more sophisticated if we create some entities between two rotations or movings.
It’s one of the best resolution for now anyway, thanks once more.
Maybe you possibly can observe this logic:
module Dezmo
module DezmoTest
class DezmoTestTool
def initialize
@in_transform = false
@myselection = nil
finish
def onCancel(motive, view)
view.mannequin.abort_operation if @in_transform
@in_transform = false
finish
def onLButtonDown( flags, x, y, view )
if @in_transform
commit_transform(view)
else
if @myselection
start_transform( view, "My Rotation" )
else
# code for choose the entities to rotate
# and set @myselection
finish
finish
finish
def onMouseMove(flags, x, y, view)
if @in_transform && @myselection
# code for trasnform (rotate) the entities (@myselection)
else
# code for choose the entities to rotate
# and set @myselection
finish
finish
def start_transform( view, undo_text )
@in_transform = true
#view.mannequin.start_operation(undo_text, true)
# edited:
view.mannequin.start_operation(undo_text)
finish
def commit_transform( view )
@in_transform = false
view.mannequin.commit_operation
finish
finish #instrument
finish #extension
finish #namespace
If you’re beginning an extended operation in a instrument, then you definitely don’t need to disable the UI (second argument), that may forestall any visible suggestions whereas the instrument updates the mannequin.
1 Like