Ruby Operation left Open
-
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_operationEverything looks good but I keep getting this error:
warning; Ruby operation left open; "Draw King Post Truss" -
It's always best to add a second argument
, trueto the.start_operation.
Also ensure there's nothing in your code that skips out before you get to do the.commit_operationat the end.If you do have some methods with code that might bale-out ensure that any '
rescue' also includes the.commit_operationand areturn, alternatively use.abort_operationand areturnso nothing is done at all... -
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.
-
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. inif @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...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement