Author Topic: Setbacks Creator  (Read 27681 times)

0 Members and 1 Guest are viewing this topic.

SMadsen

  • Guest
Setbacks Creator
« Reply #15 on: September 30, 2003, 08:02:06 AM »
Quote from: SMadsen
.. every line of code is stolen from somewhere anyway!

Mark, borrow away :)

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Setbacks Creator
« Reply #16 on: September 30, 2003, 08:24:45 AM »
"...stolen..." :lol:  w00t!  You got it stig.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Setbacks Creator
« Reply #17 on: September 30, 2003, 08:55:46 AM »
Ok...I am gonna need some time to look at this, and see where my questions are going to be...I had some for your last post of code, but I forgot them at home today... I will have something soon though...Thx agn..to all.

Rug
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

t-bear

  • Guest
Setbacks Creator
« Reply #18 on: September 30, 2003, 03:46:00 PM »
Who IS that masked man?
Stig, I'm impressed....and you gotta understand that I'm easily impressed.LOL
Heck, even Se7en and Daron amaze me!
Hi....I'm "The Bear"...a worthless no-account hanger-on who steals code from the brilliant and gives it to the brain-dead.  VERY pleased to make your aquaintance......

T-

SMadsen

  • Guest
Setbacks Creator
« Reply #19 on: September 30, 2003, 04:13:43 PM »
T-Bear, thanks for the kind words.
Se7en and Daron amazes me too at times, but their lisp code .. well  hehe J/K!

The pleasure is all mine.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Setbacks Creator
« Reply #20 on: September 30, 2003, 04:50:08 PM »
Yeah i know! Daron is frickin' awesome at lisp; his code confuses the hell out of me.  :lol:  (J/K Daron.)

BTW, Welcome abord Bear. There will be no mouse pad chewing here.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
Setbacks Creator
« Reply #21 on: September 30, 2003, 04:56:03 PM »
Quote from: semi-Se7en
his code confuses the he77 out of me.

My code confuses me too.

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Setbacks Creator
« Reply #22 on: September 30, 2003, 09:30:52 PM »
Stig-

All I have to say is wow! I finally learned how to add items to a sset. I was having a problem figuring that out. However...I am still lost with a few things...let's see if I can be clear enough here for all of you, and see if we can figure this out. Here is your code with most of my questions, and some comments to see if i understand this:

Code: [Select]
(defun GETVALUE (VAL SIDE / PRMPT INIT INQUIRY)
  (if (and (numberp VAL) (> VAL 0.0)) ;<- If 'val' is a real number and greater than 0, continue
    (setq PRMPT
  (strcat "Specify " SIDE " yard setback <" (rtos VAL) ">: ")
;<- Prompts for 'side' setbacks, and shows the current setbacks
 INIT 6
    )
    (setq PRMPT (strcat "Specify " SIDE " yard setback: ")
; <- same as above i believe, but I dont reall understand this
 INIT 7
    )
  )
  (initget INIT) ; gets the number supllied above
  (if (setq INQUIRY (getdist PRMPT)) ; sets 'inquiry' to the distance from 'prmpt'
    (setq VAL INQUIRY) ; sets val to distance recieved from last line
  )
  VAL ; returns val?
)


(defun OFFSETOBJECT (OFFDIST OFFPT SIDE SS / ENT LASTENT)
  (if (not SS)
    (setq SS (ssadd))
  ) ; if selection set is not named 'ss' then add items to 'ss'
  (setvar "ERRNO" 0) ; beyond lost here
  (while
    (and (setq ENT (car (entsel (strcat "\nSelect " SIDE " lot lines: "))))
; prompts to select current side lot lines,
; returns entname w/ car set that entity to
; ent and gets errno and continues if errno
; not equal to 52
(/= (getvar "ERRNO") 52) ; no clue
    )
     (setq LASTENT (entlast)) ; reselects the last entity selected/added
     (command ".OFFSET" OFFDIST ENT OFFPT "") ; offsets
     (cond ((not (eq LASTENT (entlast))); if entity does not equal last ent, continue
   (ssadd (entlast) SS) ; adds new entity to ss
  )
     )
  )
  (if (< 0 (sslength SS))
    SS
  ) ; if 0 is less than the # of ents in ss, continue
)

