broncos15 Posted December 7, 2015 Author Posted December 7, 2015 (edited) (defun BRONC:settings () (while (not *offsetdistans*) (setq *offsetdistans* (getreal "\nEnter Offset Distance: " )) (if (not *offsetdistans*) (princ "\nHEY YOU! I need some input here!"))) (while (not *offsetheightans*) (setq *offsetheight* (getreal "\nEnter Elevation Difference: ")) (if (not *offsetheightans*) (princ "\nHEY YOU! I need some input here!"))) ) (defun BRONC:exit () (princ "\nYou have exited my program. Good Day to you Sir!") (princ) ) (initget "Settings eXit") (setq sel (entsel "\nSelect the feature line you want to offset [settings eXit]: ")) (cond ([color=blue](= sel "Settings" )[/color][color=lime](BRONC:settings)[/color]);User has selected setttings ([color=blue](= sel "eXit")[/color][color=lime](BRONC:exit)[/color]);User has selected to exit [color=blue]((/= sel nil)[/color][color=lime](setq ent (car sel)) (BRONC:moveonIhaveaselection)[/color]);if its is neither settings or exit and its not nil it must be a slection returned by entsel );end cond This is an example of how I like to use the condition statement. Use Subroutines - It makes it easier to read and not get lost in the code. Hippe013, thank you for the help. I agree, the subroutines make the code much cleaner to look at. This is my code now, but I am still having an issue when selecting a feature line I get: "not a feature line:extra cdrs in dotted pair on input". I am sorry that I keep having so many issues. (defun c:makeparkingcurb (/ ent ent1 *error*) (defun *error* (msg) (if (not (member msg '("Function cancelled" "quit / exit abort")) ) (princ (strcat "\nError: " msg)) ) (princ) ) (if (not SurfaceDefaultAdd) (CheckorGetSurface) ) (if (not *offsetdistans*) (setq *offsetdistans* 0.5) ) (if (not *offsetheightans*) (setq *offsetheightans* 0.5) ) (setq whilestop t) (while whilestop (initget "Settings eXit") (setq sel (entsel "\nSelect the feature line you want to offset [settings eXit]: " ) ) (cond ((= sel "Settings") (BRONC:settings)) ;User has selected setttings ((= sel "eXit") (BRONC:exit)(setq whilestop nil)) ;User has selected to exit ((/= sel nil) (setq ent (car sel)) (BRONC:moveonIhaveaselection) ) ) (princ) )) ;;;Setting Default Surface Function (defun CheckorGetSurface () (while (not (and (setq SurfaceDefaultAdd (car (entsel "\rSelect the Main Surace you to be the default: " ) ) ) (= "AECC_TIN_SURFACE" (cdr (assoc 0 (entget SurfaceDefaultAdd))) ) ) ) ) ) ;;;Subroutines for the Settings portion and exit portion of the code (defun BRONC:settings () (while (not *offsetdistans*) (setq *offsetdistans* (getreal "\nEnter Offset Distance: ")) (if (not *offsetdistans*) (princ "\nPlease put the offset distance in.") ) ) (while (not *offsetheightans*) (setq *offsetheight* (getreal "\nEnter Elevation Difference: ")) (if (not *offsetheightans*) (princ "\nPlease put the elevation difference in.") ) ) ) (defun BRONC:exit () (princ "\nYou have exited the curb making routine.") (princ) ) ;;;My selection subroutine (defun BRONC:moveonIhaveaselection () ((setq entlist (entget ent)) (cond (= "AECC_FEATURE_LINE" (cdr (assoc 0 entlist))) (command "._OffsetFeature" *offsetdistans* ent) (princ "\nSpecify side to offset: ") (command pause *offsetheightans* "") (setq ent1 (entlast)) (command "._AddSurfaceBreaklines" SurfaceDefaultAdd ent1 "") ) (princ "\nNot a feature line") ) ) Edited December 7, 2015 by broncos15 Quote
Hippe013 Posted December 7, 2015 Posted December 7, 2015 The problem appears to be in the following: (defun BRONC:moveonIhaveaselection () [color="red"]([/color](setq entlist (entget ent)) (cond (= "AECC_FEATURE_LINE" (cdr (assoc 0 entlist))) (command "._OffsetFeature" *offsetdistans* ent) (princ "\nSpecify side to offset: ") (command pause *offsetheightans* "") (setq ent1 (entlast)) (command "._AddSurfaceBreaklines" SurfaceDefaultAdd ent1 "") ) (princ "\nNot a feature line") ) [color="red"])[/color] Remove the extra parans. Also your cond statement still isn't correct. No need to apologize. I am happy to help. Quote
broncos15 Posted December 7, 2015 Author Posted December 7, 2015 (edited) The problem appears to be in the following: (defun BRONC:moveonIhaveaselection () [color=red]([/color](setq entlist (entget ent)) (cond (= "AECC_FEATURE_LINE" (cdr (assoc 0 entlist))) (command "._OffsetFeature" *offsetdistans* ent) (princ "\nSpecify side to offset: ") (command pause *offsetheightans* "") (setq ent1 (entlast)) (command "._AddSurfaceBreaklines" SurfaceDefaultAdd ent1 "") ) (princ "\nNot a feature line") ) [color=red])[/color] Remove the extra parans. Also your cond statement still isn't correct. No need to apologize. I am happy to help. Thanks Hippe013, I got it up and running thanks to you. I am curious, how can I exit the while loop by hitting enter instead of exit because I haven't ever had to exit a while loop that wasn't dependent upon an ssget function. I keep messing with the settings portion and I can't figure out a way to have the prompt give the current offset distance and height. Am I missing something with the prompts, or is it not possible? Edited December 7, 2015 by broncos15 Quote
Hippe013 Posted December 7, 2015 Posted December 7, 2015 (edited) I hope that you don't mind, but I have taken the liberty of rewriting your code. I made changes to the settings subroutine since the variables once set will always exist. This will not allow for changing the offsets. Notice how clean and simple the main routine is. Everything else is handled by subroutines. This way you can get away from using a while loop. (defun Bronc:selection () (initget "Settings eXit") (setq sel (entsel "\nSelect Feature Line to Offset [settings eXit]: ")) (cond ((= sel "Settings")(Bronc:Settings)) ((= sel "eXit")(Bronc:Exit)) ((/= sel nil)(Bronc:offset sel)) );end cond );end defun selection (defun BRONC:settings () (setq *newoffsetdistans* nil *newoffsetheightans* nil) (while (not *newoffsetdistans*) (setq *newoffsetdistans* (getreal "\nEnter Offset Distance: ")) (if (not *newoffsetdistans*) (princ "\nPlease put the offset distance in.")) );end while (setq *offsetdistans* *newoffsetdistans*) (while (not *newoffsetheightans*) (setq *newoffsetheightans* (getreal "\nEnter Elevation Difference: ")) (if (not *newoffsetheightans*) (princ "\nPlease put the elevation difference in.")) );end while (setq *offsetheightans* *newoffsetheightans*) (Bronc:selection) );end defun settings (defun BRONC:exit () (princ "\nYou have exited the curb making routine.") );end defun exit (defun Bronc:offset (sel) (setq ent (car sel)) (if (= "AECC_FEATURE_LINE" (cdr (assoc 0 (entget ent)))) (progn ;All is good - offset the featureline (command "._OffsetFeature" *offsetdistans* ent) (princ "\nSpecify side to offset: ") (command pause *offsetheightans* "") (setq new-ent (entlast)) (command "._AddSurfaceBreaklines" SurfaceDefaultAdd new-ent "") );end progn (progn (princ "\nError: Expected a Feature Line.") (Bronc:selection) ) ) );end defun offset (defun Bronc:CheckorGetSurface () (while (not (and (setq SurfaceDefaultAdd (car (entsel "\nSelect the Main Surace you to be the default: "))) (= "AECC_TIN_SURFACE" (cdr (assoc 0 (entget SurfaceDefaultAdd)))))) );end while );end checkorgetsurface (defun c:make-curb () (if (not SurfacedefaultAdd) (bronc:checkOrGetSurface)) (if (not *offsetdistans*) (setq *offsetdistans* 0.5)) (if (not *offsetheightans*) (setq *offsetheightans* 0.5)) (Bronc:selection) (princ) );end defun make-curb Now the only thing to do is make everything ( that isn't needed to be global ) local. Edited December 7, 2015 by Hippe013 Fixed Error In Code Quote
broncos15 Posted December 7, 2015 Author Posted December 7, 2015 I hope that you don't mind, but I have taken the liberty of rewriting your code. I made changes to the settings subroutine since the variables once set will always exist. This will not allow for changing the offsets. Notice how clean and simple the main routine is. Everything else is handled by subroutines. This way you can get away from using a while loop. (defun Bronc:selection () (initget "Settings eXit") (setq sel (entsel "\nSelect Feature Line to Offset [settings eXit]: ")) (cond ((= sel "Settings")(Bronc:Settings)) ((= sel "eXit")(Bronc:Exit)) ((/= sel nil)(Bronc:offset sel)) );end cond );end defun selection (defun BRONC:settings () (setq *newoffsetdistans* nil *newoffsetheightans* nil) (while (not *newoffsetdistans*) (setq *newoffsetdistans* (getreal "\nEnter Offset Distance: ")) (if (not *newoffsetdistans*) (princ "\nPlease put the offset distance in.")) );end while (setq *offsetdistans* *newoffsetdistans*) (while (not *newoffsetheightans*) (setq *newoffsetheightans* (getreal "\nEnter Elevation Difference: ")) (if (not *newoffsetheightans*) (princ "\nPlease put the elevation difference in.")) ) (setq *offsetheightans* *newoffsetheightans*) (Bronc:selection);end while );end defun settings (defun BRONC:exit () (princ "\nYou have exited the curb making routine.") ) (defun Bronc:offset (sel) (setq ent (car sel)) (if (= "AECC_FEATURE_LINE" (cdr (assoc 0 (entget ent)))) (progn ;All is good - offset the featureline (command "._OffsetFeature" *offsetdistans* ent) (princ "\nSpecify side to offset: ") (command pause *offsetheightans* "") (setq new-ent (entlast)) (command "._AddSurfaceBreaklines" SurfaceDefaultAdd new-ent "") );end progn (progn (princ "\nError: Expected a Feature Line.") (Bronc:selection) ) ) );end defun offset (defun Bronc:CheckorGetSurface () (while (not (and (setq SurfaceDefaultAdd (car (entsel "\nSelect the Main Surace you to be the default: "))) (= "AECC_TIN_SURFACE" (cdr (assoc 0 (entget SurfaceDefaultAdd)))))) );end while );end checkorgetsurface (defun c:make-curb () (if (not SurfacedefaultAdd) (bronc:checkOrGetSurface)) (if (not *offsetdistans*) (setq offsetdistans* 0.5)) (if (not *offsetheightans*) (setq *offsetheightans* 0.5)) (Bronc:selection) (princ) );end defun make-curb Now the only thing to do is make everything ( that isn't needed to be global ) local. Hippe013, I really like the code. I ended up deciding to change the settings routine to the following (defun BRONC:settings ( ) (setq *offsetdistans* (cond ( (getreal (strcat "\nOffset distance <" (rtos (setq *offsetdistans* (cond (*offsetdistans*) (1) ) ) ) ">: " ) ) ) (*offsetdistans*) ) ) (setq *offsetheightans* (cond ( (getreal (strcat "\nElevation Difference <" (rtos (setq *offsetheightans* (cond (*offsetheightans*) (1) ) ) ) ">: " ) ) ) (*offsetheightans*) ) ) ) I liked the way that this would prompt, but also give the old settings. thank you so much for your help on this! Quote
Hippe013 Posted December 7, 2015 Posted December 7, 2015 Nice! Except that you may want to take another look at your cond statement. Also note that at the end of the settings subroutine calls Bronc:selection allowing for looping from selection toi settings and back to selection. How would you feel about saving those settings to a cfg so that the settings are saved from session to session? (setcfg "appdata/makecurb/offsetdist" (vl-princ-to-string *offsetdistans*)) (setcfg "appdata/makecurb/offsetheight" (vl-princ-to-string *offsetheightans*)) And retrieve those values: (setq *offsetdistans* (getcfg "appdata/makecurb/offsetdist")) (setq *offsetheightand* (getcfg "appdata/makecurb/offsetheight")) Quote
broncos15 Posted December 7, 2015 Author Posted December 7, 2015 (edited) Nice! Except that you may want to take another look at your cond statement. Also note that at the end of the settings subroutine calls Bronc:selection allowing for looping from selection toi settings and back to selection. How would you feel about saving those settings to a cfg so that the settings are saved from session to session? (setcfg "appdata/makecurb/offsetdist" (vl-princ-to-string *offsetdistans*)) (setcfg "appdata/makecurb/offsetheight" (vl-princ-to-string *offsetheightans*)) And retrieve those values: (setq *offsetdistans* (getcfg "appdata/makecurb/offsetdist")) (setq *offsetheightand* (getcfg "appdata/makecurb/offsetheight")) I had thought about that, the only reason I didn't want to is that in 95% of the cases, I want to offset a curb .5 feet and raise it .5 feet, so I didn't think it was worth it to add that in (or to use setenv and getenv). Am I missing something on the conditional statement again haha? I can't get it to error so that's why I assumed it was correct. Edited December 7, 2015 by broncos15 Quote
Hippe013 Posted December 8, 2015 Posted December 8, 2015 Broncos, The following settings subroutine sets the default offsets to 0.5 if no value exists. It then prompts for new values showing the current value. If the user just enters through without input then the current value will remain. Consider the following: (defun BRONC:settings () (if (not *offsetdistans*) (setq *offsetdistans* 0.5)) ;Set Default to 0.5 (if (not *offsetheightans*) (setq *offsetheightans* 0.5)) ;Set Default to 0.5 (setq return (getreal (strcat "\nEnter Offset Distance: < " (rtos *offsetdistans* 2 2) " >")));Prompt for a new setting (if return ;If the user just entered through then return is nil (setq *offsetdistans* return));User has a new value for offset distance else just use the value of *offsetdistans* (setq return (getreal (strcat "\nEnter Elevation Difference: < " (rtos *offsetheightans* 2 2) " >")));prompt for a new setting (if return ;If the user just entered through then return is nil (setq *offsetheightans* return));User has a new value for offset height else just use the current value of *offsetheightans* (Bronc:selection);Return to the selection prompt );end defun settings Quote
broncos15 Posted December 9, 2015 Author Posted December 9, 2015 Broncos, The following settings subroutine sets the default offsets to 0.5 if no value exists. It then prompts for new values showing the current value. If the user just enters through without input then the current value will remain. Consider the following: (defun BRONC:settings () (if (not *offsetdistans*) (setq *offsetdistans* 0.5)) ;Set Default to 0.5 (if (not *offsetheightans*) (setq *offsetheightans* 0.5)) ;Set Default to 0.5 (setq return (getreal (strcat "\nEnter Offset Distance: < " (rtos *offsetdistans* 2 2) " >")));Prompt for a new setting (if return ;If the user just entered through then return is nil (setq *offsetdistans* return));User has a new value for offset distance else just use the value of *offsetdistans* (setq return (getreal (strcat "\nEnter Elevation Difference: < " (rtos *offsetheightans* 2 2) " >")));prompt for a new setting (if return ;If the user just entered through then return is nil (setq *offsetheightans* return));User has a new value for offset height else just use the current value of *offsetheightans* (Bronc:selection);Return to the selection prompt );end defun settings Hippe013, thank you for the help! I decided that this code would be a good one to work on improving my looping skills and conditional statement skills, so I ended up rewriting portions of the code to practice. This is what I ended up doing for the settings portion (I set *offsetdistans* and *offsetdistheightans* in the the defun c:makeparkingcurb portion of the code) : (defun BRONC:settings ( ) (setq *offsetdistans* (cond ( (getreal (strcat "\nOffset distance <" (rtos *offsetdistans*) ">: " ) ) ) (*offsetdistans*) ) ) (setq *offsetheightans* (cond ( (getreal (strcat "\nOffset distance <" (rtos *offsetheightans*) ">: " ) ) ) (*offsetheightans*) ) ) ) Quote
Hippe013 Posted December 9, 2015 Posted December 9, 2015 Does it work okay? I had put the (Bronc:Selection) at the end of the settings so that it returns back to the selection prompt after running through the settings. Quote
broncos15 Posted December 9, 2015 Author Posted December 9, 2015 Does it work okay? I had put the (Bronc:Selection) at the end of the settings so that it returns back to the selection prompt after running through the settings. Yes it does. During my rewriting practice, I used a while loop that brings everything back to it if a flag variable isn't set to nil. Thanks again for your advice and help with this code. I know I will definitely make use of different functions in the future, it makes for a much cleaner code and one that is easier to debug for me personally. Quote
Hippe013 Posted December 9, 2015 Posted December 9, 2015 Right on! Happy to hear that it's all working! Cheers! hippe013 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.