cannot set Type parameter of newly created Type

cannot set Type parameter of newly created Type

m.de.vriesTH5VM
Enthusiast Enthusiast
292 Views
5 Replies
Message 1 of 6

cannot set Type parameter of newly created Type

m.de.vriesTH5VM
Enthusiast
Enthusiast

In my code I create a new Type / Symbol of a Family.

This works as expected and I subsequently create an Instance of that new Symbol.

 

I then attempt to set some parameters for this new Instanc3.

 

If the parameter is an Instance parameter then I can set the parameter value and Revit will store it.

 

If the parameter is a Type parameter (I go to instance.Symbol.LookupParameter("") for finding it)

then I can set the parameter value, Revit will acknowledge the new value without error message or exception.

However, if I look at the value the parameter, either immediately after, or when the transaction is committed, Revit returns the old value, not the new.

 

To make things even more confusing. If I start a new command that makes the exact same changes to the parameter values, using the same code, it will actually change the value.

 

I already attempted to commit the transaction between creating the type and instance and re-starting it before changing the parameter values.

 

I also attempted to put the code to change the parameter values in an external event, to maximise the chance that Revit actually finished its process of fully creating and initialising the new Type, but that did not solve the issue either.

 

I have to start a new command before I am able to modify Type parameters in a FamilySymbol that was just created. This is obviously highly undesirable, but I cannot find any answer to a similar question, nor any mention of a method that has to be called to finalise the creation of a new Type/Symbol definition so that its parameters can actually be modified

 

Thanks in advance to any answer that helps me get around this particular issue.

 

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

Ta7a
Enthusiast
Enthusiast

I think your problem is that you try to set parameter that is stored as ElementId but you try to set it as string or integer or may be I am not right could you share the code and parameter name 

by the way check storage type from Revit DB Explorer or Revit Lookup

image.png

0 Likes
Message 3 of 6

m.de.vriesTH5VM
Enthusiast
Enthusiast

Unfortunately this is not the cause of the problem.

I am using a wrapper that converts the input value to the correct type before attempting to set the parameter value.

Plus, the same parameter values can be set with the same method if the Type / Symbol already exists.

 

The pseudo-code is

 

inst = FindInstanceOf("typename");

if (null == inst || !TypeExists("typename"))

{

   tp = CreateType("typename");

   inst = CreateInstanceOf("typename");

}

 

SetParameterValue(inst, "int-parametername", 100.0);

SetParameterValue(inst, "str-parametername", "test");

 

(the actual code has more robust error checking, but for brevity that was omitted above)

 

0 Likes
Message 4 of 6

andré_martins
Contributor
Contributor

Try to assembly recognize it, before:

if (value == null)
{
Console.WriteLine("Value is null.");
}
else if (valor is int)
{
Console.WriteLine($"{value} is integer.");
}
else if (value is float || value is double || value is decimal)
{
Console.WriteLine($"{value} is decimal.");
}
else if (value is string)
{
Console.WriteLine($"\"{value}\" is a string.");
}
else if (valor is bool)
{
Console.WriteLine($"{value} is boolean.");
}
else
{
Console.WriteLine($"{value} is unknown.");
}

You could use a structure Switch.

0 Likes
Message 5 of 6

m.de.vriesTH5VM
Enthusiast
Enthusiast

To clarify myself:

 

The problem is not with setting the Type parameter of the Instance.

I can create the new Symbol and an Instance of it no problem.

 

I can set the parameters of the Instance without problem.

The parameters of the Symbol itself cannot be set. At least not in the command that created the Symbol

In the revit GUI these are Instance and Type parameters resp.

 

I.e. when I select a family there are the parameters that are visible directly in the properties window. These can be changed by the command where they Symbol was created.

The parameters that are only visible if you press the 'Edit Type' button in the properties window however cannot be set in the same command that created the Symbol. if I start a new command though, that can change the values of these 'type' parameters.

Command 1 -> creates the new symbol and creates an instance of it. Can NOT change the parameters of the symbol (Edit Type).

Command 2 -> run separately after Command 1 -> CAN change the parameters of the symbol that was created by Command 1.

Command 1 and Command 2 use the same code to set parameters values.

 

Obviously the users of Command 1 are not happy with the need to repeat all the steps in Command 2.

 

0 Likes
Message 6 of 6

andré_martins
Contributor
Contributor

I think I copy that.

Below is a snippet of a function I use in my library.

 

try
{
param = objDoc.GetElement(e.GetTypeId()).LookupParameter(strParam);
if (param == null)
{
param = e.LookupParameter(strParam).Set("Value");
}

}
catch (Exception)
{
if (param == null)
{
param = e.LookupParameter(strParam).Set("Value");
}
}

0 Likes