;; Main function
(defun C:SB (/       FRONTOFF SIDEOFF   REAROFF   USERLAY
    USERCMD   USEROSM USERFILL  OSP     TMP
    SSET      ENT LASTENT   MYPROMPT  *ERROR*
   )

  (defun *ERROR* (MSG)
    (if MSG
      (princ (strcat "Rugaroo made an error: " MSG))
    ) ; lost again
    (foreach VAR '(("clayer" USERLAY)
  ("cmdecho" USERCMD) ; for each variable, set uservars
  ("orthomode" USERORTH)
  ("osmode" USEROSM)
  ("filletrad" USERFILL)
 )
      (if (eval (cadr VAR)) ; if each uservar evaluate the 2nd item is present
(setvar (car VAR) (eval (cadr VAR)))
; like doing setvar "clayer" "something", and so on with all uservars in var
      )
    )
    (princ)
  )

  (setq USERLAY (getvar "clayer")
USERCMD (getvar "cmdecho")
USERORTH (getvar "orthomode")
USEROSM (getvar "osmode")
USERFILL (getvar "filletrad")
  )
  (setvar "cmdecho" 0)
  (setvar "orthomode" 0)
  (setvar "filletrad" 0)

  (setq FRONTOFF (distof (getcfg "AppData/Setbacks/Front"))
; sets frontoff to a corresponding integer corresponding w/ users lunits
SIDEOFF (distof (getcfg "AppData/Setbacks/Side")) ; same
REAROFF (distof (getcfg "AppData/Setbacks/Rear")) ; same
  )

  (setq FRONTOFF (GETVALUE FRONTOFF "Front") ; kind of confused here
SIDEOFF (GETVALUE SIDEOFF "Side")
REAROFF (GETVALUE REAROFF "Rear")
  )

  (cond ((and FRONTOFF
     SIDEOFF
     REAROFF
     (setq OSP (getpoint "\nPick the center of the lot: "))
; as long as f.off, s.off, r.off are present continue, but if not an error?
)
(setcfg "AppData/Setbacks/Front" (rtos FRONTOFF))
; places the setbacks into our config file
(setcfg "AppData/Setbacks/Side" (rtos SIDEOFF))
(setcfg "AppData/Setbacks/Rear" (rtos REAROFF))

(setq SSET (OFFSETOBJECT FRONTOFF OSP "Front" NIL)
; could you explain this a little more possibly?
      SSET (OFFSETOBJECT SIDEOFF OSP "Side" SSET)
      SSET (OFFSETOBJECT REAROFF OSP "Rear" SSET)
)

(setq LASTENT (entlast)) ; grabs the last entity created/added
(command ".BPOLY" OSP "") ;bpoly from osp
(cond ((not (eq (entlast) LASTENT))
; as long as a bpoly is made and does not equal above lastent, continue
(command ".LAYER" "Make" "SETBACKS" "") ;make out layer
(command ".CHPROP" (entlast) "" "Layer" "SETBACKS" "")
; changes properties of our bpoly
(command ".ERASE" SSET "") ; erases our selection set
(command ".EXPLODE" (entlast)) ;explodes our bpoly
(princ "\n\nSetbacks created...") ;ALL DONE!!!!
      )
      (t (princ "\nNo luck today :-(")) ;lost
)
)
  )
  (*ERROR* NIL) ;lost
)


Sorry for the formatting. Now some more questions...Why are you not using cl-cmdf instead of command? I believe it was actually Daron that told me it was much cleaner to use...Now that I come to think about it, that is the only other question I have besides what is in the code. Well how did I do?

Rug[/i]
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

