Parameter.Set error

Parameter.Set error

Anonymous
Not applicable
1,547 Views
4 Replies
Message 1 of 5

Parameter.Set error

Anonymous
Not applicable

Hi,

This is nolonger working.  get error "MoficationOutsideTransacionException" Attempt to modify the model outside of transaction. PramElem has correct value.

Using Revit 2015 and vb.net 2012

 

Public Sub ChangeParam(ByVal elem As Element)


Dim params As ParameterSet = elem.Parameters
Dim Parameter As Autodesk.Revit.DB.Parameter
Dim ParamElem As Double

If elem.Name.StartsWith("L") Then
      For Each Parameter In params
           If (Parameter.Definition.Name = "Leg") Then
           ParamElem = Val(Leg) / 12
           Parameter.Set(ParamElem)
End If

next

 

Thanks.

Bob V

0 Likes
Accepted solutions (1)
1,548 Views
4 Replies
Replies (4)
Message 2 of 5

arnostlobel
Alumni
Alumni

Hello Bob V:

 

You did not explain how your code differed from previous versions. I assume there have to be some changes made, because the parameter setting works as it should and as it has been for many releases. Changing a parameter as well as any other modifications to a Revit model can only be done within an open transaction. That means that you have to either start your own transaction (Transaction.Start method), or your code must be inside an external command that uses Automatic Transaction Mode. Unless this condition is met, Revit API would throw the very exact exception you got when you attempted modifying the model by changing a parameter.

 

Question I need to ask you: When do you start your transaction?

 

Thank you

Arnošt Löbel
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi,

I started transaction at beginning of my class and had it set to manual.
Changed to automatic and it works. Thanks for pointing me in the right
direction.

Bob V
0 Likes
Message 4 of 5

arnostlobel
Alumni
Alumni
Accepted solution

Hello Bob V,

 

I actually now suggest you revisit your code to find what was happening with your transaction instead of simply switching to using the automatic transaction mode. I cannot recommend using that mode as it is more of an inconvenience rather than a helpful feature. Besides the fact that it frees programmers their of duty to start a transaction before they modify a Revit model, automatic transaction mode has nothing but disadvantages. Therefore I strongly recommend you use the manual transaction mode and start transactions manually whenever they are needed.

 

The fact that you got the exception suggests that the transaction you started at the beginning of your class (whatever that means) has closed before your code reached the point at which you attempted modifying the model by changing a parameter. My guess is that you probably put the transaction in an "using" block and started it within the block (which is perfectly fine and it is what we always recommend). However, when such an "using" block ends, the transaction that started there gets automatically rolled back and destroyed if it was not committed explicitly.

 

Again, I suggest you revisit your code, find the cause of your transaction being closed prematurely, and fix it. Using transactions manually will give you more flexibility and control over your changes.

 

Thank you

Arnošt Löbel
0 Likes
Message 5 of 5

Anonymous
Not applicable
Hi,

Again thank you for your help. I will definitely look into your suggestion.



Bob V
0 Likes