• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

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.
  • M Offline
    medeek
    last edited by 17 Oct 2018, 02:52

    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
    • T Offline
      TIG Moderator
      last edited by 17 Oct 2018, 09:10

      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
      • M Offline
        medeek
        last edited by 17 Oct 2018, 16:05

        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
        • T Offline
          TIG Moderator
          last edited by 17 Oct 2018, 17:39

          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
          1 / 1
          • First post
            2/4
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement