POV-Ray : Newsgroups : povray.general : printing object's identifier : Re: printing object's identifier Server Time
18 May 2024 18:16:00 EDT (-0400)
  Re: printing object's identifier  
From: Bald Eagle
Date: 18 Mar 2016 23:15:01
Message: <web.56ecc3c1374275025e7df57c0@news.povray.org>
jr <cre### [at] gmailcom> wrote:

> the .pov illustrates building object identifiers dynamically via cli.
> the file is commented and works with version 3.7.0.  it does lack visual
> pizzazz but I'm no artist anyway.

Nice!   I like your use of the #error stream interrupt

> also, the newlines in the error messages don't work on my machine.

Yeah - they don't work on mine either. So -
I prefaced the #error directive with #warning messages, and _then_ triggered the
error.  Seems to sorta do what I think you were after.

I was a little confused, since I run POV-Ray on a Winbloze 7 machine and don't
often use CLI.
Don't judge me.   :O
I also rearranged the text a bit to make it somewhat clearer what's going on in
case it gets run without any idea what it's supposed to do.
"Hey, what's this .pov file I have in this directory... ?"

You also forgot to  #declare Whip = "Bald Eagle"   :P


############################################################################

/* parsestr.pov
 * this simple scene demonstrates the use of the 'Parse_String' macro
 * to build Object Identifiers dynamically, at runtime.
 *
 * Parse_String(String): This macro takes a string, writes it to a file, and
then includes that file.
 * This has the effect of parsing that string: "Parse_String("MyColor")" will be
seen by POV-Ray as "MyColor".
 * Parameters:
 * String = The string to be parsed.
 *
 *   command-line:
 *   povray Declare=OBJ=N ...    <<< Necessary for this scene to work!
 *          ^^^^^^^^^^^^^
 *
 * where N is one of the following:
 *  1 - box, 2 - cylinder, 3 - ovus, 4 - sphere, 5 - torus.
 *
 * date: 19.3.2016.
 * author: jr <cre### [at] gmailcom>.
 * license: Creative Commons CC0.
 * thanks to 'Bald Eagle' who provided the inspiration (motivation!).
 */

#version 3.7;

global_settings { assumed_gamma 1.0 }

#include "colors.inc"

// Parse_String.
#include "strings.inc"

light_source { <10,10,-10> White }

camera {
  location <1.5,1.5,-2.5>
  right x*image_width/image_height
  look_at <0,0,0>
}

// objects to select.
#declare the_box = box {<-0.5, -0.5, -0.5>, <0.5, 0.5, 0.5> texture {pigment
{Blue}}};
#declare the_cylinder = cylinder {<0,-0.5, 0>, <0, 0.5, 0>, .65 texture {pigment
{Blue}}};
#declare the_ovus = ovus {.65, .35 texture {pigment {Blue}}};
#declare the_sphere = sphere {<0,0,0>, 1 texture {pigment {Blue}}};
#declare the_torus = torus {1, .35 texture {pigment {Blue}}};

#declare the_help = "1 (box), (2) cylinder, (3) ovus, (4) sphere, or (5) torus";

#declare the_objs = array[5];
#declare the_objs[0] = "box";
#declare the_objs[1] = "cylinder";
#declare the_objs[2] = "ovus";
#declare the_objs[3] = "sphere";
#declare the_objs[4] = "torus";

#declare the_prefix = "the_";

// verify OBJ has been declared and is in range.
#ifndef (OBJ)
 #warning
"**********************************************************************************************************************
******\n"
 #warning concat("*** Missing argument: OBJ
                                                          ***\n")
 #warning concat("*** Need Command-Line statement \"Declare=OBJ=X\", where X = :
", the_help, ".  ***\n")
 #warning "***
                                                   ***\n"
 #warning
"**********************************************************************************************************************
******\n"

 #error concat(" *** Need Command-Line \"Declare=OBJ=X\", where X = : ",
the_help, ".\n")
 //   Try using _____Declare=OBJ=1_____ in the command-line box to the right of
the render resolution drop-down menu

#elseif (1 > OBJ | 5 < OBJ)
 #warning
"**********************************************************************************************************************
******\n"
 #warning concat("*** Bad argument# for: OBJ                       Please select
a different number                                        ***\n")
 #warning concat("*** Need Command-Line statement \"Declare=OBJ=X\", where X = :
", the_help, ".  ***\n")
 #warning "***
                                                   ***\n"
 #warning concat("*** Select (1-5):  ", the_help, ".  You used: _",
str(OBJ,0,0),"_.                            ***\n")
 #warning
"**********************************************************************************************************************
******\n"
 #error concat(" *** Bad argument # for OBJ \n  Select (1-5):  ", the_help, ".
You used: _", str(OBJ,0,0),"_.\n")

#end

// confirm selection.
#debug concat ("\n \n You chose the '", the_objs[OBJ-1], "', \n Now rendering
object '", the_prefix, the_objs[OBJ-1] ,"'.\n")

// use macro.
object { Parse_String (concat (the_prefix, the_objs[OBJ-1]) ) }


Post a reply to this message

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