}       // end function



        #region PROTOBUF

        protected MetaLinkProtobuf.Edit ModifyCADParameterProtoBufMsg(string in_ComponentInstanceID,
                                                                   CADParameter in_CADParameter)
        {
            MetaLinkProtobuf.ParametricParametersType ParametricParameters = new MetaLinkProtobuf.ParametricParametersType()
            {
                ComponentID = in_ComponentInstanceID
            };



            MetaLinkProtobuf.CADParameterType CADParameter_msg = new MetaLinkProtobuf.CADParameterType
            {
                Name = in_CADParameter.Name,
                Type = in_CADParameter.Type,
                Value = in_CADParameter.Value
            };

            ParametricParameters.CADParameter.Add(CADParameter_msg);


            MetaLinkProtobuf.Payload Payload_msg = new MetaLinkProtobuf.Payload();
            Payload_msg.parameters.Add(ParametricParameters);

            MetaLinkProtobuf.Action Action_msg = new MetaLinkProtobuf.Action
            {
                actionMode = MetaLinkProtobuf.Action.ActionMode.REPLACE,
                payload = Payload_msg
            };

            MetaLinkProtobuf.Edit Edit_msg = new MetaLinkProtobuf.Edit
            {
                editMode = MetaLinkProtobuf.Edit.EditMode.POST,
                guid = Guid.NewGuid().ToString(),
                sequence = 0,
            };
            Edit_msg.origin.Add(GMEOrigin);

            Edit_msg.actions.Add(Action_msg);
            Edit_msg.topic.Add(CadAssemblyTopic);
            Edit_msg.topic.Add(AssemblyID);

            return Edit_msg;
        }
        /*
        private void RunFormulaEvaluator(CyPhyML.ValueFlowTarget vft,
                                        MgaFCO vft_parent,
                                        MgaProject project)
        {
            if (vft_parent.MetaBase.Name == "Component" || vft_parent.MetaBase.Name == "ComponentAssembly")
            {
                // Formula Evaluator doesn't work correctly, using elaborator instead.
                
                Type tFormulaEval = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyFormulaEvaluator");
                IMgaComponentEx formulaEval = Activator.CreateInstance(tFormulaEval) as IMgaComponentEx;

                MgaFCOs selected = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs"));
                formulaEval.Initialize(project);
                formulaEval.InvokeEx(project, vft_parent, selected, 0);
                
                
            }
            else
                return;
        }*/

        private void ModifyCADParameter(CyPhyML.CADParameter cyphycadparam)
        {
            // [1] Find ComponentInstanceID
            // [2] Create Protobuf Message
            // [3] Send message

            if (cyphycadparam != null)
            {
                CADParameter cadparam = new CADParameter((cyphycadparam.Attributes.ParameterName == "") ? cyphycadparam.Name : cyphycadparam.Attributes.ParameterName,
                                                            cyphycadparam.Attributes.CADParameterType.ToString(),
                                                            (cyphycadparam.Attributes.Value == "") ? (cyphycadparam.Attributes.DefaultValue == "") ? "0" : cyphycadparam.Attributes.DefaultValue : cyphycadparam.Attributes.Value);


                // [1] Find ComponentInstanceID
                if (cyphycadparam.ParentContainer != null && cyphycadparam.ParentContainer.ParentContainer != null)
                {
                    if (cyphycadparam.ParentContainer.Kind=="ComponentRef" && cyphycadparam.ParentContainer.ParentContainer.Kind == "Component")
                    {
                        string componentInstanceID = (cyphycadparam.ParentContainer as CyPhyML.ComponentRef).Attributes.InstanceGUID;


                        // [2] Create Protobuf Message
                        MetaLinkProtobuf.Edit message = ModifyCADParameterProtoBufMsg(componentInstanceID,
                                                                                        cadparam);

                        // [3] Send message
                        bridgeClient.SendToMetaLinkBridge(message);
                    }
                    else
                    {
                        GMEConsole.Warning.WriteLine("Parent container for parameter {0} is not a ComponentRef." + cyphycadparam.Name);
                    }
                }
                else
                {
                    GMEConsole.Warning.WriteLine("Can't find parent container for parameter: " + cyphycadparam.Name);
                }


            }
        }       // end function