Print display feature

Having problems with or questions about SheetCam? Post them here.
User avatar
Les Newell
Site Admin
Posts: 3668
Joined: Thu May 11, 2006 8:12 pm

Re: Print display feature

Post by Les Newell »

Give this a try. It switches to the light colour scheme to take the screen shot.

Code: Select all

   --save screen shot as 'screen.png' in g-code directory
   local colours = sc.Globals:Get().colours
   local cfg = wx.wxFileConfig("", "", "", "", 0)
   colours:Save(cfg) --Back up current colours
   colours:LoadProfile(2) --white profile
   sc.Parts:Get():SetDirty(sc.DIRTY_COLOURS) --trigger screen redraw
   wx.wxYield()
   local path = filePath .. "screen.png"
   local bmp = sc.Parts:Get().glDisplay:GetBitmap()
   bmp:SaveFile(path, wx.wxBITMAP_TYPE_PNG)
   colours:Load(cfg) --restore current colours
   sc.Parts:Get():SetDirty(sc.DIRTY_COLOURS)
David_Lelen01
Posts: 452
Joined: Wed Sep 12, 2018 8:18 pm
Location: South Carolina, USA
Contact:

Re: Print display feature

Post by David_Lelen01 »

Hey Les, I hate to bother you more about this but I really need a little more help here if you don't mind.

Are file path wild cards not accepted here? I decided I want to just save the screenshot in the AppData folder and I wanted to use

Code: Select all

local path = "%APPDATA%\\SheetCam TNG Development\\screen.png"
it works fine using

Code: Select all

local path = C:\\Users\\user\\AppData\\Roaming\\SheetCam TNG Development\\screen.png
but then that will only work on my machine and I would have to edit the post for our other programmers here with their user directory.

I also want to auto zoom the display to either the job area or the material area. how do the actions work with the action manager in the post? is it like sc.actZOOM_MATERIAL() or something of the sort? I have been searching through post processors and plugins and all but I haven't found an example anywhere I can go by yet. I really wanted to figure this one out on my own, but I've wasted a good bit of time here already. Sometimes its better to just ask for help.
User avatar
Les Newell
Site Admin
Posts: 3668
Joined: Thu May 11, 2006 8:12 pm

Re: Print display feature

Post by Les Newell »

File paths are absolute. What you want is this:

Code: Select all

local path = sc.Globals.Get().settingsDir . "\\screen.png"

You can see all of the actions in sc.i
The ones you are likely to need are:
actZOOM_PART,actZOOM_JOB,actZOOM_MATERIAL,actZOOM_MACHINE

Code: Select all

local mgr = sc.wxActionManager.Get() --you may already have this
mgr:Execute(sc.actZOOM_JOB)
This does the same as pressing the 'zoom job' button.
David_Lelen01
Posts: 452
Joined: Wed Sep 12, 2018 8:18 pm
Location: South Carolina, USA
Contact:

Re: Print display feature

Post by David_Lelen01 »

Les... I'm almost embarrassed to keep bothering you. So that worked except its saving it under each profile's setting directory instead of the default profile directory. So its saving in "\SheetCam TNG Development\Plasma\screen.png" instead of "\SheetCam TNG Development\screen.png". Let me guess... you cant somehow tell it to go up a directory because its special, huh? I tried everything I could find online about going up a directory in Lua, but nothing worked or I just did it wrong.

The zoom works perfect though. Thanks.

And then I bet the report HTML doesnt support file paths like "%APPDATA%\SheetCam TNG Development\screen.png" or the "sc.Globals.Get().settingsDir .. "\\screen.png" does it. Man this is becoming a nightmare.
User avatar
Les Newell
Site Admin
Posts: 3668
Joined: Thu May 11, 2006 8:12 pm

Re: Print display feature

Post by Les Newell »

Maybe use the Windows temporary directory instead. I'm pretty sure most versions of Windows use \windows\temp
I'd recommend not specifying the drive. By default the current directory in SheetCam is it's install directory. On most Windows installations program files is on the same drive as Windows. This isn't bulletproof but it should work in most cases.
David_Lelen01
Posts: 452
Joined: Wed Sep 12, 2018 8:18 pm
Location: South Carolina, USA
Contact:

Re: Print display feature

Post by David_Lelen01 »

