Delta-Sword Posted July 10, 2009 Share Posted July 10, 2009 I have a problem with looping a function to a previous point. i have written a small program to 1. choose a layer name 2. check to see if the layer all ready exists if it does 3a. tell user it exists 3b. ask if they want to add to the existing layer. 3c. if the want to add to it set it as current. -if they dont want to add to it loop back to choosing the layer name 4. if the layer doesnt exist make it. (DEFUN C:SETLAYER () (SETQ PREVLAYER (GETVAR "CLAYER")) ********** (SETQ LAYERNAME (GETSTRING "\n ENTER NAME FOR NEW LAYER : ")) (SETQ CHECKLAYER (TBLSEARCH "LAYER" LAYERNAME )) ( IF CHECKLAYER (PROGN (PROMPT "\n LAYER ALREADY EXISTS : ") (SETQ CONTINUE (GETSTRING "\n ADD TO CURRENT LAYER? [Y/N] : ")) (IF ( = CONTINUE Y ) (COMMAND "-LAYER" "M" LAYERNAME "") (-------) ) ) (COMMAND "-LAYER" "M" LAYERNAME "") ) (PRINC) ) (PRINC) In the Code i want to loop from the (------) back up to the ***** but only if they select N. i hope someone can help. cos im pulling my hair out. what ever is left of it :x:x:x:x Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted July 10, 2009 Share Posted July 10, 2009 I have a problem with looping a function to a previous point. i have written a small program to 1. choose a layer name 2. check to see if the layer all ready exists if it does 3a. tell user it exists 3b. ask if they want to add to the existing layer. 3c. if the want to add to it set it as current. -if they dont want to add to it loop back to choosing the layer name 4. if the layer doesnt exist make it. (DEFUN C:SETLAYER () (SETQ PREVLAYER (GETVAR "CLAYER")) ********** (SETQ LAYERNAME (GETSTRING "\n ENTER NAME FOR NEW LAYER : ")) (SETQ CHECKLAYER (TBLSEARCH "LAYER" LAYERNAME )) ( IF CHECKLAYER (PROGN (PROMPT "\n LAYER ALREADY EXISTS : ") (SETQ CONTINUE (GETSTRING "\n ADD TO CURRENT LAYER? [Y/N] : ")) (IF ( = CONTINUE Y ) (COMMAND "-LAYER" "M" LAYERNAME "") (-------) ) ) (COMMAND "-LAYER" "M" LAYERNAME "") ) (PRINC) ) (PRINC) In the Code i want to loop from the (------) back up to the ***** but only if they select N. i hope someone can help. cos im pulling my hair out. what ever is left of it :x:x:x:x Try this: You can change the function name to your own choice. (DEFUN C:SETLAYER () (SETQ PREVLAYER (GETVAR "CLAYER")) (INPUT) ) (DEFUN INPUT () (SETQ LAYERNAME (GETSTRING "\n ENTER NAME FOR NEW LAYER : ")) (SETQ CHECKLAYER (TBLSEARCH "LAYER" LAYERNAME )) ( IF CHECKLAYER (PROGN (PROMPT "\n LAYER ALREADY EXISTS : ") (SETQ CONTINUE (GETSTRING "\n ADD TO CURRENT LAYER? [Y/N] : ")) (IF ( = CONTINUE Y ) (COMMAND "-LAYER" "M" LAYERNAME "") (INPUT) ) ) (COMMAND "-LAYER" "M" LAYERNAME "") ) (PRINC) ) (PRINC) Quote Link to comment Share on other sites More sharing options...
Delta-Sword Posted July 10, 2009 Author Share Posted July 10, 2009 THANK YOU SOOOOO MUCH have been looking through all manner of places for a special looping function. :\ didnt find one tho Thanks again Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 10, 2009 Share Posted July 10, 2009 This will probably give you the most control over the loop behaviour: (defun c:setlayer (/ lay) (while (progn (setq lay (getstring t "\nSpecify Layer Name: ")) (cond ((eq "" lay) nil) ; Exit loop ((not (snvalid lay)) (princ "\n** Invalid Layer Name **")) ((tblsearch "LAYER" lay) (princ "\n** Layer Already Exists **") (initget "Yes No") (if (eq "No" (getkword "\nAdd to Current Layer? [Y/N] <Yes> : ")) nil ; Exit loop (not (setvar "CLAYER" lay)))) ; Exit loop (t (command "_.-layer" "_M" lay "") nil)))) ; Exit Loop (princ)) Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted July 10, 2009 Share Posted July 10, 2009 This will probably give you the most control over the loop behaviour: (defun c:setlayer (/ lay) (while (progn (setq lay (getstring t "\nSpecify Layer Name: ")) (cond ((eq "" lay) nil) ; Exit loop ((not (snvalid lay)) (princ "\n** Invalid Layer Name **")) ((tblsearch "LAYER" lay) (princ "\n** Layer Already Exists **") (initget "Yes No") (if (eq "No" (getkword "\nAdd to Current Layer? [Y/N] <Yes> : ")) nil ; Exit loop (not (setvar "CLAYER" lay)))) ; Exit loop (t (command "_.-layer" "_M" lay "") nil)))) ; Exit Loop (princ)) The way to go Lee! Quote Link to comment Share on other sites More sharing options...
Delta-Sword Posted July 10, 2009 Author Share Posted July 10, 2009 hrmmm interesting i see what it does basically but could you explain the ((not (snvalid lay)) and ((eq "" lay) nil) and just the how each of the parts works. i have only started using lisps in last few weeks. many thanks Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted July 10, 2009 Share Posted July 10, 2009 hrmmm interesting i see what it does basically but could you explain the ((not (snvalid lay)) and ((eq "" lay) nil) and just the how each of the parts works. i have only started using lisps in last few weeks. many thanks snvalid checks the symbol table name for valid characters ((eq "" lay) nil) says if enter or blank information is supplied then exit the loop. All this is better error trapping. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 11, 2009 Share Posted July 11, 2009 i see what it does basically but could you explain the ((not (snvalid lay)) and ((eq "" lay) nil) and just the how each of the parts works. Pretty much echoeing what Buzzard said, snvalid will check for dodgy characters, like * for example in the layer name. If the user hits enter on the layer name prompt, an empty string is returned (""), hence the loop will exit. Tbh, its just one long wrapped test expression, no functions are executed within the main "loop". I would be inclined to use either vla-add or entmake to create the layer though, as it is much faster and much more reliable, but if you are just starting, (command "_.-layer"..) is quick and easy Quote Link to comment Share on other sites More sharing options...
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.