Exemplo n.º 1
0
        public static string EvaluateAttributeUserText(RhinoSceneHierarchyNode InNode, string ValueFormula)
        {
            if (!ValueFormula.StartsWith("%<") || !ValueFormula.EndsWith(">%"))
            {
                // Nothing to evaluate, just return the string as-is.
                return(ValueFormula);
            }

            RhinoObject             NodeObject   = InNode.Info.RhinoModelComponent as RhinoObject;
            RhinoObject             ParentObject = null;
            RhinoSceneHierarchyNode CurrentNode  = InNode;

            while (CurrentNode.LinkedNode != null)
            {
                CurrentNode  = CurrentNode.LinkedNode;
                ParentObject = CurrentNode.Info.RhinoModelComponent as RhinoObject;
            }

            // In case this is an instance of a block sub-object, the ID held in the formula may not have been updated
            // with the definition object ID. We need to replace the ID with the definition object ID, otherwise the formula
            // will not evaluate correctly.
            if (InNode.LinkedNode != null && !InNode.LinkedNode.bIsRoot)
            {
                int IdStartIndex = ValueFormula.IndexOf("(\"") + 2;
                int IdEndIndex   = ValueFormula.IndexOf("\")");

                if (IdStartIndex >= 0 && IdEndIndex > IdStartIndex)
                {
                    ValueFormula = ValueFormula.Remove(IdStartIndex, IdEndIndex - IdStartIndex);
                    ValueFormula = ValueFormula.Insert(IdStartIndex, NodeObject.Id.ToString());
                }
            }

            return(RhinoApp.ParseTextField(ValueFormula, NodeObject, ParentObject));
        }