Maybe use the Windows temporary directory instead.
Well that works... I was avoiding that because I was afraid User Account Control and permissions may restrict access to the windows folder, but it worked on my machine. Awesome, thanks! I should have just tried instead of assuming it wouldn't work.

Now... what all can I do with the "colours" commands? Can I set all of the contours to be black instead of some grey so they will show up when printed? I'm looking at the "globals.i" file for some ideas, but that looks more like C programming which I am unfortunately not very good at all with yet.

I really appreciate your help and patience with me on this.
User avatar
Les Newell
Site Admin
Posts: 3668
Joined: Thu May 11, 2006 8:12 pm

Re: Print display feature

Post by Les Newell »

It uses the 'white' colour scheme which I am afraid is hard coded. You cannot change it.
David_Lelen01
Posts: 452
Joined: Wed Sep 12, 2018 8:18 pm
Location: South Carolina, USA
Contact:

Re: Print display feature

Post by David_Lelen01 »

Darn. Could i create, save, and load a custom scheme?

Is there no way to set the color of individual contours from the post? It looks like it should be possible when I look at globals.i in the "class Colours" section in the SDK folder.

Code: Select all

class Colour : public wxColour
{
	void SetGl(void);
	void SetGl(unsigned char alpha);
	void SetGlInv(void);
	Colour & operator = (const wxColour & src);
	Colour & operator = (const Colour & src);
};

class Colours
{
    void Invert(void);
    void LoadProfile(int profile);
	Colour& operator[](const wxString& name);
	Colour& Index(const wxString& name);
	void Save(wxConfigBase& cfg);
	void Load(wxConfigBase& cfg);
    void FillControl(wxControlWithItems * ctrl);
	Colours& operator = (const Colours & src);

    enum {path, feedOverride, rapid,  inside, outside, open, lineEnd, segEnd, backGnd, machine, table, work, workOutline, marker, startPoint, fixedStart, hilite, duplicate, inactive, centre, tabs, grid, roundShank, roundFlute, turnShank, turnTip, cutPart,};
};
User avatar
Les Newell
Site Admin
Posts: 3668
Joined: Thu May 11, 2006 8:12 pm

Re: Print display feature

Post by Les Newell »

Actually, looking at the code you can change the colours. I thought glDisplay:GetBitmap() automatically changes the colors but it doesn't.
In your code after:

Code: Select all

colours:LoadProfile(2) --white profile
use this:

Code: Select all

colours:op_index(sc.Colours.path) = wx.wxColour(0,0,0)
colours:op_index(sc.Colours.inside) = wx.wxColour(0,0,0)
colours:op_index(sc.Colours.outside) = wx.wxColour(0,0,0)
colours:op_index(sc.Colours.open) = wx.wxColour(0,0,0)
The numbers are red,green,blue values in the range 0-255.
David_Lelen01
Posts: 452
Joined: Wed Sep 12, 2018 8:18 pm
Location: South Carolina, USA
Contact:

Re: Print display feature

Post by David_Lelen01 »

Awesome! I figured it could be done. Except there must be a typo or syntax error in there...

Lua: Syntax error during pre-compilation
...6)\SheetCam TNG Development\posts\001-Burny Phantom2 Machine Kerf.scpost:107: unexpected symbol near '='
User avatar
Les Newell
Site Admin
Posts: 3668
Joined: Thu May 11, 2006 8:12 pm

Re: Print display feature

Post by Les Newell »

Oops, the Lua version only allows indexing by name. I must have forgotten to add indexing by number. Try this instead:

Code: Select all

colours:Index("Cut path"):Set(0,0,0)
Take a look at the [Colours] section of the ini file for the colour names. Note that space is escaped in the ini file, so ' ' becomes '\ '.
David_Lelen01
Posts: 452
Joined: Wed Sep 12, 2018 8:18 pm
Location: South Carolina, USA
Contact:

Re: Print display feature

Post by David_Lelen01 »

AWESOME!!! Thanks Les!

The only color that doesn't seem to be changing for some reason is the rapid paths. They are stuck on blue no matter what I change or what mode I change to. Weird. Here's the code in case you see something in it.

