コード例 #1
0
        public InventorParameters ExtractParameters(Document doc, dynamic userParameters)
        {
            /* The resulting json will be like this:
             * {
             *  "length" : {
             *    "unit": "in",
             *    "value": "10 in",
             *    "values": ["5 in", "10 in", "15 in"]
             *  },
             *  "width": {
             *    "unit": "in",
             *    "value": "20 in",
             *  }
             * }
             */
            try
            {
                var parameters = new InventorParameters();
                foreach (dynamic param in userParameters)
                {
                    var nominalValue = param.Expression;
                    try
                    {
                        var unitType = doc.UnitsOfMeasure.GetTypeFromString(param.Units);
                        var value    = doc.UnitsOfMeasure.GetValueFromExpression(param.Expression, unitType);
                        nominalValue = doc.UnitsOfMeasure.GetPreciseStringFromValue(value, unitType);
                    }
                    // not all unitTypes seem to be convertible (e.g. kTextUnits). In that case, we'll go on with param.Expression assigned before.
                    catch (Exception e)
                    {
                        LogError("Can't get nominalValue for " + param.Name + ": " + e.Message);
                    }

                    var parameter = new InventorParameter
                    {
                        Unit   = param.Units,
                        Value  = nominalValue,
                        Values = param.ExpressionList?.GetExpressionList() ?? new string[0]
                    };
                    parameters.Add(param.Name, parameter);
                }

                return(parameters);
            }
            catch (Exception e)
            {
                LogError("Error reading params: " + e.Message);
                return(null);
            }
        }
コード例 #2
0
            private void ProcessParameter(ParameterControlSpec spec)
            {
                if (_allowedParameters.TryGetValue(spec.ParameterName, out var knownParameter))
                {
                    var result = new InventorParameter
                    {
                        Label    = spec.Name.Trim(),
                        Unit     = knownParameter.Unit,
                        ReadOnly = spec.ReadOnly,
                        Value    = knownParameter.Value,
                        Values   = knownParameter.Values
                    };

                    _collectedParameters.Add(spec.ParameterName, result);
                }
            }
コード例 #3
0
        private InventorParameters ExtractParameters(Document doc, dynamic userParameters)
        {
            /* The resulting json will be like this:
             * {
             *  "length" : {
             *    "unit": "in",
             *    "value": "10 in",
             *    "values": ["5 in", "10 in", "15 in"]
             *  },
             *  "width": {
             *    "unit": "in",
             *    "value": "20 in",
             *  }
             * }
             */
            try
            {
                var parameters        = new InventorParameters();
                var docUnitsOfMeasure = doc.UnitsOfMeasure;
                foreach (dynamic param in userParameters)
                {
                    var    nominalValue = param.Expression;
                    string errorMessage = null;
                    try
                    {
                        var unitType = docUnitsOfMeasure.GetTypeFromString(param.Units);
                        LogTrace($"Checking expression validity on extraction for {param.Expression} and unit type {param.Units} / {unitType}");
                        if (docUnitsOfMeasure.IsExpressionValid(param.Expression, unitType))
                        {
                            var value = docUnitsOfMeasure.GetValueFromExpression(param.Expression, unitType);
                            nominalValue = docUnitsOfMeasure.GetPreciseStringFromValue(value, unitType);
                        }
                        else
                        {
                            LogTrace($"Expression '{param.Expression}' invalid for unit type '{unitType}' on extract attempt");
                            errorMessage = "Parameter's expression is not valid for its unit type";
                        }
                    }
                    // not all unitTypes seem to be convertible (e.g. kTextUnits). In that case, we'll go on with param.Expression assigned before.
                    catch (Exception e)
                    {
                        LogError("Can't get nominalValue for " + param.Name + ": " + e.Message);
                    }

                    var parameter = new InventorParameter
                    {
                        Unit         = param.Units,
                        Value        = nominalValue,
                        Values       = param.ExpressionList?.GetExpressionList() ?? new string[0],
                        ErrorMessage = errorMessage
                    };
                    parameters.Add(param.Name, parameter);
                }

                return(parameters);
            }
            catch (Exception e)
            {
                LogError("Error reading params: " + e.Message);
                return(null);
            }
        }