Author Topic: ACA/MEP Property with formula eInvalidInput  (Read 2291 times)

0 Members and 1 Guest are viewing this topic.

MexicanCustard

  • Swamp Rat
  • Posts: 705
ACA/MEP Property with formula eInvalidInput
« on: May 31, 2012, 04:19:07 PM »
I get an eInvalidInput error when this code to insert a formula property executes.

Code: [Select]
var descDef = new PropertyDefinitionFormula();
descDef.SetToStandard(db);
descDef.SubSetDatabaseDefaults(db);
descDef.Name = "Description";
descDef.UseFormulaForDescription = true;
psd.Definitions.Add(descDef);
descDef.SetFormulaString("X");  <--- Right here I get an eInvalidInput error

the actual formula looks like this:
Code: [Select]
const string formula =
                        "If \"[ObjectType]\" = \"PIPE\" Then\r\n\tRESULT=\"[PartSizeName]\" & \" X \" & \"[CutLength]\"\r\nElse\r\n\tRESULT=\"[PartSizeName]\"\r\nEnd If";

It doesn't matter what type of string I use in the SetFormulaString method call I get an eInvalidInput.  So I'm thinking there has got to be another property that needs to be set a certain way before I can set the formula.  The sample in the MEP help files is written identical to my code posted above.
Revit 2019, AMEP 2019 64bit Win 10

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: ACA/MEP Property with formula eInvalidInput
« Reply #1 on: June 05, 2012, 08:07:39 AM »
Bump!  Nobody?
Revit 2019, AMEP 2019 64bit Win 10

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: ACA/MEP Property with formula eInvalidInput
« Reply #2 on: June 05, 2012, 09:15:54 AM »
Found the problem.

The PropertySetDefinition must be added to the DictionaryPropertySetDefinitions and Transaction.AddNewlyCreatedDBObject() called before the PropertyDefinitionFormula can be added to the PropertySetDefinition.  Works fine after that.
Revit 2019, AMEP 2019 64bit Win 10

kaefer

  • Guest
Re: ACA/MEP Property with formula eInvalidInput
« Reply #3 on: June 05, 2012, 04:47:43 PM »
Found the problem.

Congrats.

The PropertySetDefinition must be added to the DictionaryPropertySetDefinitions and Transaction.AddNewlyCreatedDBObject() called before the PropertyDefinitionFormula can be added to the PropertySetDefinition.  Works fine after that.

It says as much in Sample\CS.NET\AecPropertyDefinitionFormulaSampleMgd\AecPropertyDefinitionFormulaSampleMgd.cs:

Code: [Select]
    // we need to add all the automatic properties prior to the formula property
    // then we add the property set definition to the dictionary to make formula property work properly
    ...
    // before setting formula string to the formula property, we need to make sure
    // that the property definition is added to the property set definition (which has an object id)

In addition, it appears beneficial to call SetAppliesToFilter on the definition.