Code: Select all

	local mgr = sc.wxActionManager.Get()
	mgr:Execute(sc.actZOOM_JOB)
	mgr:Execute(sc.actMODE_START)
	local colours = sc.Globals:Get().colours
	local cfg = wx.wxFileConfig("", "", "", "", 0)
	colours:Save(cfg) --Back up current colours
	colours:LoadProfile(2) --white profile
	colours:Index("Cut path"):Set(0,0,0)
	colours:Index("Feed override"):Set(0,0,0)
	colours:Index("Rapid path"):Set(255,255,255)
	colours:Index("Inside shape"):Set(0,0,0)
	colours:Index("Outside shape"):Set(0,0,0)
	colours:Index("Open paths"):Set(0,0,0)
	colours:Index("Line end"):Set(255,255,255)
	colours:Index("Segment end"):Set(255,255,255)
	colours:Index("Background"):Set(255,255,255)
	colours:Index("Machine working envelope"):Set(255,255,255)
	colours:Index("Machine table"):Set(255,255,255)
	colours:Index("Work"):Set(255,255,255)
	colours:Index("Material extents"):Set(0,0,0)
	colours:Index("Marker"):Set(255,255,255)
	colours:Index("Highlight"):Set(0,0,0)
	colours:Index("Duplicated part"):Set(0,0,0)
	colours:Index("Inactive part"):Set(0,0,0)
	colours:Index("Centre marker colour"):Set(255,255,255)
	colours:Index("Tabs"):Set(255,255,255)
	colours:Index("Grid"):Set(255,255,255)
	colours:Index("Start point"):Set(255,255,255)
	colours:Index("Locked start point"):Set(255,255,255)
	colours:Index("Round tool shank"):Set(255,255,255)
	colours:Index("Round tool flutes"):Set(255,255,255)
	colours:Index("Turning tool shank"):Set(255,255,255)
	colours:Index("Turning tool tip"):Set(255,255,255)
	colours:Index("Cut out part"):Set(0,0,0)
	sc.Parts:Get():SetDirty(sc.DIRTY_COLOURS) --trigger screen redraw
	wx.wxYield()
	local path = "C:\\Windows\\Temp\\SCamScreenReport.png"
	local bmp = sc.Parts:Get().glDisplay:GetBitmap()
	bmp:SaveFile(path, wx.wxBITMAP_TYPE_PNG)
	colours:Load(cfg) --restore current colours
	sc.Parts:Get():SetDirty(sc.DIRTY_COLOURS)

And the other weird thing is if I use the lines from several posts ago to pop up the job report at the end of the post, the rapid distance, cut time, pierces, etc. all shows up as 0. If I run it by clicking the button after the post finished it works fine.

Code: Select all

function OnFileClosed()
	local mgr = sc.wxActionManager.Get()
	mgr:Execute(sc.actPOST_ESTIMATE)
	end
David_Lelen01
Posts: 452
Joined: Wed Sep 12, 2018 8:18 pm
Location: South Carolina, USA
Contact:

Re: Print display feature

Post by David_Lelen01 »

Well, it looks like its the rapid paths, the cut paths, and the feed override colors right now. If i go to application options and look at the colors there, it shows the colors that i set in the post so i know that part is working right at least. Only when i click with the mouse on another tab like nesting or start points or contours, then it updates the colors on screen correctly. I tried using "mgr:Execute(sc.actMODE_START)" and "mgr:Execute(sc.actMODE_NEST)" to have the post change the modes too, but that doesnt trigger the colors either. It is only when i click on the mode buttons with the mouse that it fixes.

I have "colours:Load(cfg) --restore current colours" commented out for debugging right now.
User avatar
Les Newell
Site Admin
Posts: 3668
Joined: Thu May 11, 2006 8:12 pm

Re: Print display feature

Post by Les Newell »

I have to admit I don't know why this is happening. One problem is that SetDirty is asynchronous. It only takes effect when the SheetCam is idle.
David_Lelen01
Posts: 452
Joined: Wed Sep 12, 2018 8:18 pm
Location: South Carolina, USA
Contact:

Re: Print display feature

Post by David_Lelen01 »

I just saw "actREGEN" in the actions list and thought that might do the trick, but alas it does not help either. Is that likely the issue, I am asking sheetcam to switch colors while in the middle of something else?

I find it very odd that some colors are changing exactly as intended but others are remaining the same. Inside Shape, Outside Shape, Open Paths, Background, Machine Working Envelope, Machine Table, Work, Material, and Highlight all appear, as best I can tell, to be changing as intended, but Cut Path, Feed Override, and Rapid Path appear to not change. There may be others, these are just the ones I can confirm right now.
Post Reply