Set Global Parameter value

Set Global Parameter value

Anonymous
Not applicable
4,104 Views
8 Replies
Message 1 of 9

Set Global Parameter value

Anonymous
Not applicable

Hello everyone.

 

I'm trying to apply a value to a Global Parameter. Can anyone tell me why the follwing code doesn't work:

 

double value = 55;

ElementId paramId = GlobalParametersManager.FindByName(doc, "ParameterName");
GlobalParameter param = doc.GetElement(variable) as GlobalParameter;

paramSetValue(new DoubleParameterValue(value));

 

Thank you

0 Likes
Accepted solutions (1)
4,105 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

Yes. The variable variable is not set.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 9

GonçaloFeio1321
Enthusiast
Enthusiast

Please tell what went wrong, what exception was thrown.

paramId returnsInvalidElementId if no GlobalParameter is found with that name.

Then, param.SetValue should had worked.

0 Likes
Message 4 of 9

Anonymous
Not applicable

The parameter does exists on file.

Please check the image bellow to see the exception message.

0 Likes
Message 5 of 9

Anonymous
Not applicable

Can you tell me how to solve it please?

0 Likes
Message 6 of 9

matthew_taylor
Advisor
Advisor

Hi @Anonymous

There's a pretty decent example here:

http://www.revitapidocs.com/2016/df012c22-6e65-8de5-1057-f15660d02288.htm

 

There are also a lot of notes that look worth reading here:

http://www.revitapidocs.com/2016/b0e53a4a-84ad-abb4-358d-9797870f101b.htm

 

Also, your quasi-code has a couple of issues. (A missing period, inconsistent variable naming.) I wonder whether one of those are your actual problem?

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 7 of 9

matthew_taylor
Advisor
Advisor
Accepted solution

Sounds like you just need a valid transaction. There's an example of that in the links I provided.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 8 of 9

Anonymous
Not applicable

Sorry, as Jeremy said there is an error in the code i've pasted above but the problem stills the same:

 

double value = 55;

ElementId paramId = GlobalParametersManager.FindByName(doc, "ParameterName");
GlobalParameter param = doc.GetElement(paramId) as GlobalParameter;

paramSetValue(new DoubleParameterValue(value));

0 Likes
Message 9 of 9

GonçaloFeio1321
Enthusiast
Enthusiast

@matthew_taylor already answered. You need a started Transaction.