api-issue-tracker icon indicating copy to clipboard operation
api-issue-tracker copied to clipboard

Problems arise after a large number of upward fusion operations

Open LItterBoy-GB opened this issue 4 months ago • 4 comments

line = Sketchup.active_model.entities.add_line ORIGIN, ORIGIN.offset(X_AXIS, 10.m)
10.times do |i|
  Sketchup.active_model.start_operation('', true, false, true)
  line.set_attribute('DFC', 'index', i)
  Sketchup.active_model.commit_operation
end

Undo, edge has been deleted.

line = Sketchup.active_model.entities.add_line ORIGIN, ORIGIN.offset(Y_AXIS, 10.m)
1000.times do |i|
  Sketchup.active_model.start_operation('', true, false, true)
  line.set_attribute('DFC', 'index', i)
  Sketchup.active_model.commit_operation
end

Undo, edge cannot be revoked.

LItterBoy-GB avatar Sep 11 '25 09:09 LItterBoy-GB

I think the Undo stack has a limit to around 100. This may explain the problem.

By the way, I am not sure why you need to have the start_operation INSIDE the loop, rather than OUTSIDE.

Fredosixx avatar Sep 12 '25 14:09 Fredosixx

By the way, I am not sure why you need to have the start_operation INSIDE the loop, rather than OUTSIDE.

Because of the EntitiesObserver. I need to listen to the added entities and perform some operations. Of course, it's rare for observers to be triggered hundreds of times, but this situation still exists.

I think mergers should always be done once, no matter how many times they occur

LItterBoy-GB avatar Sep 13 '25 01:09 LItterBoy-GB

The undo stack has a limit, yet. Currently 1000, used to be 100 in older versions.

Transparent operations don't add to previous, but chain. Undo/redo will iterate over transparent operations until a non-transparent is reached.

I need to listen to the added entities and perform some operations. Why do you need an observer in this case? Observers are mainly useful when your own code isn't in control of the model changes. In this case you have control. Seems redundant to create a chain of transparent operations like this. (I'd advice against it)

thomthom avatar Sep 17 '25 11:09 thomthom

I need to listen to the added entities and perform some operations. Why do you need an observer in this case? Observers are mainly useful when your own code isn't in control of the model changes. In this case you have control. Seems redundant to create a chain of transparent operations like this. (I'd advice against it) You are right. But

I have paused all observers within my controllable code. I am just a task merging operation, which should not be counted as one operation unless there are no operations that can be merged. That is to say, merging operations can only be counted as one operation at most after 100 times, so as not to occupy the entire undo stack

LItterBoy-GB avatar Sep 18 '25 01:09 LItterBoy-GB