Verify if a parameter is a shared parameter

Verify if a parameter is a shared parameter

Anonymous
Not applicable
758 Views
5 Replies
Message 1 of 6

Verify if a parameter is a shared parameter

Anonymous
Not applicable

In here, a piece of a code

 

foreach (Parameter param in elementType.Parameters) //Pega Type
{
if (param.Definition.Name == "CotaA")
{
trans.Start();
if ((CotaA != 0) && (param.IsShared))
{
param.Set(CotaA);
}
else
return Result.Failed;
trans.Commit();
}
}

 

and always fail in revit.

 

I want to check if the parameter in revit "CotaA" is a Shared Parameter.

Tks.

0 Likes
759 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

What type is the variable CotaA, and is it the same as the storage type for the parameter labelled "CotaA"?

 

The statement CotaA != 0 suggests that it's an integer, if the "CotaA" parameter is not compatible with integer values then the param.Set(CotaA) will fail. Variable CotaA might also have a value of zero, failing your test, it might not even be an issue with the parameter.

 

Step through with debugger and see what's going on.

 

0 Likes
Message 3 of 6

Revitalizer
Advisor
Advisor

Dear h.paulo,

 

you can adress your parameter directly without stepping through the whole Parameters map.

Just use elementType.LookupParameter(string yourParamName).

 

Additionally, what happens if you try to set the parameter manually ?

 

May it be that your "elementType" is a FamilySymbol, and that your Family has geometric constraints that prevent it from accepting your input values for the "CotaA" parameter?

 

 

 

Best regards,

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 4 of 6

Anonymous
Not applicable

The variable "CotaA" is defined as double, and it's the same storage, the parameter is compatible and the bool param.IsShared return TRUE, but the program fails because something in that piece of code cancel the debugging.

 

Tks.

0 Likes
Message 5 of 6

Anonymous
Not applicable

The parameter must set with a form that appears in Revit when I run the add-in, till there it works, and the test param.IsShared is TRUE but always fail and the parameters is not setted. There isn't errors in the code, but always return as canceled.

 

Thanks.

0 Likes
Message 6 of 6

Revitalizer
Advisor
Advisor

Hi h.paulo,

 

you don't commit your Transaction since Commit() is in the "else" branch; also, you leave your function with return before executing the Commit().

Sorry, didn't read it carefully enough.

Nonetheless, you start a transaction without ending it properly if using the "else"-branch.

 

You always do that if both CotaA is not zero AND CotaA is shared.

What if CotaA's current value is zero ?

In this case, you will not be able to change it to another value, using your current code.

Maybe zero is the default value for a double parameter.

Thus, once a ElementType is created with default zero value, it won't be updated when executing your code.

It will always stay at zero.

So change "(CotaA != 0) && (param.IsShared))" to "(param.IsShared)".

 

 

Best regards,

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes