Exemplo n.º 1
0
        public void SetProperty(InventorDocument document, string propertyName, string value)
        {
            var properties = GetIpropertyEnums();

            IpropertyEnum iproperty = IpropertyEnum.Custom;

            foreach (var p in properties)
            {
                if (p.GetDescription().ToUpper() == propertyName.ToUpper())
                {
                    iproperty = p;
                    break;
                }
            }

            if (document == null)
            {
                throw new Exception("Could not find document to set property on");
            }

            try
            {
                document.Properties.SetPropertyValue(iproperty, value, propertyName);
            }
            catch (Exception ex)
            {
                LogManager.Add(ex.Message);
            }
        }
Exemplo n.º 2
0
        public string GetProperty(InventorDocument document, string propertyName)
        {
            var properties = GetIpropertyEnums();

            IpropertyEnum iproperty = IpropertyEnum.Custom;

            foreach (var p in properties)
            {
                if (p.GetDescription().ToUpper() == propertyName.ToUpper())
                {
                    iproperty = p;
                    break;
                }
            }

            if (document == null)
            {
                throw new Exception("Could not find document to set property on");
            }

            var value = document.Properties.GetPropertyValue(iproperty, propertyName);

            if (string.IsNullOrEmpty(value))
            {
                LogManager.Add($"Could not find property {propertyName} in {document.Name}");
            }

            return(value);
        }
        /// <summary>
        /// Gets the given iproperty if the custom is selected give the name
        /// </summary>
        /// <param name="ipropertyEnum"></param>
        /// <param name="customName"></param>
        /// <returns></returns>
        public string GetPropertyValue(IpropertyEnum ipropertyEnum, string customName = "")
        {
            var property = ipropertyEnum == IpropertyEnum.Custom ?
                           PropertyExists(customName) ? _propertySets[ipropertyEnum.GetCategory()][customName] : null :
                           _propertySets[ipropertyEnum.GetCategory()][ipropertyEnum.GetDescription()];

            if (property == null)
            {
                return("");
            }

            return(property.Value as string);
        }
        /// <summary>
        /// Sets the value of the given property
        /// </summary>
        /// <param name="ipropertyEnum"></param>
        /// <param name="value"></param>
        /// <param name="customName"></param>
        /// <exception cref="Exception"></exception>
        public void SetPropertyValue(IpropertyEnum ipropertyEnum, string value, string customName)
        {
            Property property = null;

            if (ipropertyEnum == IpropertyEnum.Custom)
            {
                var customProperties = _propertySets[ipropertyEnum.GetCategory()];

                foreach (Property p in customProperties)
                {
                    if (p.Name == customName)
                    {
                        property = p;
                        break;
                    }
                }
            }
            else
            {
                property = _propertySets[ipropertyEnum.GetCategory()][ipropertyEnum == IpropertyEnum.Custom ? customName : ipropertyEnum.GetDescription()];
            }

            if (property == null)
            {
                if (ipropertyEnum == IpropertyEnum.Custom)
                {
                    _propertySets[ipropertyEnum.GetCategory()].Add(value, customName);
                }
                else
                {
                    throw new Exception($"Could not set {(ipropertyEnum == IpropertyEnum.Custom ? customName : ipropertyEnum.GetDescription())}");
                }
            }
            else
            {
                property.Value = value;
            }
        }