| 
  | 
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 
 | 
  | 
 | 
  | 
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 
 | 
  |