Esempio n. 1
0
 /// <summary>
 /// Removes the entity at the specified index on the list and it also removes it from PowerMill.
 /// </summary>
 /// <param name="index">The zero-based index of the element to remove.</param>
 public override void RemoveAt(int index)
 {
     if (index >= Count)
     {
         throw new IndexOutOfRangeException("Current number of items is " + Count);
     }
     _powerMILL.DoCommand("DELETE " + this[index].Identifier + " '" + this[index].Name + "'");
     base.RemoveAt(index);
 }
Esempio n. 2
0
 /// <summary>
 /// Initialises the item.
 /// </summary>
 /// <param name="powerMILL">The base instance to interact with PowerMILL.</param>
 /// <param name="projectDirectory">The project directory path.</param>
 /// <param name="openReadOnly">If true it will open as read only.</param>
 /// <remarks></remarks>
 internal PMProject(PMAutomation powerMILL, Directory projectDirectory, bool openReadOnly = false)
 {
     _powerMILL        = powerMILL;
     _projectDirectory = projectDirectory;
     if (openReadOnly)
     {
         _powerMILL.DoCommand("PROJECT READONLY OPEN '" + projectDirectory.Path + "'");
     }
     else
     {
         _powerMILL.DoCommand("PROJECT OPEN '" + projectDirectory.Path + "'");
     }
     Initialise();
 }
        /// <summary>
        /// Duplicates an entity. It also updates PowerMill.
        /// </summary>
        public virtual PMEntity Duplicate()
        {
            PMEntity copiedItem = null;

            // Use Clipboard copy for a model to avoid empty model
            if (Identifier == "MODEL")
            {
                PowerMill.DoCommand("EDIT MODEL '" + _name + "' CLIPBOARD COPY");
                PowerMill.DoCommand("CREATE MODEL CLIPBOARD");
            }
            else
            {
                PowerMill.DoCommand("Copy " + Identifier + " '" + _name + "'");
            }

            List <PMEntity> createdItems = PowerMill.ActiveProject.CreatedItems();

            if (createdItems.Count == 1)
            {
                if (createdItems[0].Identifier == Identifier)
                {
                    copiedItem = createdItems[0];
                }
                else
                {
                    throw new ApplicationException("Item not duplicated");
                }
            }
            else
            {
                List <PMEntity> entLst =
                    (from ent in createdItems where ent.Identifier == Identifier select ent).ToList();
                if ((entLst.Count > 1) | (entLst.Count == 0))
                {
                    throw new ApplicationException("Too many items created. Do not know which is the one duplicated!");
                }
                copiedItem = entLst[0];

                //return item
            }
            if (copiedItem != null)
            {
                PowerMill.ActiveProject.AddEntityToCollection(copiedItem);
            }
            return(copiedItem);
        }
        /// <summary>
        /// Duplicates an entity. It also updates PowerMill.
        /// </summary>
        public virtual PMEntity Duplicate()
        {
            PMEntity copiedItem = null;

            PowerMill.DoCommand("Copy " + Identifier + " '" + _name + "'");
            List <PMEntity> createdItems = PowerMill.ActiveProject.CreatedItems();

            if (createdItems.Count == 1)
            {
                if (createdItems[0].Identifier == Identifier)
                {
                    copiedItem = createdItems[0];
                }
                else
                {
                    throw new ApplicationException("Item not duplicated");
                }
            }
            else
            {
                List <PMEntity> entLst =
                    (from ent in createdItems where ent.Identifier == Identifier select ent).ToList();
                if ((entLst.Count > 1) | (entLst.Count == 0))
                {
                    throw new ApplicationException("Too many items created. Do not know which is the one duplicated!");
                }
                copiedItem = entLst[0];

                //return item
            }
            if (copiedItem != null)
            {
                PowerMill.ActiveProject.AddEntityToCollection(copiedItem);
            }
            return(copiedItem);
        }
Esempio n. 5
0
 /// <summary>
 /// This operation creates a Block in PowerMILL from a DMT file.
 /// </summary>
 /// <param name="blockFile">The DMT file from which to create the block.</param>
 public void CreateBlock(File blockFile)
 {
     _powerMILL.DoCommand("DELETE BLOCK \\r " + "EDIT BLOCKTYPE TRIANGLES \\r " + "EDIT BLOCK COORDINATE WORLD",
                          "GET BLOCK \"" + blockFile.Path + "\"",
                          "EDIT BLOCK DRAWMODE 25",
                          "EDIT BLOCK UPDATEFORM",
                          "BLOCK ACCEPT");
 }
