예제 #1
0
        public bool Read(GH_IReader reader)
        {
            foreach (var item in reader.Items)
            {
                var field = FindField(item.Name);
                var param = FindParam(item._guid);

                if (field == null)
                {
                    if (param != null)
                    {
                        m_UnRegister(param);
                    }
                }
                else if (param == null)
                {
                    param = new CsxParameter();
                    m_Register(param);
                    param.Field = field;
                    continue;
                }
                else
                {
                    param.Field = field;
                }
            }

            // In case the script defines more parameters than the current block.
            // Call Sync() to add and sort them
            Sync();

            return(true);
        }
예제 #2
0
        public void Sync()
        {
            var exists = new List <Guid>();

            // Update or register GH parameters
            foreach (var field in m_fields)
            {
                var param = FindParam(field.Info.Name);
                if (param != null)
                {
                    param.Field = field;
                }
                else
                {
                    param = new CsxParameter();
                    m_Register(param);
                    param.Field = field;
                }

                exists.Add(param.InstanceGuid);
            }

            // Remove inused GH parameters
            for (var i = m_params.Count - 1; i >= 0; --i)
            {
                if (!exists.Contains(m_params[i].InstanceGuid))
                {
                    m_UnRegister(m_params[i]);
                }
            }

            Sort();
        }