【Revit 2025 API】 A Question about SetFormula

【Revit 2025 API】 A Question about SetFormula

yz8023yz
Participant Participant
408 Views
3 Replies
Message 1 of 4

【Revit 2025 API】 A Question about SetFormula

yz8023yz
Participant
Participant

When I execute the following code

FamilyManager manager = familyDoc.FamilyManager;

ForgeTypeId forgeTypeId_length = new ForgeTypeId("autodesk.spec.aec:length-2.0.0");
FamilyParameter parameter_qzh = manager.AddParameter("墙肢高度", GroupTypeId.Geometry, forgeTypeId_length, false);

I got this

yz8023yz_0-1719823595595.png

 

But when I execute this one code:

manager.SetFormula(parameter_qzh, "侧墙高度 -底板厚度");

it will throw an error:There is no valid family type. at Autodesk.Revit.DB.FamilyManager.SetFormula(FamilyParameter familyParameter, String formula)

0 Likes
Accepted solutions (1)
409 Views
3 Replies
Replies (3)
Message 2 of 4

TripleM-Dev.net
Advisor
Advisor

Is there a Type active in the FamilyEditor, a parameter needs to be set while a type is set.

If no types are defined (the type box shows a grey inactive combobox) the values can't be set.

 

See remarks in: CurrentType  

I Think the UI can do this because it sets the type to the name of the family...

 

- Michel

0 Likes
Message 3 of 4

yz8023yz
Participant
Participant

Hi, thanks for the reply, but I noticed that the type box is not showing the gray inactive combo box.screenshot-1719884883577.pngscreenshot-1719884941798.png

0 Likes
Message 4 of 4

yz8023yz
Participant
Participant
Accepted solution
Add the following code for the creation parameter in the family document
// Checks to see if the current family type exists, and if not, creates the
FamilyType currentType = manager.CurrentType;
if (currentType == null)
{
currentType = manager.NewType("DefaultType");
}
0 Likes