object GetValueFromParam_nameContext(Element elem, ParamExprGrammarParser.Param_nameContext paramName) { object parValue = null; Element el = elem; if (paramName.ChildCount > 1 && paramName.type() != null) { el = elem.Document.GetElement(RevitElement.GetTypeId()); } parValue = GetParameterValue(el, paramName); return(parValue); }
/// <summary> /// Executed upon exiting atomic_param rule /// </summary> /// <param name="context">the atomic_param context</param> public override void ExitAtomic_param([NotNull] ParamExprGrammarParser.Atomic_paramContext context) { base.ExitAtomic_param(context); NodeProperty nodeP = new NodeProperty(); nodeP.originalNodePropertyValue = context.GetText(); // Handle special_param if (context.GetChild(0) is ParamExprGrammarParser.Special_paramContext) { var spParCtx = context.GetChild(0) as ParamExprGrammarParser.Special_paramContext; if (spParCtx.ELEMENTID() != null) { nodeP.nodePropertyValue = RevitElement.Id.IntegerValue; } else if (spParCtx.RUNNINGNUMBER() != null) { var key = new Tuple <string, string>(RevitElement.Category.Name, RevitParameterName); int lastNumber; if (LastRunningNumberCollection.ContainsKey(key)) { lastNumber = ++LastRunningNumberCollection[key]; } else { lastNumber = 1; LastRunningNumberCollection.Add(key, lastNumber); } nodeP.nodePropertyValue = lastNumber; } else if (spParCtx.RUNNINGNUMBERINSTANCE() != null) { var key = new Tuple <string, string>(RevitElement.Id.ToString(), RevitParameterName); int lastNumber; if (LastRunningNumberCollection.ContainsKey(key)) { lastNumber = ++LastRunningNumberCollection[key]; } else { lastNumber = 1; LastRunningNumberCollection.Add(key, lastNumber); } nodeP.nodePropertyValue = lastNumber; } //else if (spParCtx.AUTOCALCULATE() != null) //{ //} else { // Not supported } } // handle objref param_name (',' param_name) else { object parValue = null; var thisObj = context.GetChild(0) as ParamExprGrammarParser.ObjrefContext; var paramNames = context.param_name(); if (paramNames.Count() >= 1) { // This is the first level reference if (thisObj.THIS() != null) { parValue = GetValueFromParam_nameContext(RevitElement, paramNames[0]); } else if (thisObj.TYPE() != null) { parValue = GetValueFromParam_nameContext(RevitElement.Document.GetElement(RevitElement.GetTypeId()), paramNames[0]); } } if (paramNames.Count() > 1 && parValue != null && parValue is ElementId) { // Parameter should be obtained from the second level reference if the parameter is of ElementId type parValue = GetValueFromParam_nameContext(RevitElement.Document.GetElement(parValue as ElementId), paramNames[1]); } nodeP.nodePropertyValue = parValue; } SetNodePropertyValue(context, nodeP); }