Exemple #1
0
            /// <summary>
            /// Create Logger
            /// </summary>
            /// <returns>Logger Interface</returns>
            private ILogger CreateLogger()
            {
                var logger = new LogManager();

                logger.Add(new ConsoleLogger());
                logger.Add(new FileLogger("Log.txt"));

                return(logger);
            }
Exemple #2
0
        public string GetParameter(InventorDocument workingDocument, string paramName)
        {
            var parameter = workingDocument.Parameters.FirstOrDefault(x => x.Name == paramName);

            if (parameter == null)
            {
                LogManager.Add($"Could not find parameter {paramName} in {workingDocument.Name}");
                return("Not Found");
            }

            switch (parameter.UnitType)
            {
            case UnitTypes.Length:
            case UnitTypes.Angular:
                return(UnitManager.UnitsFromInventor(parameter.Value, parameter.UnitType).ToString());

            case UnitTypes.Unitless:
                return(parameter.Value.ToString());

            case UnitTypes.Text:
                return(parameter.Value.ToString());

            default:
                return("");
            }
        }
Exemple #3
0
        public void SetParameter(InventorDocument document, string paramName, string value)
        {
            var parameter = document.Parameters.FirstOrDefault(x => x.Name == paramName);

            if (parameter == null)
            {
                LogManager.Add($"Could not find parameter {paramName} in {document.Name}");
                return;
            }

            switch (parameter.UnitType)
            {
            case UnitTypes.Length:
            case UnitTypes.Angular:
                parameter.Value = UnitManager.UnitsToInventor(ConverterHelpers.ConvertDouble(value), parameter.UnitType);
                break;

            case UnitTypes.Unitless:
                parameter.Value = ConverterHelpers.ConvertInt(value);
                break;

            case UnitTypes.Text:
                parameter.Value = value;
                break;
            }
        }
Exemple #4
0
        public void Suppression(InventorDocument document, string component, string suppressed, SuppresionType suppresionType)
        {
            var status = suppressed.ToUpper() == "S";

            try
            {
                switch (suppresionType)
                {
                case SuppresionType.Component:
                    document.GetAssemblyDocument().Components.SetComponentStatus(component, status);
                    break;

                case SuppresionType.Constraint:
                    document.GetAssemblyDocument().Constraints.SetConstraintStatus(component, status);
                    break;

                case SuppresionType.Pattern:
                    document.GetAssemblyDocument().Patterns.SuppressPattern(component, status);
                    break;

                case SuppresionType.Feature:
                    document.SetFeatureStatus(component, status);
                    break;
                }
            }
            catch (Exception ex)
            {
                LogManager.Add(ex.Message);
            }
        }
Exemple #5
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);
        }
        public void SetVisiblity(SolidworksDocument document, string name, bool visibilty, string featureType)
        {
            document.ClearSelection();

            try
            {
                switch (featureType)
                {
                case FeatureTypes.Component:
                    document.Select(name, FeatureTypes.Component);
                    break;
                }

                if (document.SelectedCount() != 1)
                {
                    throw new Exception($"Could not find {name} in {document.Name}");
                }

                if (visibilty)
                {
                    document.ShowSelected();
                }
                else
                {
                    document.HideSelected();
                }
            }
            catch (Exception ex)
            {
                LogManager.Add(ex.Message);
            }
        }
Exemple #7
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);
            }
        }
        public string GetDimValue(SolidworksDocument workingDocument, string name, string configuration)
        {
            var dim = workingDocument.GetSolidworksDimension(name);

            if (dim == null)
            {
                LogManager.Add($"Could not find dimension {name} in {workingDocument.Name}");
                return("");
            }

            double value = dim.GetValue(string.IsNullOrEmpty(configuration) ? ConfigurationOptions.ThisConfiguration
                                                                            : ConfigurationOptions.SpecifyConfiguration,
                                        configuration);
            double convertedValue;

            switch (dim.Type)
            {
            case DimensionTypes.Linear:
                convertedValue = UnitManager.UnitsFromSolidworks(value);
                break;

            case DimensionTypes.Angular:
                convertedValue = UnitManager.ConvertRadians(value);
                break;

            case DimensionTypes.Integer:
            default:
                convertedValue = value;
                break;
            }

            return(convertedValue.ToString());
        }
