creating a workspace thumbnail in a script

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

creating a workspace thumbnail in a script // Scriptorium

1  |  

Post by stan // Aug 16, 2007, 8:54am

stan
Total Posts: 1240
pic
I want to create a thumbnail of the screen or workspace on the fly while running a script to save an object to the library

are any of this on the right track? just guessing at this point :confused:
any help would be much appreciated

thumb = System.CreateDO('FileIO Package/RdChunk Unknown')
newthumbnail = thumb.DataLen()

screengrab = System.CreateDO('FileIO Package/RdChunk System')
screengrab.SystemSnapshot(newthumbnail)

pic = System.CreateDO('FileIO Package/RdChunk Thumbnail')
pic

Post by Norm // Sep 11, 2007, 6:58am

Norm
Total Posts: 862
pic
At risk of you already knowing ..... In Objects-Tutorial Objects library you find Remove Thumbnail and Replace Thumbnail script objects, where is used:


objBitmap = System.CreateDO('Common Data Package/Bitmap Data');


Some other interesting examples in that library too :)

Post by stan // Sep 11, 2007, 7:12am

stan
Total Posts: 1240
pic
thanks Norm..not sure will that make a screengrab of workspace?..thats the call I need to make the light setup file thumbnail

I'm aware of those scripts, was trying to get the save and add scripts to run in a collector type senario saving multiple objects in one operation no luck yet.

Post by 3dvisuals dude // Sep 11, 2007, 11:31am

3dvisuals dude
Total Posts: 1703
pic
thanks Norm..not sure will that make a screengrab of workspace?..thats the call I need to make the light setup file thumbnail

I'm aware of those scripts, was trying to get the save and add scripts to run in a collector type senario saving multiple objects in one operation no luck yet.

Hopefully Norm will have the exact answer for you on this but perhaps the following may help in some way.

In the SaveRsObj script there is the following code which creates a thumbnail of objects (which includes them in a snaphot thumbnail of the Workspace scene) and maybe this code can be slightly modified for your use?


// Create Thumbnail chunk and add it
objBitmap = System.CreateDO('Common Data Package/Bitmap Data');
try
{
objBitmap.LoadFromFile(Thumbnail);
chThumbnail = System.CreateDO('FileIO Package/RdChunk Thumbnail');
chThumbnail.PutBitmap(objBitmap, BFILEFMT_PNG)
hFile.AddChunk(chThumbnail, false);
}
catch (e)
{
}
// Create Thumbnail chunk and add it
chRsObj = System.CreateDO('FileIO Package/RdChunk RsObj');
chRsObj.AddNode(Node.FirstSelected(), '', '');
hFile.AddChunk(chRsObj, false);
// Close the file
hFile.Close(false)
}


I'll keep hunting for you but if the code above can me altered to point to your light setups as opposed to a single RsObj object in the scene than it should work fine I think.

- Mark / 3dvisuals dude

Post by Vladimir // Sep 11, 2007, 9:39pm

Vladimir
Total Posts: 11
Unfortunatelly, the thumbnail generating methods are not exposed in scripts.


Thus there are two solutions:

a) if you want save actual 3D view, then write your own grabbing script function by using the D3D Texture Render Targer (library "scenes - base", scene D3D TRT)

b) if you want the whole screen grab, save e.g. layout object, then open it and get its thumbnail. After this delete the temporary created layout object. To save the layout you can use: WindowsManager.SaveObjectAsLayout(<filename>, <object str id>)


Other solution is to write grabbing function set out of tS as an active x object. However its more complicated mainly if you want distribute the created dll.

Post by 3dvisuals dude // Sep 11, 2007, 9:50pm

3dvisuals dude
Total Posts: 1703
pic
Unfortunatelly, the thumbnail generating methods are not exposed in scripts.

Thus there are two solutions:
a) if you want save actual 3D view, then write your own grabbing script function by using the D3D Texture Render Targer (library "scenes - base", scene D3D TRT)
b) if you want the whole screen grab, save e.g. layout object, then open it and get its thumbnail. After this delete the temporary created layout object. To save the layout you can use: WindowsManager.SaveObjectAsLayout(<filename>, <object str id>)

Other solution is to write grabbing function set out of tS as an active x object. However its more complicated mainly if you want distribute the created dll.

I wonder if we could use dll calls to the windows API and do bitblit type active window captures. The fact that we can access the shell from scripts leads me to think there may be a way to make direct Win API DLL calls as well from script.

If there's an existing approach you could point us toward to harness the Win API via DLL Calls (like one can easily do in BASIC programs) via scripting this should be do-able that way, and I have quite a bit of related VB Code which may be utilized in that fashion for screen captures.

Thanks for the help Vladimir,:)

- Mark / 3dvisuals dude

EDIT: Here's a BASIC language example of setting up screen capturing via the Win API:


'get upper left x,y and lower right x,y coords into Rect struct
CallDLL #user32, "GetWindowRect",_
hWin As Long,_ 'window handle
Rect As struct,_ 'struct name
result As Boolean

'fill Point struct with upper left window coords
Point.x.struct=Rect.ulx.struct
Point.y.struct=Rect.uly.struct

'change screen coords to window client coords
'the function takes in screen coords in Point struct
'and replaces them with coords relative to
'upper left corner of client (graphics) area
CallDLL #user32, "ScreenToClient",_
hWin As Long,_ 'window handle
Point As struct,_ 'struct name
r As Long

'retrieve coords of upper left corner of
'window relative to graphics area
startX = Point.x.struct-1
startY = Point.y.struct-1

'get width and height of window
'from coords in Rect struct
'width is rightX - leftX
'height it lowerY - upperY
widthX = Rect.lrx.struct-Rect.ulx.struct
heightY = Rect.lry.struct-Rect.uly.struct

'now we have the coords to use for capturing
'the window


Once we have that, here's the rest of the screen capture routine in Win API DLL Calls and BASIC language code:


UpperLeftX = 20:UpperLeftY=20
WindowWidth=300:WindowHeight=150
graphicbox #1.g, 0,0,0,0
open "Window ScreenCap" for window as #1
#1 "trapclose [quit]"
hWin=hwnd(#1)
struct Point,x As Long, y As Long
struct Rect,ulx as long, uly as long, lrx as long, lry as long
CallDLL #user32, "GetWindowRect",hWin As Long,Rect As struct,result As Boolean
Point.x.struct=Rect.ulx.struct
Point.y.struct=Rect.uly.struct
CallDLL #user32, "ScreenToClient",hWin As Long,Point As struct,r As Long
startX = Point.x.struct-1
startY = Point.y.struct-1
widthX = Rect.lrx.struct-Rect.ulx.struct
heightY = Rect.lry.struct-Rect.uly.struct
#1.g "getbmp cap ";startX;" ";startY;" ";widthX;" ";heightY
bmpsave "cap", "mycap.bmp"
run "mspaint mycap.bmp"
[quit] close #1: end

Post by stan // Sep 12, 2007, 6:29am

stan
Total Posts: 1240
pic
Thanks Vladimir..thought it might possible already with FileIO Package script but now I know..:)

maybe a generic light setup thumbnail will have to be used for now, then a person will have to generate thumbs as they add to the library themselves if they want to have workspace grabs as thumbs.

at least I finally got the saving of multiple objects in one operation figured out..:D
you will have to load light setups from the load script though [which will be incorporated into the light setups script] , not directly from the library or you only load the first object;)
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn