private void UpdateExternalValue()
        {
            SolidEdgeFramework.Application       application    = null;
            SolidEdgeFramework.SolidEdgeDocument document       = null;
            SolidEdgeFramework.UnitsOfMeasure    unitsOfMeasure = null;

            try
            {
                application    = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");
                document       = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument;
                unitsOfMeasure = document.UnitsOfMeasure;
                _externalValue = unitsOfMeasure.FormatUnit((int)_unitType, _internalValue, _precision);
            }
            catch (System.Exception ex)
            {
                _externalValue = ex.Message;
            }
            finally
            {
                if (unitsOfMeasure != null)
                {
                    Marshal.ReleaseComObject(unitsOfMeasure);
                }
                if (document != null)
                {
                    Marshal.ReleaseComObject(document);
                }
                if (application != null)
                {
                    Marshal.ReleaseComObject(application);
                }
            }
        }
Example #2
0
        public static double GetValueofCurrentMeasure(SolidEdgeFramework.UnitsOfMeasure unitesOfMeasure, int unitsType, double value)
        {
            string result = unitesOfMeasure.FormatUnit(unitsType, value).ToString();

            string[] strArray = result.Split(' ');
            if (strArray.Length == 2 && strArray[0] != "")
            {
                result = strArray[0];
            }
            else if (strArray.Length == 3 && strArray[1] != "")
            {
                result = strArray[1];
            }
            return(double.Parse(result));
        }
Example #3
0
        public PartProperty(object property, SolidEdgeFramework.UnitsOfMeasure unitesOfMeasure)
        {
            // TODO: Fix error in ST9 with UnitsType not accessible

            /**
             * try {
             *  this.unitType = dimension.UnitsType;
             * } catch (Exception ex) {
             *  log.Error(ex.Message);
             * }
             **/
            try {
                Type type = property.GetType();
                SolidEdgeFramework.ObjectType objectType = (SolidEdgeFramework.ObjectType)type.InvokeMember("Type", System.Reflection.BindingFlags.GetProperty, null, property, null);
                switch (objectType)
                {
                case SolidEdgeFramework.ObjectType.igDimension:
                    SolidEdgeFrameworkSupport.Dimension dimension = (SolidEdgeFrameworkSupport.Dimension)property;
                    this.Name  = dimension.DisplayName.ToString();
                    this.Value = GetValueofCurrentMeasure(unitesOfMeasure, this.UnitType, dimension.Value);
                    this.Units = GetUnitsOfCurrentMeasure(unitesOfMeasure, this.UnitType, dimension.Value);
                    Marshal.FinalReleaseComObject(dimension);
                    break;

                // Currently only supporting dimension properties
                case SolidEdgeFramework.ObjectType.igVariable:
                    SolidEdgeFramework.variable variable = (SolidEdgeFramework.variable)property;
                    this.Name  = variable.DisplayName.ToString();
                    this.Value = GetValueofCurrentMeasure(unitesOfMeasure, this.UnitType, variable.Value);
                    this.Units = GetUnitsOfCurrentMeasure(unitesOfMeasure, this.UnitType, variable.Value);
                    Marshal.FinalReleaseComObject(variable);
                    break;
                }
            } catch (Exception ex) {
                log.Error(ex.Message);
            }
        }
Example #4
0
 public double GetSolidEdgeStoredValue(SolidEdgeFramework.UnitsOfMeasure unitesOfMeasure)
 {
     return((double)unitesOfMeasure.ParseUnit(this.UnitType, this.Value.ToString()));
 }