Exemple #9
0
 public void DeleteReferenced(InventorDocument document, string component)
 {
     try
     {
         document.GetAssemblyDocument().Components.DeleteComponents(component);
     }
     catch (Exception ex)
     {
         LogManager.Add(ex.Message);
     }
 }
        public string GetEquation(SolidworksDocument workingDocument, string name)
        {
            var equation = workingDocument.Equations.GetEquation(name);

            if (equation == null)
            {
                LogManager.Add($"Could not find equation {name} in {workingDocument.Name}");
            }

            return(equation == null ? "" : equation.Value.ToString());
        }
 public void ShowConfiguration(SolidworksDocument document, string configurationName)
 {
     if (document.ConfigurationExists(configurationName))
     {
         document.ShowConfiguration(configurationName);
     }
     else
     {
         LogManager.Add($"{configurationName} does not exist in document {document.Name}");
     }
 }
 public void SetProperty(SolidworksDocument document, string propertyName, string value)
 {
     try
     {
         document.ActiveConfiguration.Properties.SetValue(propertyName, value);
     }
     catch (Exception ex)
     {
         LogManager.Add(ex.Message);
     }
 }
        public void Suppression(SolidworksDocument document, string name, string value, SuppresionType suppresionType)
        {
            var status = value.ToUpper() == "S";

            document.ClearSelection();

            try
            {
                switch (suppresionType)
                {
                case SuppresionType.Component:
                    document.Select(name, FeatureTypes.Component);
                    break;

                case SuppresionType.Constraint:
                    document.Select(name, FeatureTypes.Mate);
                    break;

                case SuppresionType.Feature:
                    document.Select(name, FeatureTypes.BodyFeature);
                    break;

                case SuppresionType.Pattern:
                    document.Select(name, FeatureTypes.ComponentPattern);
                    break;

                case SuppresionType.Folder:
                    document.Select(name, FeatureTypes.Folder);
                    break;
                }

                if (document.SelectedCount() != 1)
                {
                    throw new Exception($"Could not find {name} in {document.Name}");
                }

                if (status)
                {
                    document.SuppressSelected();
                }
                else
                {
                    document.UnsuppressSelected();
                }
            }
            catch (Exception ex)
            {
                LogManager.Add(ex.Message);
            }
        }
        public string GetProperty(SolidworksDocument document, string propertyName)
        {
            var value = "";

            try
            {
                value = document.ActiveConfiguration.Properties.GetValue(propertyName);
            }
            catch (Exception ex)
            {
                LogManager.Add(ex.Message);
            }

            return(value);
        }
        public void SetComponentConfiguration(SolidworksDocument document, string componentName, string configurationName)
        {
            document.ClearSelection();

            document.Select(componentName, FeatureTypes.Component);

            if (document.SelectedCount() != 1)
            {
                LogManager.Add($"Could not find {componentName} in {document.Name}");
                return;
            }

            var comp = document.GetSelectedComponent();

            if (comp != null)
            {
                comp.ReferencedConfiguration = configurationName;
            }
        }
 private void lbBuild_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show(TextManager.Get().Text("buildsav"), "RouteTycoon", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             SaveFileDialog sfd = new SaveFileDialog();
             sfd.Title  = TextManager.Get().Text("selectsavepath");
             sfd.Filter = "sav 파일|*.sav";
             if (sfd.ShowDialog() == DialogResult.OK)
             {
                 try
                 {
                     GameManager.Sandbox       = false;
                     GameManager.isBuild       = true;
                     GameManager.Company.Money = 0;
                     GameManager.SaveExtraPath(sfd.FileName.Substring(0, sfd.FileName.Length - 4));
                     MessageBox.Show(TextManager.Get().Text("buildcomplete"), "RouteTycoon", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     SceneManager.SetScene(new MainPlayScene(), AccessManager.AccessKey);
                     return;
                 }
                 catch (Exception ex)
                 {
                     LogManager.Add(new Log()
                     {
                         evt = Log.Event.MESSAGE, type = Log.Type.ERROR, Message = $@"GameManager - 빌드 도중 오류 발생\n에러 메세지: {ex.ToString()}"
                     });
                     MessageBox.Show(TextManager.Get().Text("builderr"), "RouteTycoon", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     return;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         RTCore.Environment.ReportError(ex, AccessManager.AccessKey);
     }
 }
        public void SetDimValue(SolidworksDocument workingDocument, string name, string configuration, double value)
        {
            var dim = workingDocument.GetSolidworksDimension(name);

            if (dim == null)
            {
                LogManager.Add($"Could not find dimension {name} in {workingDocument.Name}");
                return;
            }

            double convertedValue;

            switch (dim.Type)
            {
            case DimensionTypes.Linear:
                convertedValue = UnitManager.UnitsToSolidworks(value);
                break;

            case DimensionTypes.Angular:
                convertedValue = UnitManager.ConvertDegrees(value);
                break;

            case DimensionTypes.Integer:
            default:
                convertedValue = value;
                break;
            }

            var success = dim.SetValue(convertedValue, string.IsNullOrEmpty(configuration) ? ConfigurationOptions.ThisConfiguration
                                                                                           : ConfigurationOptions.SpecifyConfiguration,
                                       configuration);

            if (!success)
            {
                LogManager.Add($"Could not set dim {name} in {workingDocument.Name}");
            }
        }
        public void SetWeldmentMemberConfiguration(SolidworksDocument document, string featurename, string configurationName)
        {
            document.ClearSelection();

            document.Select(featurename, FeatureTypes.BodyFeature);

            if (document.SelectedCount() != 1)
            {
                LogManager.Add($"Could not find {featurename} in {document.Name}");
                return;
            }

            var feature = document.GetSelectedFeature();

            if (feature.TypeName.ToUpper() == FeatureSubTypes.WeldMemberFeat.ToUpper())
            {
                feature.SetWeldmentConfiguration(configurationName);
            }
            else
            {
                LogManager.Add($"Feature {featurename} in {document.Name} is not a weldment member");
                return;
            }
        }
        /// <summary>
        /// Run application against the commands in the excel file
        /// </summary>
        /// <param name="rangeName"></param>
        /// <param name="rangeParameter"></param>
        /// <returns></returns>
        public void Run(string rangeName = "", string rangeParameter = "")
        {
            // The start cell
            Excel.Range startCell = null;

            // if the range name is null get the name of the current sheet plus type
            if (string.IsNullOrEmpty(rangeName))
            {
                startCell = _worksheet.Range[_worksheet.Name + "Type"];
            }
            else
            {
                startCell = _worksheet.Range[rangeName];
            }

            if (startCell == null) throw new Exception("Could not find start range");

            // Column for the type of commands we are running
            var typeCol = startCell.Column;

            // Name of the document or sub we are working with
            var nameCol = typeCol + 1;

            // Parent of the document we are working 
            var parentCol = nameCol + 1;

            // Value to set or get based on command
            var value = parentCol + 1;

            // Secondary value for some commands
            var value2 = value + 1;

            // Set the start orw
            var i = startCell.Row + 1;

            // loop while the command column is not null
            while (!string.IsNullOrEmpty(GetString(i, typeCol)))
            {
                // get the command we are working with
                var command = GetString(i, typeCol).ToUpper();

                // if the command is a comment continue
                if (command == Commands.Comment)
                {
                    i++;
                    continue;
                }
                // Open the document 
                else if (command == Commands.OpenDocument)
                {
                    _methods.OpenDocument(GetString(i, nameCol), GetString(i, parentCol), GetString(i, value), GetString(i, value2));
                    i++;
                    continue;
                }

                // Assign the working document
                var workingDocumentName = GetString(i, parentCol);

                // working document name is null then assign the working document to the document
                if (string.IsNullOrEmpty(workingDocumentName))
                {
                    if (_topDocument == null)
                    {
                        _topDocument = InventorApplication.ActiveDocument;
                    }

                    _workingDocument = _topDocument;
                }
                // Assign the working document
                else
                {
                    // if the working document is null then assign
                    if (_workingDocument == null)
                    {
                        _workingDocument = DocumentHelper.GetDocument(workingDocumentName);

                        if (_workingDocument == null)
                        {
                            LogManager.Add($"Could not find document {workingDocumentName}. If all occurences are suppressed you can ignore this error.");
                            i++;
                            continue;
                        }
                    }
                    // if the working document does not match working document name then assign it.
                    else
                    {
                        if (_workingDocument.Name != workingDocumentName)
                        {
                            _workingDocument = DocumentHelper.GetDocument(workingDocumentName);
                        }

                        if (_workingDocument == null)
                        {
                            LogManager.Add($"Could not find document {workingDocumentName}. If all occurences are suppressed you can ignore this error.");
                            i++;
                            continue;
                        }
                    }
                }

                switch (command)
                {
                    case Commands.TopLevelName:
                        var topLevelName = GetString(i, nameCol);

                        if (InventorApplication.ActiveDocument.Name != topLevelName)
                        {
                            throw new Exception("Top level name does not match active model");
                        }
                        else
                        {
                            _topDocument = InventorApplication.ActiveDocument;
                        }
                        break;
                    case Commands.Parameter:
                        _methods.SetParameter(_workingDocument, GetString(i, nameCol), GetString(i, value));
                        break;
                    case Commands.GetParameter:
                        var parameterValue = _methods.GetParameter(_workingDocument, GetString(i, nameCol));
                        SetValue(i, value, parameterValue);
                        break;
                    case Commands.SetProperty:
                        _methods.SetProperty(_workingDocument, GetString(i, nameCol), GetString(i, value));
                        break;
                    case Commands.GetProperty:
                        var propertyValue = _methods.GetProperty(_workingDocument, GetString(i, nameCol));
                        SetValue(i, value, propertyValue);
                        break;
                    case Commands.ComponentActivity:
                        _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Component);
                        break;
                    case Commands.ConstraintActivity:
                        _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Constraint);
                        break;
                    case Commands.PatternActivity:
                        _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Pattern);
                        break;
                    case Commands.FeatureActivity:
                        _methods.Suppression(_workingDocument, GetString(i, nameCol), GetString(i, value), SuppresionType.Feature);
                        break;
                    case Commands.DeleteComponent:
                        _methods.Delete(_workingDocument, GetString(i, nameCol));
                        break;
                    case Commands.DeleteReferencedDocuments:
                        _methods.DeleteReferenced(_workingDocument, GetString(i, nameCol));
                        break;
                    case Commands.Stop:
                        throw new Exception("Program Stopped");
                    case Commands.UpdateDocument:
                        _workingDocument.Update();
                        break;
                    case Commands.Sub:
                        ProcessRunBlockInventor runBlock = null;
                        var subName = GetString(i, nameCol);
                        var workSheetName = "";
                        
                        if (subName.Contains("!"))
                        {
                            var subSplit = subName.Split('!');

                            workSheetName = subSplit[0];
                            subName = subSplit[1];

                            runBlock = new ProcessRunBlockInventor(Globals.ThisAddIn.Application.ActiveWorkbook.GetWorksheets().FirstOrDefault(x => x.Name == workSheetName), _topDocument);
                        }
                        else
                        {
                            runBlock = new ProcessRunBlockInventor(_worksheet, _topDocument);
                        }

                        runBlock.Run(subName, GetString(i, value));
                        break;
                    case Commands.If:
                        ValidateIf(i, typeCol);

                        var booleanValue = GetBoolean(i, value);

                        if (!booleanValue)
                        {
                            i = GetEndIfRow(i, typeCol);
                        }
                        break;
                    case Commands.Repeat:
                        ValidateRepeat(i, typeCol);
                        repeatStart = i;
                        repeatEnd = GetEndRepeatRow(i, typeCol);
                        repeatCount = GetInt(i, value);
                        repeatIndex = 1;
                        SetValue(i, value2, repeatIndex.ToString());
                        inRepeat = true;
                        break;
                }

                i++;

                if (inRepeat)
                {
                    if (i == repeatEnd)
                    {
                        if (repeatIndex == repeatCount)
                        {
                            i = repeatEnd + 1;
                            repeatStart = 0;
                            repeatEnd = 0;
                            repeatCount = 0;
                            repeatIndex = 0;
                            inRepeat = false;
                        }
                        else
                        {
                            i = repeatStart + 1;
                            repeatIndex++;
                            SetValue(repeatStart, value2, repeatIndex.ToString());
                        }
                    }
                }
            }

            if (_topDocument != null)
            {
                if (InventorApplication.ActiveDocument.Name != _topDocument.Name)
                {
                    InventorApplication.ActiveDocument.Save();

                    InventorApplication.ActiveDocument.Close();
                }
            }

            InventorApplication.ActiveDocument.Update();

            InventorApplication.ActiveDocument.Save();
        }
