Starting Print From Custom Plugin

Hi, I made a custom plugin for Repetier-Host that edits the "composition.gcode " according to some user definitions. I'd like to add a "start" button to this plugin, so when clicked it runs the editted gcode. I tried using "RepetierHostExtender.basic.Printjob.BeginJob();", but it doesn't work. Is there a way of doing it?

Comments

  • That is actually not the correct function. It is just part of how to fill the job command list. The correct function is RunJob in the printer connector that is connected with printer. Just for you to show how it uses the printjob the sources:

            public override void RunJob()
            {
                bool isContinuedJob = false; // @continuedScript
                List<GCodeShort> content = Main.main.editor.getContentArray();
                if (content.Count == 0) return; // nothing to print
                if (content[0].Text.StartsWith("@continuedScript"))
                    isContinuedJob = true;
                job.BeginJob();
                if (!isContinuedJob)
                    job.PushGCodeShortArray(Main.main.ActivePrinter.ScriptAsGCodeShort(0));
                job.PushGCodeShortArray(content);
                if (!isContinuedJob)
                    job.PushGCodeShortArray(Main.main.ActivePrinter.ScriptAsGCodeShort(1));
                job.EndJob();
                host.UpdateJobButtons();
            }

    But I'm not sure your solution is correct at all. Changing composition.gcode has no effect on the host. You can make such a modification if you enable the postprocessor in host so it is run directly after slicing. But after slicing that file gets loaded and from there on ignored. So if you modify it afterwards you need to reload the gcode to include it in host and from there on the regular print button also will work.
  • So if after I altered composition.gcode, I reload the gcode to include it in the host and then use the RunJob() command, it should print the modified file even when using the regular print button? Is there a method to reload the gcode outside the slicing tab? Currently, I read the composition.gcode to a list and then send it line by line with the "host.Connection.injectManualCommand()" method, but this does not allow for pause or cancel.
  • Ok that solution is really bad! injectManualCommand is required for side commands to be injected correctly to a print like M105 queries. Plus it is not handled as print job.

    The host function 
     void LoadGCodeOrSTL(string file);
    would load a new gcode named in file to editor and switch to preview tab.

    But it gets even easier. Host function
    IGCodeEditor GCodeEditor { get; }

    gives you direct access to the editor content. That way you can also modify the code without reloading. See editor interface:
    public interface IGCodeEditor
        {
            event EventHandler ShowModeChanged;
            event EventHandler ShowMinLayerChanged;
            event EventHandler ShowMaxLayerChanged;
            event EventHandler MaxLayerChanged;

            void AppendLine(string l);
            void Clear();
            void setFocus();
            void setContent(string text);
            List<GCodeShort> getContentArray();
            string getContent();
            /// <summary>
            /// Visualization mode for gcode.
            /// 0 = Show all layer, 1 = show one layer, 2 = show layer range
            /// </summary>
            int ShowMode { get; set; }
            int ShowMinLayer {get; set;}
            int ShowMaxLayer { get; set; }
            int MaxLayer { get; }
            string PreferredSaveName { get; set; }
        }

    For reload all you need is
    editor.setContent(System.IO.File.ReadAllText(file));

    but with getContent and setContent you can also postprocess the result internally.
  • Thanks! I'll try that
Sign In or Register to comment.