daron

  • Guest
Setbacks Creator
« Reply #23 on: October 01, 2003, 10:12:47 AM »
Quote from: rugman
(setq SSET (OFFSETOBJECT FRONTOFF OSP "Front" NIL)
               ; could you explain this a little more possibly?
          SSET (OFFSETOBJECT SIDEOFF OSP "Side" SSET)
          SSET (OFFSETOBJECT REAROFF OSP "Rear" SSET)
    )

Look at the Offsetobject function. How many arguments (items before /) does it have? Where are those arguments stated in the function and what value is being passed in its place? Instead of writing out the OFFSETOBJECT three different times, you run it three different times, with slightly different controls. Think of the simplicity in that. How many times do you want to write the same code?
Quote from: rugman
I believe it was actually Daron that told me it was much cleaner to use...

Sorry, wrong there. I have NEVER used vl-cmdf in any of my code and have never told anybody to use it. I avoid it as much as possible. I feel the same way of it as I have come to feel about using command. I think Se7en was actually introducing it in his Ninja tutorial as a better cast for the broken leg that is "command".

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Setbacks Creator
« Reply #24 on: October 01, 2003, 10:30:13 AM »
Thx Daron...and yes you were right...It was 7 that actually brought the vl-cmdf function up...But yes I do see what you are saying.
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

SMadsen

  • Guest
Setbacks Creator
« Reply #25 on: October 01, 2003, 12:47:10 PM »
My comments with three ;'s

Code: [Select]
(defun GETVALUE   (VAL SIDE / PRMPT INIT INQUIRY)
  (if (and (numberp VAL) (> VAL 0.0))   ;<- If 'val' is a real number and greater than 0, continue
;;; ^correct in your comment
    (setq PRMPT
      (strcat "Specify " SIDE " yard setback <" (rtos VAL) ">: ")
               ;<- Prompts for 'side' setbacks, and shows the current setbacks
;;; ^correct in your comment
     INIT 6
    )
    (setq PRMPT   (strcat "Specify " SIDE " yard setback: ")
               ; <- same as above i believe, but I dont really understand this
;;; Remember that VAL comes directly from an attempt to retrieve a value
;;; from the configuration. Therefore VAL will be an empty string ("") if
;;; no such value is found - meaning that IF will go here. Not having a
;;; default value to offer, you would like to NOT have the brackets in the
;;; prompt and you would like the user to input a value (hence INITGET of
;;; 7 that will prohibit a null response).
     INIT   7
    )
  )
  (initget INIT)         ; gets the number supllied above
;;; ^correct in your comment
  (if (setq INQUIRY (getdist PRMPT))   ; sets 'inquiry' to the distance from 'prmpt'
;;; ^correct in your comment
    (setq VAL INQUIRY)         ; sets val to distance recieved from last line
;;; ^correct in your comment - if INQUIRY returns a number,
;;; otherwise VAL is still equal to VAL, i.e. the default value
  )
  VAL               ; returns val?
;;; ^correct in your comment
)