Exemple #20
0
        private void itemBuild_Click(object sender, EventArgs e)
        {
            try
            {
                if (lstSave.SelectedItems.Count == 1)
                {
                    if (lbInfo.Text == TextManager.Get().Text("notsavefile") || lbInfo.Text == TextManager.Get().Text("savevernot") || lbInfo.Text == TextManager.Get().Text("oldmap") || lbInfo.Text == TextManager.Get().Text("notmap") || lbInfo.Text == TextManager.Get().Text("nomap") || lbInfo.Text == TextManager.Get().Text("readerr"))
                    {
                        Dictionary <string, string> d = new Dictionary <string, string>();
                        d.Add("%MESSAGE%", lbInfo.Text);
                        MessageBox.Show(TextManager.Get().Text("cannotbuild", true, d), "RouteTycoon", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (MessageBox.Show(TextManager.Get().Text("buildsav"), "RouteTycoon", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        SaveFileDialog sfd = new SaveFileDialog();
                        sfd.Title  = TextManager.Get().Text("selectsavepath");
                        sfd.Filter = "sav 파일|*.sav";
                        if (sfd.ShowDialog() == DialogResult.OK)
                        {
                            try
                            {
                                GameManager.Load(lstSave.SelectedItems[0].ToString());
                                string dev = "";
                                while (true)
                                {
                                    dev = Microsoft.VisualBasic.Interaction.InputBox(TextManager.Get().Text("inputdeveloper"), "RouteTycoon");
                                    if (dev.Trim() == string.Empty)
                                    {
                                        if (MessageBox.Show(TextManager.Get().Text("cannotempty"), "RouteTycoon", MessageBoxButtons.RetryCancel, MessageBoxIcon.Stop) == DialogResult.Cancel)
                                        {
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        dev = dev.Trim();
                                        break;
                                    }
                                }
                                GameManager.SaveInfo      = $"Developer: {dev}\nisSandbox: {GameManager.Sandbox.ToString().ToLower()}\nisUseCheat: {GameManager.UseCheat.ToString().ToLower()}\nPlayer Income: {string.Format("{0:n0}", GameManager.Company.Income)}RTW\nCreate Date: {GameManager.CreateTime.Year}-{GameManager.CreateTime.Month}-{GameManager.CreateTime.Day} {GameManager.CreateTime.Hour}:{GameManager.CreateTime.Minute}:{GameManager.CreateTime.Second}";
                                GameManager.Sandbox       = false;
                                GameManager.isBuild       = true;
                                GameManager.Company.Money = 0;
                                GameManager.SaveExtraPath(sfd.FileName.Substring(0, sfd.FileName.Length - 4));
                                LoadSaves();
                                MessageBox.Show(TextManager.Get().Text("buildcomplete"), "RouteTycoon", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                return;
                            }
                            catch (Exception ex)
                            {
                                LogManager.Add(new Log()
                                {
                                    evt = Log.Event.MESSAGE, type = Log.Type.ERROR, Message = $@"GameManager - 빌드 도중 오류 발생\n에러 메세지: {ex.ToString()}"
                                });
                                MessageBox.Show(TextManager.Get().Text("builderr"), "RouteTycoon", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                RTCore.Environment.ReportError(ex, AccessManager.AccessKey);
            }
        }