//******************************************************************** // Project File: PovRayStarter.dpr v1.02 2021-12-12 // A Delphi console example program for starting 'PovRay rendering'. // PovRayStarter.exe tested with: Delphi-6 release with 121.856 Bytes // Delphi-Sydney-CE with 1.162.752 Bytes // https://www.delphipraxis.net/35458-wie-ruft-man-povray-aus-einem-programm-heraus-auf.html //******************************************************************** {$D+,L+,Y+,R+,S+,Q+,O-,C+} // debug {$D-,L-,Y-,R-,S-,Q-,O-,C-} // release {$APPTYPE CONSOLE} program PovRayStarter; uses SysUtils, ShellApi, Windows, Registry; const NL = #13#10; // NewLine = carriage return + linefeed PovRayStartCommand36 = 'C:/Program Files/POV_Ray/POV-Ray 3.6/bin/pvengine.exe'; PovRayStartCommand37 = 'C:/Program Files/POV_Ray/POV-Ray 3.7/bin/pvengine.exe'; PovRayStartCommand38 = 'C:/Program Files/POV_Ray/POV-Ray 3.8/bin/pvengine.exe'; // set your individual start command here: PovRayStartCommand37b = 'E:\Programming_Tools\POV_Ray\POV-Ray_3.7\bin\pvengine32-sse2.exe'; PovRayStartCommand37c = 'E:\Programming_Tools\POV_Ray\POV-Ray_3.7\bin\pvengine64.exe'; PovRayStartCommand38b = 'E:\Programming_Tools\POV_Ray\POV-Ray_3.8\bin\pvengine32-sse2.exe'; PovRayStartCommand38c = 'E:\Programming_Tools\POV_Ray\POV-Ray_3.8\bin\pvengine64.exe'; var povStartCommand, povStartParams: string; //********************************************************* // Gets a string value from the registry from the given root // and sub 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 GetPovRayRegistryCommand (const rootKey: HKEY; subKey: string); var hs: string; begin hs := GetRegistryString (rootKey, subKey, ''); if length(hs) = 0 then exit; povStartCommand := hs; writeln (#13#10,hs); end; //********************************************************* // get start command of PovRay Renderer //--------------------------------------------------------- procedure GetPovRayStartCommand; var si: integer; begin povStartCommand := paramStr(1); if povStartCommand = '' then begin GetPovRayRegistryCommand (HKEY_CLASSES_ROOT , '\Applications\pvengine.exe\shell\open\Command'); GetPovRayRegistryCommand (HKEY_CURRENT_USER , '\SOFTWARE\Classes\pov_auto_file\shell\open\command'); GetPovRayRegistryCommand (HKEY_CLASSES_ROOT , '\POV-Ray.Scene\shell\Open\command'); if povStartCommand <> '' then begin // cut text after 'pvengine.exe"' si := pos('pvengine.exe"', povStartCommand); if si > 0 then delete (povStartCommand, si+13, 999); end; if povStartCommand = '' then povStartCommand := PovRayStartCommand37b; if povStartCommand = '' then povStartCommand := PovRayStartCommand37; if povStartCommand = '' then povStartCommand := PovRayStartCommand36; end; writeln (NL,'Start command of PovRay program: '#13#10 ,' ', povStartCommand); end; //********************************************************* // execute Windows application // input: name: string application name // param: string application start parameters // result: boolean =true application started // errorCode e.g. 2 = ERROR_FILE_NOT_FOUND // https://docwiki.embarcadero.com/RADStudio/Sydney/en/Input-Output_Errors // examples: // started := RunApplication ('pvengine.exe', '/RENDER example.pov'); // view text file // started := RunApplication ('ReadMe.txt', ''); // view text file with notePad // RunApplication ('notepad', 'info.txt'); // start windows explorer // RunApplication ('Explorer', 'C:\'); //--------------------------------------------------------- function RunApplication (const name, param: string): boolean; var errorCode: cardinal; begin writeln (NL,'try starting PovRay with command...', NL, 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: ', NL ,' can not start application ''', name+param, '''' + NL ,' error code = ' + IntToStr(errorCode)); // german info from Delphi-Praxis: // https://www.delphipraxis.net/126563-shellexecute-error.html end; //********************************************************* // start rendering of povray scene //--------------------------------------------------------- procedure StartPovRayRendering (const povfilename: string); var result: boolean; begin povStartParams := ' /EDIT ' + povfilename + ' /RENDER ' + povfilename + ' +FN'; // PNG output see: // http://www.povray.org/documentation/view/3.6.1/219/ // try to start PovRay 3.7b result := RunApplication (PovRayStartCommand37b, povStartParams); if not result // try to start PovRay 3.6 then RunApplication (povStartCommand, 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, NL , 'camera {location -3*z right x*image_width/image_height}', NL , 'light_source {<9,9,-9> 1.5 parallel}', NL , 'sphere {0 1 pigment {rgb<1,1,0.5>}}', NL); Close (pov); end; //********************************************************* const povFilename = 'Test1.pov'; begin writeln (NL, '=== PovRayStarter v1.02 ===', NL); SavePovRayTestFile (povFilename); GetPovRayStartCommand; StartPovRayRendering (povFilename); sleep(7000); end.