(defun OFFSETOBJECT (OFFDIST OFFPT SIDE SS / ENT LASTENT)
  (if (not SS)
    (setq SS (ssadd))
  )               ; if selection set is not named 'ss' then add items to 'ss'
;;; ^not correct in your comment. SSADD without arguments creates an empty
;;; selection set, making it possible to add entities to it later. You might
;;; say that this initializes a selection set ready for use.
  (setvar "ERRNO" 0)         ; beyond lost here
;;; the sysvar ERRNO does not necessarily get reset after last error. This
;;; means that ERRNO could hold the value 52 from any time during previous
;;; work in the drawing. It's reset here to 0, so that the loop below works.
  (while
    (and (setq ENT (car (entsel (strcat "\nSelect " SIDE " lot lines: "))))
               ; prompts to select current side lot lines,
               ; returns entname w/ car set that entity to
               ; ent and gets errno and continues if errno
               ; not equal to 52
;;; ^correct in your comment
    (/= (getvar "ERRNO") 52)   ; no clue
;;; sysvar ERRNO will be set (automatically by AutoCAD) to 52 if entity
;;; selecting with ENTSEL fails. This gives you a chance to exit the loop
;;; by simply hitting space (or clicking in empty drawing area which should
;;; not happen, but you can play with that particular case :)
    )
     (setq LASTENT (entlast))      ; reselects the last entity selected/added
;;; No, saves the last entity added
     (command ".OFFSET" OFFDIST ENT OFFPT "") ; offsets
;;; ^correct in your comment
     (cond ((not (eq LASTENT (entlast))); if entity does not equal last ent, continue
       (ssadd (entlast) SS)   ; adds new entity to ss
;;; ^correct in both comments
      )
     )
  )
  (if (< 0 (sslength SS))
    SS
  )               ; if 0 is less than the # of ents in ss, continue
;;; simply meaning if there are entities in the selection set then return it,
;;; otherwise return nil (if will fail and return nil)
)

;; Main function
(defun C:SB (/          FRONTOFF    SIDEOFF   REAROFF   USERLAY
        USERCMD   USEROSM    USERFILL  OSP        TMP
        SSET      ENT    LASTENT   MYPROMPT  *ERROR*
       )

  (defun *ERROR* (MSG)
    (if   MSG
      (princ (strcat "Rugaroo made an error: " MSG))
    )               ; lost again
    (foreach VAR '(("clayer" USERLAY)
         ("cmdecho" USERCMD)   ; for each variable, set uservars
         ("orthomode" USERORTH)
         ("osmode" USEROSM)
         ("filletrad" USERFILL)
        )
      (if (eval (cadr VAR))      ; if each uservar evaluate the 2nd item is present
   (setvar (car VAR) (eval (cadr VAR)))
               ; like doing setvar "clayer" "something", and so on with all uservars in var
;;; ^correct. Because variables are provided in a quoted list, they will have
;;; to be "ripped open" to read the value they hold. EVAL does this.
      )
    )
    (princ)
  )

  (setq   USERLAY    (getvar "clayer")
   USERCMD    (getvar "cmdecho")
   USERORTH (getvar "orthomode")
   USEROSM    (getvar "osmode")
   USERFILL (getvar "filletrad")
  )
  (setvar "cmdecho" 0)
  (setvar "orthomode" 0)
  (setvar "filletrad" 0)

  (setq   FRONTOFF (distof (getcfg "AppData/Setbacks/Front"))
               ; sets frontoff to a corresponding integer corresponding w/ users lunits
   SIDEOFF    (distof (getcfg "AppData/Setbacks/Side")) ; same
   REAROFF    (distof (getcfg "AppData/Setbacks/Rear")) ; same
  )

  (setq   FRONTOFF (GETVALUE FRONTOFF "Front") ; kind of confused here
;;; As Daron mentioned, look at the GetValue arguments and see what it does.
;;; It simply returns a value based in user input (user's value or default value)
   SIDEOFF    (GETVALUE SIDEOFF "Side")
   REAROFF    (GETVALUE REAROFF "Rear")
  )

  (cond   ((and FRONTOFF
         SIDEOFF
         REAROFF
         (setq OSP (getpoint "\nPick the center of the lot: "))
               ; as long as f.off, s.off, r.off are present continue, but if not an error?
    )
 ;;; ^Exactemento
    (setcfg "AppData/Setbacks/Front" (rtos FRONTOFF))
               ; places the setbacks into our config file
    (setcfg "AppData/Setbacks/Side" (rtos SIDEOFF))
    (setcfg "AppData/Setbacks/Rear" (rtos REAROFF))

    (setq SSET (OFFSETOBJECT FRONTOFF OSP "Front" NIL)
               ; could you explain this a little more possibly?
 ;;; I'll leave that to Darons posting
          SSET (OFFSETOBJECT SIDEOFF OSP "Side" SSET)
          SSET (OFFSETOBJECT REAROFF OSP "Rear" SSET)
    )

    (setq LASTENT (entlast))   ; grabs the last entity created/added
    (command ".BPOLY" OSP "")   ;bpoly from osp
    (cond ((not (eq (entlast) LASTENT))
               ; as long as a bpoly is made and does not equal above lastent, continue
      (command ".LAYER" "Make" "SETBACKS" "") ;make out layer
      (command ".CHPROP" (entlast) "" "Layer" "SETBACKS" "")
               ; changes properties of our bpoly
      (command ".ERASE" SSET "") ; erases our selection set
      (command ".EXPLODE" (entlast)) ;explodes our bpoly
      (princ "\n\nSetbacks created...") ;ALL DONE!!!!
 ;;; ^^^^Yup
          )
          (t (princ "\nNo luck today :-(")) ;lost
 ;;; If BPOLY did not make a boundary object then announce the sad news.
 ;;; A condition of T will always be true, so when COND is evaluating
 ;;; each of its conditions from top to bottom and it stumps into T it will
 ;;; say, "hey, I take this to be true!" and starts evaluating statements
 ;;; within the condition.
    )
   )
  )
  (*ERROR* NIL)            ;lost
;;; Can't explain it better than what I did before. You just have to
;;; make a fresh pot of coffee and stare at it until it reveals itself :)
)