Esempio n. 6
0
        /// <summary>
        /// Executes the next line in the macro and increments the index marker.
        /// </summary>
        /// <param name="hideDialogs">If true, hides all dialogs.</param>
        public override void RunStep(bool hideDialogs = true)
        {
            List <string> commands = ReplaceTokens(_lines[_localIndex]);
            string        trimLine = "";
            var           results  = new List <string>();

            foreach (string item in commands)
            {
                var command = item;

                // Handle the case where the line is trying to open a file
                if (hideDialogs && command.ToUpper().Contains("FILEOPEN"))
                {
                    //Macro could have filename on same line or next line.
                    trimLine = command.ToUpper().Trim();

                    // remove spaces
                    string[] works = trimLine.Split(' ');

                    //check last word
                    if (works[works.Length - 1] == "FILEOPEN")
                    {
                        // Instead of launching a dialog box, concatonate the two lines removing the FILEOPEN command
                        command = command.Substring(0, command.ToUpper().IndexOf("FILEOPEN")) +
                                  ReplaceTokens(_lines[_localIndex + 1])[0];
                        _localIndex += 2;
                        _totalIndex += 2;

                        //single line
                    }
                    else
                    {
                        //do nothing as already on line
                        _localIndex += 1;
                        _totalIndex += 1;
                    }

                    //_powerMILL.DoCommand(command)
                }
                else if (hideDialogs && command.ToUpper().Contains("FILESAVE"))
                {
                    trimLine = command.ToUpper().Trim();

                    // remove spaces
                    string[] works = trimLine.Split(' ');

                    //check last word
                    if (works[works.Length - 1] == "FILESAVE")
                    {
                        // Instead of launching a dialog box, concatonate the two lines removing the FILESAVE command
                        command = command.Substring(0, command.ToUpper().IndexOf("FILESAVE")) +
                                  ReplaceTokens(_lines[_localIndex + 1])[0];
                        _localIndex += 2;
                        _totalIndex += 2;

                        //single line
                    }
                    else
                    {
                        //do nothing as already on line
                        _localIndex += 1;
                        _totalIndex += 1;
                    }
                }
                else if (hideDialogs && command.ToUpper().Contains("TMPLTSELECTORGUI"))
                {
                    trimLine = command.ToUpper().Trim();

                    // remove spaces
                    string[] works = trimLine.Split(' ');

                    //check last word
                    if (works[works.Length - 1] == "TMPLTSELECTORGUI")
                    {
                        // Instead of launching a dialog box, concatonate the two lines removing the TMPLTSELECTORGUI command
                        command = command.Substring(0, command.ToUpper().IndexOf("TMPLTSELECTORGUI")) +
                                  ReplaceTokens(_lines[_localIndex + 1])[0];
                        _localIndex += 2;
                        _totalIndex += 2;

                        //single line
                    }
                    else
                    {
                        //do nothing as already on line
                        _localIndex += 1;
                        _totalIndex += 1;
                    }
                }
                else if (hideDialogs && command.ToUpper().StartsWith("FORM"))
                {
                    // Ignore first two words
                    if (command.IndexOf(" ", 5) != -1)
                    {
                        command = command.Substring(command.IndexOf(" ", 5) + 1);

                        //_powerMILL.DoCommand(command)
                    }
                    else
                    {
                        command = "$$$NothingToDo$$$";
                    }
                    _localIndex += 1;
                    _totalIndex += 1;
                }
                else if (hideDialogs && command.ToUpper().Contains(" FORM "))
                {
                    // Ignore the bit from the form command onward
                    command = command.Substring(0, command.ToUpper().IndexOf(" FORM "));

                    //_powerMILL.DoCommand(command)
                    _localIndex += 1;
                    _totalIndex += 1;
                }
                else if (command.ToUpper().StartsWith("MACRO"))
                {
                    //In some cases sub macros should be run as a single line. E.g they contain loops
                    if (RunSubMacrosOption == SubMacroRunOptions.RunAllLines)
                    {
                        _childMacro = new PMMacro(_powerMILL,
                                                  new FileSystem.File(command.Substring(command.IndexOf("\"") + 1,
                                                                                        command.LastIndexOf("\"") -
                                                                                        command.IndexOf("\"") - 1)));
                        _childMacro.Run();
                        command      = "$$ " + command;
                        _totalIndex += 1 + _childMacro.TotalCount;
                    }
                    else
                    {
                        _totalIndex += 1;
                    }
                    _localIndex += 1;
                }
                else if (command.ToUpper().StartsWith("RUNMACRO"))
                {
                    // Remove the "RUN" from the start and just run as a macro
                    command      = command.Substring(3);
                    _localIndex += 1;
                    _totalIndex += 1;
                }
                else
                {
                    // Otherwise just run the command
                    _localIndex += 1;
                    _totalIndex += 1;
                }
                bool bIgnoreCmdLine = false;
                if (DoNotExecuteCommentsOrBlankLines)
                {
                    string strCmd = command.Trim();

                    // remove whitespace
                    if (string.IsNullOrEmpty(strCmd) || strCmd.StartsWith("$$") || strCmd.StartsWith("//"))
                    {
                        //must use start with because have to account for case where comment is on right of a command.i.e
                        // PRINT ENTITY 'fred' $$ a comment
                        bIgnoreCmdLine = true;
                    }
                }
                if (command != "$$$NothingToDo$$$" && bIgnoreCmdLine == false)
                {
                    _executedCommands.Add(command);
                    if (UseExecuteEx == false)
                    {
                        _powerMILL.DoCommand(command);
                    }
                    else
                    {
                        // capture the result of the command for potential debugging purposes
                        string result = _powerMILL.DoCommandEx(command).ToString();
                        if (!string.IsNullOrEmpty(result.Trim()))
                        {
                            _executedCommands.Add("$$ MESSAGE INVOKED:");

                            //EchoCommand("$$ MESSAGE INVOKED:")
                            foreach (
                                string ritem in
                                result.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                            {
                                _executedCommands.Add("$$ " + ritem);

                                //EchoCommand("$$ " + ritem)
                            }
                        }
                    }
                }
            }

            // Rejig the counters for where extra lines were inserted because of the ReplaceTokens command
            if (commands.Count > 1)
            {
                _localIndex -= commands.Count - 1;
                _totalIndex -= commands.Count - 1;
            }
        }