; =========================================================== ; ; START OF SOLRENDER.LSP ; ; =========================================================== (command ^C ^C) (print "loading solrender lisp...") ; ============================================== ; Dialog box that explains the lisp when loaded. ; ============================================== (defun c:solhelp () (alert "___________________________________ SOLAR SHADING ANALYSIS TOOL ___________________________________ This AutoLISP Renders hourly from one time to another time for a day you specify. The renderings are saved as tiff's in the folder of your drawing with the name as the hour that they represent. This lisp assumes that no lights exist when it is run. It creates and deletes a light called temp_dis when running, which may remain and cause errors if lisp is canceled while rendering. To fix just delete the light. __________________________________ COMMANDS: __________________________________ SOLRENDER To Run SETSOLRENDER Sets: - image size - output location - global position - hourly/half-hourly renderings SOLDEFAULTS Resets variables to default SOLHELP This dialog box __________________________________ CHRIS FURNEAUX 2002 __________________________________") ) (c:solhelp) ; Other commands: ; ; c:set_sol_imagesize : sets output image size ; set_sol_location : sets location of model ; c:set_sol_halfhours : sets if half hour rendering is to be included ; c:set_sol_dir : sets directory to render to ; c:sol_setmonthend (month) : sets the end day of the month in the variable monthendday ; c:sol_setrenderer : sets up rendering parameters ; c:sol_setptime : sets the string for the output file name ; c:sol_checkinputs : checks that location and image size are set ; error (message) : writes an error message and exits task ; c:sol_setinputs : sets inputs ; c:sol_solrender : runs render with conditions set when run ; c:sol_renderloop : runs rendering loop ; ========================================= ; Sets start (default) values for the lisp. ; edit this to change defaults. ; ========================================= (defun c:soldefaults () (setq fileformat "TIFF") ; file format of rendered image (setq xres 300) ; x resolution of image (setq yres 300) ; y resolution of image (setq aratio 1) ; aspect ratio of image (setq colormode "C24") ; colourmode of image (setq halfhours "N") ; weather to render on the half hour as well by default (setq sollat -41.28) ; default latitude (setq sollong 174.77) ; default longitude (setq soltime -12) ; default timezone (setq soldir "") ; directory to render to. (print "solrender defaults set...") ) (c:soldefaults) (arxload "acrender.arx" "unable to load acrender.arx : please open and close the light dialog and run this again") ; ============================= ; Functions to change settings. ; ============================= (defun c:setsolrender () (c:set_sol_imagesize) (set_sol_location) (c:set_sol_halfhours) (c:set_sol_dir) ) (defun c:set_sol_imagesize () ; Sets the image size (setq setsolimgsze "N") (initget 1 "Y N") (setq setsolimgsze (getkword "Set output image size? (Y/N)")) (if (= setsolimgsze "Y") (progn (while (< xres 0) (setq xres (getint "enter the x resolution of the image:")) ) (while (< yres 0) (setq yres (getint "enter the y resolution of the image:")) ) ) ) ) (defun c:set_sol_location () ; Sets the location of the rendering (setq setsollocation "N") (initget 1 "Y N") (setq setsollocation (getkword "Set latitude, longitude and timezone? (Y/N)")) (if (= setsollocation "Y") (progn (setq sollat 181) (while (> sollat 180) (setq sollat -181) (while (< sollat -180) (setq sollat (getreal "enter the latitude (-180 to 180):")) ) ) (setq sollong 181) (while (> sollong 180) (setq sollong -181) (while (< sollong -180) (setq sollong (getreal "enter the longitude (-180 to 180):")) ) ) (setq sollong 14) (while (> soltime 12) (setq soltime -14) (while (< soltime -12) (setq soltime (getreal "enter the timezone (-12 to 12):")) ) ) ) ) ) (defun c:set_sol_halfhours () ; Sets weather renderings are done on the hour or the halfhour (setq halfhours "Y") (initget 1 "Y N") (setq halfhours (getkword "Do you want renderings on half hours (Y/N)")) ) (defun c:set_sol_dir () ; Sets the location to save the image to (setq setsoldir "N") (initget 1 "Y N") (setq setsoldir (getkword "Do you want to set the directory to save images to? (Y/N)")) (if (= setsoldir "Y") (setq soldir (getstring "Enter location for images (e.g. drive:\full_path\): ")) ) ) ; ======================================== ; Functions used by the rendering routine. ; ======================================== ; =================== ; Set months end day. ; =================== (defun c:sol_setmonthend (monthvar) (graphscr) (if (= monthvar 1) (setq monthendday 31)) ; Jan (if (= monthvar 2) (setq monthendday 28)) ; Feb (if (= monthvar 3) (setq monthendday 31)) ; Mar (if (= monthvar 4) (setq monthendday 30)) ; Apr (if (= monthvar 5) (setq monthendday 31)) ; May (if (= monthvar 6) (setq monthendday 30)) ; Jun (if (= monthvar 7) (setq monthendday 31)) ; Jul (if (= monthvar 8) (setq monthendday 31)) ; Aug (if (= monthvar 9) (setq monthendday 30)) ; Sep (if (= monthvar 10) (setq monthendday 31)) ; Oct (if (= monthvar 11) (setq monthendday 30)) ; Nov (if (= monthvar 12) (setq monthendday 31)) ; Dec ) ; ================ ; Set up Renderer. ; ================ (defun c:sol_setrenderer () (graphscr) ; =========================================================== ; Loads the acrender.arx that is needed to enable renderings. ; =========================================================== (arxload "acrender.arx" "***error*** unable to load acrender.arx : please open and close the light dialog and run this again") ; ========================== ; Sets up rendering options. ; ========================== (c:rfileopt fileformat xres yres aratio colormode) (c:rpref "DEST" "FILE") (c:rpref "STYPE" "ARAY") (c:rpref "SELECT" "ALL") (c:rpref "TOGGLE" "SHADOW" "ON") (c:rpref "TOGGLE" "CACHE" "ON") (c:rpref "TOGGLE" "SHADOW" "ON") (c:rpref "TOGGLE" "FINISH" "ON") ) ; ==================== ; Set up print string. ; ==================== (defun c:sol_setptime () (graphscr) (if (< ptime 1000) (progn (if (< day 10) (setq ptimedate (strcat soldir "m" (vl-princ-to-string month) "_d0" (vl-princ-to-string day) "_h0" (vl-princ-to-string ptime))) (setq ptimedate (strcat soldir "m" (vl-princ-to-string month) "_d" (vl-princ-to-string day) "_h0" (vl-princ-to-string ptime))) ) ) (progn (if (< day 10) (setq ptimedate (strcat soldir "m" (vl-princ-to-string month) "_d0" (vl-princ-to-string day) "_h" (vl-princ-to-string ptime))) (setq ptimedate (strcat soldir "m" (vl-princ-to-string month) "_d" (vl-princ-to-string day) "_h" (vl-princ-to-string ptime))) ) ) ) ) ; ============================================ ; Checks that inputs are safe (error control). ; ============================================ (defun c:sol_checkinputs () (graphscr) (if (or (< xres 1) (< yres 1)) (error "Image size")) (if (or (< sollat -180) (> sollat 180)) (error "Latitude")) (if (or (> sollong 180) (< sollong -180)) (error "Longitude")) (if (or (< soltime -12) (> soltime 12)) (error "Timezone")) ) ; =========================================== ; bad input quit with error message function. ; =========================================== (defun error (msg) (princ (strcat "***error***: Bad " msg ", Please set. (SOLRENDERSET/SOLRENDERDEFAULT)")) (princ " ") (exit) ) ; ===================================== ; Prompt for rendering times and dates. ; ===================================== (defun c:sol_setinputs () (graphscr) ; ***sets the times of the day to be rendered for each day specified*** (setq sttime 0) (setq fintime 0) (while (or (< sttime 1) (> sttime 24)) (setq sttime (getint "what time should the renderings start?(hour in 24HR time):")) ) (while (or (> sttime fintime) (< fintime 1) (> fintime 24)) (setq fintime (getint "what time should the renderings finish?(hour in 24HR time):")) ) (setq fintime (+ fintime 1)) (initget 1 "Y N") (setq solmultiple (getkword "Do you want to render more then one day? (Y/N)")) ; ***for setting a single day for rendering*** (if (= solmultiple "N") (progn (setq stmonth 0) (while (or (< stmonth 1) (> stmonth 12)) (setq stmonth (getint "what month of the year (1-12):")) ) (c:sol_setmonthend stmonth) (setq stday 0) (while (or (< stday 1) (> stday monthendday)) (setq stday (getint "what day of that month?")) ) (setq finmonth stmonth) (setq finday stday) ) ) ; ***for setting a period of days to be rendered on*** (if (= solmultiple "Y") (progn ; ***Sets the starting month and day*** (setq stmonth 0) (while (or (< stmonth 1) (> stmonth 12)) (setq stmonth (getint "what month of the year to start?:")) ) (c:sol_setmonthend stmonth) (setq stday 0) (while (or (< stday 1) (> stday monthendday)) (setq stday (getint "what day of that month?")) ) ; ***Sets the finishing month and day*** (setq finmonth 0) (while (or (< finmonth 1) (> finmonth 12) (< finmonth stmonth)) (setq finmonth (getint "what month of the year to finish?:")) ) (c:sol_setmonthend finmonth) (if (= stmonth finmonth) (setq monthstday stday) (setq monthstday 1)) (setq finday 0) (while (or (< finday 1) (> finday monthendday) (< finday monthstday)) (setq finday (getint "what day of that month?")) ) ) ) ) ; ====================================== ; Rendering task that is run every hour. ; ====================================== (defun c:sol_solrender () (graphscr) ; ***sets the filename to be used for image*** (setq ptime (* 100 time)) (c:sol_setptime) ; ***creates a light for the specified time*** (c:light "ND" "temp_dis" 1 nil nil '(1 1 1) 0 nil nil 0 "on" month day time 0 "off" sollat sollong soltime) ; ***renders an image to the specified filename*** (c:render (vl-princ-to-string ptimedate)) ; ***deletes the light*** (c:light "D" "temp_dis") ; ========================================================= ; Runs Renderings on the halfhours when specified to do so. ; ========================================================= (if (= halfhours "Y") (progn ; ***sets the filename to be used for image*** (setq ptime (+ 30 ptime)) (c:sol_setptime) ; ***creates a light for the specified time*** (c:light "ND" "temp_dis" 1 nil nil '(1 1 1) 0 nil nil 0 "on" month day time 30 "off" sollat sollong soltime) ; ***renders an image to the specified filename*** (c:render (vl-princ-to-string ptimedate)) ; ***deletes the light*** (c:light "D" "temp_dis") ) ) ; ======================= ; End halfhour rendering. ; ======================= ) ; ================ ; Rendering loops. ; ================ (defun c:sol_renderloop () (graphscr) (setq month stmonth) (setq finmonth (+ finmonth 1)) (while (< month finmonth) ; Start month loop. (if (= stmonth month) (setq day stday) (setq day 1)) (if (= finmonth (+ month 1)) (setq thisfinday finday) (progn (c:sol_setmonthend month) (setq thisfinday monthendday) ) ) ; reset current day to time to start day for month (Setq thisfinday (+ thisfinday 1)) (while (< day thisfinday) ; Start day loop. (setq time sttime) ; reset current time to time to start time (while (< time fintime) ; Start hour loop. (c:sol_solrender) ; run the renders (setq time (+ time 1)) ; step the loop foward one time step. ) ; End hour loop. (setq day (+ day 1)) ; step the loop foward one time step. ) ; end day loop. (setq month (+ month 1)) ; step the loop foward one time step. ) ; end month loop. (princ) ;exit quietly ) ; ====================================== ; Function to run the rendering routine. ; ====================================== (defun c:solrender () (graphscr) (c:sol_checkinputs) (c:sol_setrenderer) (c:sol_setinputs) (c:sol_renderloop) ) ; End solrender function. (print "***solrender lisp loaded***") ; =========================================================== ; ; END OF SOLRENDER.LSP ; ; ===========================================================