POV-Ray : Newsgroups : povray.programming : Who to start PovRay from another program and render a scenery... Server Time
3 Nov 2024 07:22:34 EST (-0500)
  Who to start PovRay from another program and render a scenery... (Message 1 to 6 of 6)  
From: m steiger
Subject: Who to start PovRay from another program and render a scenery...
Date: 1 Jan 2011 06:10:00
Message: <web.4d1f0a8ead017ee9b1e857390@news.povray.org>
Hi

I am searching for detailed descriptions and information about how to start
PovRay from a self written 3d-program.

I use Delphi for coding my 3d-application and want to do following steps:
- set appropriate Povray preferences (e.g. run only one instance)
- export a 3d-scenery as PovRay file (write a SDL-file)
- get PovRay execution path (registry entry)
- start PovRay (v3.6.2 or beta) with SDL-file
- immediately continue own application after PovRay was started

useful hints and links to all these points are welcome...

~~~ martin ~~~


Post a reply to this message

From: martin steiger
Subject: Re: How to start PovRay from another program and render a scenery...
Date: 1 Jan 2011 06:22:29
Message: <4d1f0e75$1@news.povray.org>
Of course subject should be "How to start PovRay...


Post a reply to this message

From: clipka
Subject: Re: Who to start PovRay from another program and render a scenery...
Date: 1 Jan 2011 06:22:48
Message: <4d1f0e88$1@news.povray.org>
Am 01.01.2011 12:05, schrieb m.steiger:
> Hi
>
> I am searching for detailed descriptions and information about how to start
> PovRay from a self written 3d-program.
>
> I use Delphi for coding my 3d-application and want to do following steps:
> - set appropriate Povray preferences (e.g. run only one instance)

I guess you'll need to tweak the registry there.

> - export a 3d-scenery as PovRay file (write a SDL-file)

This effectively boils down to the question how to write ASCII files 
from within Delphi.

> - get PovRay execution path (registry entry)

I guess the source code is the best documentation on this topic.

> - start PovRay (v3.6.2 or beta) with SDL-file
> - immediately continue own application after PovRay was started

These boil down to the question of how to start background processes 
from within Delphi.


Post a reply to this message

From: trp
Subject: Re: Who to start PovRay from another program and render a scenery...
Date: 2 Jan 2011 10:35:01
Message: <web.4d209ac28918d457bba08f230@news.povray.org>
At the risk of being redundant, here is a request from Ian:

http://news.povray.org/op.vonur8vk0819q0%40gdsentropy.nc.rr.com

and what I posted a few minutes ago:

