• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Start/commit_operation

Scheduled Pinned Locked Moved Developers' Forum
12 Posts 6 Posters 1.2k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    sdmitch
    last edited by 2 Oct 2011, 20:53

    Is it just me or do you frequently have issues with start_operation and/or commit_operation. Recently I have been working on a plugin that after working without fail stopped working or bug splatted after I added a start_operation statement. Moving the start_operation statement up a few lines in the script allowed the script to run normally.

    Is there a limit on the number of entity creations that can be undone with a single start/commit block?

    Nothing is worthless, it can always be used as a bad example.

    http://sdmitch.blogspot.com/

    1 Reply Last reply Reply Quote 0
    • A Offline
      Anton_S
      last edited by 2 Oct 2011, 22:52

      Well I don't know if there is the limit or not, but so far I never experienced problems with start and commit operation. Did you state the right arguments for the start operation? If did and still doesn't work then give more info like an example.

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 2 Oct 2011, 23:36

        One thing you do not want to do with start_operation and commit_operation is nest them - that is, make sure you always commit or abort an operation before starting a new one.

        Hi

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 3 Oct 2011, 01:09

          See code post: [Code] wrapping operations

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • S Offline
            sdmitch
            last edited by 7 Oct 2011, 17:35

            I have given up trying to figure out why .start_operation/.commit_operation inclusion in my Bolt Maker plugin causes periodic bug splats. Even when that didn't happen, the undo capability was the same as if it wasn't included so no gain for the pain. The only commonality of the bug splats seemed to be that the first entity selected was a group with "Head Type:Cap" selected.

            If you can figure it out, I would love to hear from you.

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • D Offline
              Dan Rathbun
              last edited by 8 Oct 2011, 09:35

              My standard advice would be to always develop and test with ALL other 3rd party plugins unloaded. May be that some other plugin's observers are causing the splats.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 8 Oct 2011, 10:04

                Why not put
                @ent.erase_entities(@guide1) if @guide1 @ent.erase_entities(@guide2) if @guide2 @ent.erase_entities(@guide3) if @guide3 @mod.commit_operation self.reset()
                Inside the begin section where it belongs.
                The .abort_operation in the rescue section already removes these temporary guides as everything is undone.
                Both the else and ensure sections could then be left empty, because you can end the rescue code with self.reset() too...

                TIG

                1 Reply Last reply Reply Quote 0
                • L Offline
                  LarsG
                  last edited by 18 Oct 2011, 02:31

                  Start/commit operation has today cost me many hours.

                  I'm developing a plugin writting in c++ that calls some sketchup functions and one them
                  is to print some 3d text on a group. That worked fine before I put a start / commit operation
                  around it then I suddenly couldn't use objects only a command later.
                  They would be referencing nilClass.

                  I haven't been able to figure out what it changes, especiallly since disabling the ruby garbage collector didn't
                  change anything.

                  ( and sorry if my terminology is confusing, ruby is new to me, and Sketchup API (especially when going c++ -> ruby -> sketchup c++ ) is a mystery )

                  1 Reply Last reply Reply Quote 0
                  • L Offline
                    LarsG
                    last edited by 18 Oct 2011, 03:00

                    whoops, writing that out made me think of something...

                    Learn To Think... solved my problem, quite stupid mistake that was well hidden.

                    I believe that if an operation goes wrong after start_operation then other objects will be deleted,
                    possible all objects created since start_operation.

                    In my case it was add_3d_face("") which made it so, haven't tested with other functions.

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      sdmitch
                      last edited by 18 Oct 2011, 14:50

                      LarsG, That was exactly my situation. Everything worked perfectly but the simple addition of a start/commit block caused references to deleted entities.

                      Nothing is worthless, it can always be used as a bad example.

                      http://sdmitch.blogspot.com/

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        Dan Rathbun
                        last edited by 19 Oct 2011, 00:07

                        @larsg said:

                        I believe that if an operation goes wrong after start_operation then other objects will be deleted,
                        possible all objects created since start_operation.

                        That is what is supposed to happen, and why you should use a begin .. rescue .. end block around your operation, with a call to model.abort_operation() inside the rescue clause, so that a ref to the operation does not remain on the undo stack.
                        You can also do other recovery code within the rescue clause, so as to prevent actions on deleted entities, or close a logfile handle, etc.

                        See code post: [Code] wrapping operations

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • L Offline
                          LarsG
                          last edited by 19 Oct 2011, 21:15

                          First
                          I guess like the poster I don't really have a point with this rant except to warn others who
                          is as clueless as I about both neccessary and good practices working with Ruby Sketchup.
                          As usual when I read your posts, thank you, I find a gold nugget, it is sometimes just hard
                          to to know that you need it.

                          Second
                          I see that it is good and and I agree it makes sence that it works that way..
                          My irritation points are that:

                          As far as I know my add_3d_text didn't output any error beside returning a nil
                          value, a return value you seldom use.

                          There was (AFAIK) no type of exception raised either.

                          The documentation is as usual very short and doesn't mention it actually undoing any work,
                          the work might as well have been undone by a call to abort_operation not automatically.

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          • First post
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement