sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Start/commit_operation

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 6 Posters 1.2k Views 6 Watching
    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.
    • sdmitchS Offline
      sdmitch
      last edited by

      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

        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

          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
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            See code post: [Code] wrapping operations

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • sdmitchS Offline
              sdmitch
              last edited by

              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
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                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
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  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

                    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

                      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
                      • sdmitchS Offline
                        sdmitch
                        last edited by

                        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
                        • Dan RathbunD Offline
                          Dan Rathbun
                          last edited by

                          @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

                            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