daron

  • Guest
Setbacks Creator
« Reply #26 on: October 01, 2003, 01:53:21 PM »
Quote
(*ERROR* NIL)            ;lost

When I started working with lisp, functions with arguments really caused me to scream. I couldn't make sense of them. Let's see if I can help you realize what's happening. First go back to the code where Stig says he'll leave it to my post. We're referring to a set of functions with values that take the place of arguments in the function. I believe Se7en explained them as (Global / Local) variables. These Global variables are the arguments. You have to tell them their value for the function to work. In this case (*error* nil) is setting msg to nil. This will run the command with no error and will set your variables back to their original state. If you type a loaded function containing arguments like this: (offsetobject) you will get something like this:
Error: too few arguments

Why?

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Setbacks Creator
« Reply #27 on: October 01, 2003, 02:04:56 PM »
damn it! I knew that would bite me in the ass! I misused that damn word! :lol: I made a mistake by posting that little section, it was taken out of context and i didnt notice it till Mark pointed it out to me.

...Im sorry! lmao! Let me try to fix this error. Ill explain in a second daron.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Setbacks Creator
« Reply #28 on: October 01, 2003, 02:15:22 PM »
Quote
I knew that would bite me in the ass!


HEYHEYHEYHEYHEYHEYHEYHEYHEYHEY.................

All it takes is ONE!  HEYHEYHEYHEYHEY
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Setbacks Creator
« Reply #29 on: October 01, 2003, 02:29:06 PM »
Alright, i screwed up on that damn grafic and im NEVER gonna live it down.  *sigh* Im sorry, for confusing you.

The left side of the parens is for the argument and the right side is the local vars

Lets look at Stigs Error function.
Code: [Select]
(defun *ERROR* (MSG)
    (if   MSG
      (princ (strcat "Rugaroo made an error: " MSG))
    )               ; lost again
    (foreach VAR '(("clayer" USERLAY)
         ("cmdecho" USERCMD)   ; for each variable, set uservars
         ("orthomode" USERORTH)
         ("osmode" USEROSM)
         ("filletrad" USERFILL)
        )
...


You'll notice the first statment is an IF statement. Whats its say? (In words)
"If the MSG argument is true, then prompt this, else dont" So you see? If there is a msg, the function will promt "you made an error" otherwise it dosent.  Now when he used the "(error nil)" statment, what was the value of the message argument?

Edit: I feel like Charlie Brown trying to kick the football here! I screwed up again, but i think i fixed all the mistakes! If you guys see any more mistakes, let me know so i can go give myself a swirly.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org