"
This does seem to come up every so often. There should be a FAQ. (Maybe there
is. I'll look after I post this.) Anyway, here are a couple of earlier
references.

http://news.povray.org/web.4c0165e33f4c95c6bba08f230%40news.povray.org

http://news.povray.org/web.4c5df3ad7c1e70dfbba08f230%40news.povray.org
"

I did look. (Based on the time between my posts you can tell it wasn't a lot.)
But, I didn't find a FAQ. No, I don't feel confident enough to write one.

I wrote my application in C++. For me the easiest thing is to have POV already
running. (I may at some point prompt the user to start POV if it is not
running.) I have the default locations I obtained from the registry and the GUI
extensions DLL I created for communications.

I write my POV code and an ini file to work files. I pass a DDE message to POV
thru the DLL. The message includes a handle to my window that will display the
image. POV writes a BMP file and in the DLL posts a Windows message to my
display window when it is done. I read the BMP and display it in my window.

I hope this helps. Have fun.
Tim


"m.steiger" <nomail@nomail> wrote:
> Hi
>
> I am searching for detailed descriptions and information about how to start
> PovRay from a self written 3d-program.
>
> I use Delphi for coding my 3d-application and want to do following steps:
> - set appropriate Povray preferences (e.g. run only one instance)
> - export a 3d-scenery as PovRay file (write a SDL-file)
> - get PovRay execution path (registry entry)
> - start PovRay (v3.6.2 or beta) with SDL-file
> - immediately continue own application after PovRay was started
>
> useful hints and links to all these points are welcome...
>
> ~~~ martin ~~~


Post a reply to this message

From: m steiger
Subject: Re: How to start PovRay from another program and render a scenery...
Date: 3 Jan 2011 07:51:18
Message: <4d21c646$1@news.povray.org>
How to start PovRay from a 3d-application coded with Pascal (Delphi)

1. set appropriate PovRay preferences
-------------------------------------
- Menu: Editor / Auto-Reload / * Always
- Menu: Options / * Keep single instance
- add '+FN' to command line option field to save PNG pictures

2. export a 3d-scenery as PovRay file
-------------------------------------
- build filename: povfilename = <name> + '.pov'
- save scenery as ASCII file named 'povfilename'

3. get PovRay execution path from registry
------------------------------------------
- get execution command from registry
   povStartCommand := GetRegistryString (HKEY_CLASSES_ROOT
        , '\Applications\pvengine.exe\shell\open\Command', '');
- from povStartCommand cut away the text after 'pvengine.exe'

4. start PovRay with saved PovRay file
--------------------------------------
- set execution parameter to:
   param := ' /EDIT ' + povfilename + ' /RENDER ' + povfilename;
- start povray without waiting for ending
   errorCode := ShellExecute (Application.Handle, 'open'
      ,PChar(povStartCommand), PChar(param), nil, SW_SHOWNORMAL);

5. handling PovRay after execution
----------------------------------
- if you want to restart rendering press 'Stop' at PovRay
   and continue with point 2
- to change resolution press 'Stop' change it and press 'Run'
- if rendering ends you can restart rendering
   during PovRay is still running


Post a reply to this message

From: m steiger
Subject: Re: How to start PovRay from another program and render a scenery...
Date: 3 Jan 2011 12:20:06
Message: <4d220546$1@news.povray.org>
I was extracting the needed code to a console application for testing.
Hope this implemention is useful for all Delphi coders and for coding in 
other languages too.

With Delphi create a new console application, save it as 'PovRayStarter' 
and replace the whole code with this one...

//********************************************************************
// PovRayStarter v1.0
// a console program for testing start of PovRay rendering with Delphi
//********************************************************************
{$D+,L+,Y+,R+,S+,Q+,O-,C+}

program PovRayStarter;

{$APPTYPE CONSOLE}

uses  SysUtils, ShellApi, Windows, Registry;

const CRLF = #13#10;      // carriage return + linefeed
       PovRayStartCommand36
         = 'C:/Programme/POV_Ray/POV-Ray 3.6/bin/pvengine.exe ';
       PovRayStartCommand37
         = 'C:/Programme/POV_Ray/POV-Ray 3.7/bin/pvengine-sse2.exe ';

var   povStartCommand, povStartParams: string;

//*********************************************************
// Gets a string value from the registry from the given key.
// Converts integer value to a string
// Returns '' if the sub key or value name are unknown.
//---------------------------------------------------------
function GetRegistryString (const rootKey: HKEY;
                             const subKey, name: string): string;
var
   reg: TRegistry;            // registry access object
   valueInfo: TRegDataInfo;   // info about registry value
begin
   Result := '';
   reg := TRegistry.Create;
   try
     reg.RootKey := rootKey;
     if reg.OpenKeyReadOnly (subKey)
     then if reg.GetDataInfo (name, valueInfo)
     then begin
       // check if registry value is string or integer
       case valueInfo.RegData of
         // string value: just return it
         rdString, rdExpandString:   Result := reg.ReadString (name);
         // integer value: convert to string
         rdInteger:   Result := IntToStr (reg.ReadInteger(name));
       end;
     end;
   finally
     reg.CloseKey;
     reg.Free;
   end;
end;
//*********************************************************
// get start command of PovRay Renderer
//---------------------------------------------------------
procedure GetPovRayStartCommand;
var si: integer;
begin
   povStartCommand := GetRegistryString (HKEY_CLASSES_ROOT
                   , '\Applications\pvengine.exe\shell\open\Command', '');
   if povStartCommand = ''
   then povStartCommand := PovRayStartCommand36
   else begin
     // cut text after 'pvengine.exe '
     si := pos('pvengine.exe ', povStartCommand);
     delete (povStartCommand, si+12, 999);
   end;
end;
//*********************************************************
// execute Windows application
// input:    name: string     application name
//           param: string    application start parameters
// result:   boolean          =true application started
//           errorCode        <= 32 --> error
//                            e.g.  2 = ERROR_FILE_NOT_FOUND
// examples:
//  started := RunApplication ('pvengine.exe', '/RENDER example.pov');
//  started := RunApplication ('ReadMe.txt', '');  // view text file
//  RunApplication ('notepad', 'info.txt');  // view text file with notePad
//  RunApplication ('Explorer', 'C:\');   // start windows explorer
//---------------------------------------------------------
function RunApplication (const name, param: string): boolean;
var
   errorCode: cardinal;
begin
   writeln (CRLF,'starting PovRay with command...', CRLF,'  ', name, param);

   errorCode := ShellExecute (0, 'open'
      ,PChar(name), PChar(param), nil, SW_SHOWNORMAL);
   result := (errorCode = 0) or (errorCode = 42);
   if result
   then writeln ('  successfully started ')
   else writeln ('RunApplication:  ', CRLF
     ,'  can not start application ''' + povStartCommand + '''' + CRLF
     ,'  error code = ' + IntToStr(errorCode));
end;
//*********************************************************
// start rendering of povray scene
//---------------------------------------------------------
procedure StartPovRayRendering (const povfilename: string);
var
   result: boolean;
begin
   povStartParams := ' /EDIT ' + povfilename + ' /RENDER ' + povfilename;

   // try to start PovRay 3.6
   result := RunApplication (povStartCommand, povStartParams);
   if not result
   // try to start PovRay 3.7
   then RunApplication (PovRayStartCommand37, povStartParams);
end;
//*********************************************************
// create povray test scene file
//---------------------------------------------------------
procedure SavePovRayTestFile (const povfilename: string);
var  pov: text;
begin
   Assign (pov, povfilename);
   ReWrite (pov);
   writeln (pov, '// File: ' + povfilename, CRLF
               ,'camera {location -3*z}', CRLF
               ,'light_source {<9,9,-9> 1 parallel}', CRLF
               ,'sphere {0 1 pigment {rgb<1,1,0.5>}}', CRLF);
   Close (pov);
end;
//*********************************************************
const
   povFilename = 'Test1.pov';
begin
   writeln (CRLF, '=== PovRayStarter v1.0 ===', CRLF);
   SavePovRayTestFile (povFilename);
   GetPovRayStartCommand;
   StartPovRayRendering (povFilename);
   sleep(7000);
end.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.