Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Parameter.Set error

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
rvetrano
1299 Views, 4 Replies

Parameter.Set error

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

4 REPLIES 4
Message 2 of 5
arnostlobel
in reply to: rvetrano

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
Message 3 of 5
rvetrano
in reply to: arnostlobel

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
Message 4 of 5
arnostlobel
in reply to: rvetrano

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
Message 5 of 5
rvetrano
in reply to: arnostlobel

Hi,

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



Bob V

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community