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

    Ruby Operation left Open

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 6.0k Views 2 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.
    • medeekM Offline
      medeek
      last edited by

      I've had this bug in my plugin for a while. My code is:

      # Get handles to our model and the Entities collection it contains.
      @model1 = Sketchup.active_model
      entities = @model1.entities
      	
      if @Trusstype == "King Post"
        @Model_operation = 'Draw King Post Truss'
        draw_status = @model1.start_operation(@Model_operation)
      
        ....  lots of code here ....
      end
      
      .... more code here ....
      
      draw_status = @model1.commit_operation
      

      Everything looks good but I keep getting this error:

      warning; Ruby operation left open; "Draw King Post Truss"
      

      Nathaniel P. Wilkerson PE
      Medeek Engineering Inc
      design.medeek.com

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        It's always best to add a second argument , true to the .start_operation.
        Also ensure there's nothing in your code that skips out before you get to do the .commit_operation at the end.

        If you do have some methods with code that might bale-out ensure that any ' rescue' also includes the .commit_operation and a return, alternatively use .abort_operation and a return so nothing is done at all...

        TIG

        1 Reply Last reply Reply Quote 0
        • medeekM Offline
          medeek
          last edited by

          I think this may be the hint that I need. For some reason it never occurred to me that the program might be somehow terminating before it got to the final commit command, duh. Looking at it again now.

          Nathaniel P. Wilkerson PE
          Medeek Engineering Inc
          design.medeek.com

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            Also remember that your code as we can see it ALWAYS does a commit - even if there was never an operation started.
            But since we only see some of your code it's unclear if there's always an operation to be committed !
            One way round that is initially to set **@**draw_status = false, then within the 'tests' use **@**draw_status = @model1.start_operation(@Model_operation, true) e.g. in if @Trusstype...
            Always remembering to set in each 'test':

            and then in your unshown code, for each commit you need to use:
            draw_status = @model1.commit_operation if **@**draw_status
            So you don't commit anything unless an operation is been started...

            TIG

            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