I have an odd situation, and I'm just checking in to see if this is normal.
I have a transaction. It's rather simple. I just sets a parameter.
It has worked fine. Recently, I've been enhancing my code to set multiple parameters on different elements. I made a simple loop with the transaction inside the loop. Basically, it does back-to-back-to-back transactions on different object parameters.
I've noticed that the loop only commits the first object parameter change. The first elements go through the whole commit process, because I've stepped through it to make sure it hits the parameter.set() line. But when I go to the model, only the first object parameter has changed. I have verified that the object element ID has changed with each iteration of the loop.
Has anyone seen this? This is really odd.
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
Do you commit each of the transactions before starting a new one?
If not, all your changes will be lost.
If you do, each commit will regenerate the model.
Odd behaviour may well ensure if you do not:
https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.33
It would be much more efficient to perform all the modifications within one single transaction, instead of creating and committing a new transaction for each iteration of your loop.
Cheers,
Jeremy
I agree that it would be more efficient to do the loop inside the transaction, but I'm expecting rollback issues when I try this on worksets. I wanted to run each transaction at a time, so if like 3 of the 5 parameters couldn't be set due to a workset error, then I could use the rollback swallower to resolve it.
Regardless, I put the loop inside the transaction to see if that worked. I kind of does. Here's the deal. When I step through the code, it modifies all the parameters respectively, which is correct. Like if I had 5 parameters, and I looped through them with an alphabetic string order, the first parm would be "a", second would be "b", third would be "c" etc. However, If I remove all the Visual Studio break points, and run it at regular speed, it only commits the first value of the parameter.set(). So basically, all my parameters have the same value, and it's always the string for the first parameter. All five of my parameters are just "a".
Kind of confused.... How can it be a different value when it's run slower?
Nevermind the last post. I forgot my "regen" operation you mentioned in your response. My bad.
Can't find what you're looking for? Ask the community or share your knowledge.