Jump to content

slope lisp needed


NH3man!

Recommended Posts

Well not really. I should rise .125 per ft. (which is 12 inches)

 

240= 20ft so it would be 20x.125= 2.5

 

Sorry we still do not use decimal system over here. LOL

Link to comment
Share on other sites

  • Replies 70
  • Created
  • Last Reply

Top Posters In This Topic

  • NH3man!

    38

  • Lee Mac

    29

  • lpseifert

    1

  • Freerefill

    1

Was able to get it to work properly by dividing .125 by 12 (0.010416666666666666666666666666667).

 

I can live with that! Thanks so much Lee this will help a lot.

Link to comment
Share on other sites

Ok, but you could have sorted it also like this:

 

(defun c:hc  (/ *error* vlst ovar cBlk tmp1 tmp2 tmp3 tmp4 blkpt)

 ; Error Handler

 (defun *error* (msg)
   (if ovar (mapcar 'setvar vlst ovar))  ; Return System Variables
   (if (not (member msg '("Function cancelled" "quit / exit abort")))
     (princ (strcat "\n<< Error: " msg " >>")))  ; Print Error Message
   (princ))

 ; Collect and Set System Variables

 (setq vlst '("CMDECHO" "OSMODE")
       ovar (mapcar 'getvar vlst))
 (mapcar 'setvar vlst '(0 0))

 ; Set Defaults

 (or hc$slp:def (setq hc$slp:def 1))
 (or hc$cop:def (setq hc$cop:def 1))
 (or hc$spc:def (setq hc$spc:def 1))
 (or hc$dir:def (setq hc$dir:def "X"))

 ; Get Block to Copy

 (if (and (setq cBlk (car (entsel "\nSelect Block: ")))
          (eq "INSERT" (cdr (assoc 0 (entget cBlk)))))
   (progn

 ; Get User Input

     (initget 6)
     (setq tmp1 (getreal (strcat "\nSpecify Slope <" (rtos hc$slp:def) "> : ")))
     (or (not tmp1) (setq hc$slp:def tmp1))
     (initget 6)
     (setq tmp2 (getint (strcat "\nSpecify Number of Copies <" (itoa hc$cop:def) "> : ")))
     (or (not tmp2) (setq hc$cop:def tmp2))
     (initget 6)
     (setq tmp3 (getreal (strcat "\nSpecify Spacing <" (rtos hc$spc:def) "> : ")))
     (or (not tmp3) (setq hc$spc:def tmp3))
     (initget "X Y")
     (setq tmp4 (getkword (strcat "\nSpecify Direction [X/Y] <" hc$dir:def "> : ")))
     (or (not tmp4) (setq hc$dir:def tmp4))

 ; Get Block Insertion Point Information and Initiate Counter

     (setq blkpt (cdr (assoc 10 (entget cBlk)))
           i     1)

 ; Copy the Block a Number of Times

     (repeat hc$cop:def

       (command "_copy" cBlk "" blkpt)
       (cond ((eq "X" hc$dir:def)
              (command
                (list (+ (* i hc$spc:def) (car blkpt))
                      (cadr blkpt)
                      [b][color=Red](+ (* i (/ hc$spc:def 12.) hc$slp:def) (caddr blkpt)))))[/color][/b]
             ((eq "Y" hx$dir:def)
              (command
                (car blkpt)
                (list (+ (* i hc$spc:def) (cadr blkpt))
                      [b][color=Red](+ (* i (/ hc$spc:def 12.) hc$slp:def) (caddr blkpt))))))[/color][/b]
       (command)
       (setq i (1+ i))))

   ; Else No Block was Selected

   (princ "\n<!> No Block Selected <!>"))

 ; Return Sys Vars Back

 (mapcar 'setvar vlst ovar)

 ; Exit Cleanly

 (princ))

Link to comment
Share on other sites

I tried that one and it seemed to do the same thing. That is ok, I just have to remember to divide .125 by 12 and it works perfectly. I will keep looking at your code and if I can figure out where to make that happen I will try to edit it into and post back.

 

 

Thanks again Lee

Link to comment
Share on other sites

I just have to remember to divide .125 by 12 and it works perfectly.

 

The above code does the same as dividing the slope by 12... ^^ see highlighted part

 

btw, you may need to reload these routines when testing - as they have the same syntax :) hence ACAD may run an old program instead.

Link to comment
Share on other sites

I don't see the highlighted area. But if I were to guess this would be the area

(+ (* i (/ hc$spc:def 12.) hc$slp:def) (caddr blkpt))))))

I even loaded it on my desktop and it does not seem to divide by 12.

Link to comment
Share on other sites

I don't see the highlighted area. But if I were to guess this would be the area

(+ (* i (/ hc$spc:def 12.) hc$slp:def) (caddr blkpt))))))

I even loaded it on my desktop and it does not seem to divide by 12.

 

??? You don't see the highlighted area?

 

Look at the above code, and scroll down a bit - you should see the section I have made red.

Link to comment
Share on other sites

That is weird. It was not red the first few times I looked at it. Hmmm works even better now. Don't know how the thank you.

Link to comment
Share on other sites

I ran into a small problem. I can't get it to slope in the -x and -y direction. Or if it could use a -.125 so that it slopes in the opposite direction.

Link to comment
Share on other sites

I think I see what I can do to make it go -x and -y. But do I need two new separate commands for this.

Link to comment
Share on other sites

(setq tmp5 (getkword (strcat "\nSpecify Direction [+/-] : ")))

(or (not tmp5) (setq hc$dir:def tmp5))

 

Am I even close?

Link to comment
Share on other sites

There are two ways you could approach it, either have an extra "-X" and "-Y" in the direction part, or have a separate prompt after the X/Y saying + or -

 

which would you like to proceed with?

Link to comment
Share on other sites

The -x and -y would be faster I would think. I didn't know if that could be done. That was why I went the other way.

Link to comment
Share on other sites

Ok, give this a shot....

 

Going over my code, I can't believe how many typo's there were... I must've been half asleep when I first wrote it!

 

(defun c:hc  (/ *error* vlst ovar cBlk tmp1 tmp2 tmp3 tmp4 blkpt)

 ; Error Handler

 (defun *error*  (msg)
   (if ovar
     (mapcar 'setvar vlst ovar)) ; Return System Variables
   (if (not (member msg '("Function cancelled" "quit / exit abort")))
     (princ (strcat "\n<< Error: " msg " >>"))) ; Print Error Message
   (princ))

 ; Collect and Set System Variables

 (setq vlst '("CMDECHO" "OSMODE")
       ovar (mapcar 'getvar vlst))
 (mapcar 'setvar vlst '(0 0))

 ; Set Defaults

 (or hc$slp:def (setq hc$slp:def 1))
 (or hc$cop:def (setq hc$cop:def 1))
 (or hc$spc:def (setq hc$spc:def 1))
 (or hc$dir:def (setq hc$dir:def "X"))

 ; Get Block to Copy

 (if (and (setq cBlk (car (entsel "\nSelect Block: ")))
          (eq "INSERT" (cdr (assoc 0 (entget cBlk)))))
   (progn

 ; Get User Input

     (initget 6)
     (setq tmp1 (getreal (strcat "\nSpecify Slope <" (rtos hc$slp:def) "> : ")))
     (or (not tmp1) (setq hc$slp:def tmp1))
     (initget 6)
     (setq tmp2 (getint (strcat "\nSpecify Number of Copies <" (itoa hc$cop:def) "> : ")))
     (or (not tmp2) (setq hc$cop:def tmp2))
     (initget 6)
     (setq tmp3 (getreal (strcat "\nSpecify Spacing <" (rtos hc$spc:def) "> : ")))
     (or (not tmp3) (setq hc$spc:def tmp3))
     (initget "X Y -x -y")
     (setq tmp4 (getkword (strcat "\nSpecify Axis [X/Y/-X/-Y] <" hc$dir:def "> : ")))
     (or (not tmp4) (setq hc$dir:def tmp4))

 ; Get Block Insertion Point Information and Initiate Counter

     (setq blkpt (cdr (assoc 10 (entget cBlk)))
           i     1)

 ; Copy the Block a Number of Times

     (repeat hc$cop:def

       (command "_copy" cBlk "" blkpt)
       (cond ((eq "X" hc$dir:def)
              (command
                (list (+ (* i hc$spc:def) (car blkpt))
                      (cadr blkpt)
                      (+ (* i (/ hc$spc:def 12.) hc$slp:def) (caddr blkpt)))))
             ((eq "Y" hc$dir:def)
              (command
                (list (car blkpt)
                      (+ (* i hc$spc:def) (cadr blkpt))
                      (+ (* i (/ hc$spc:def 12.) hc$slp:def) (caddr blkpt)))))
             ((eq "-x" hc$dir:def)
              (command
                (list (+ (* -1. i hc$spc:def) (car blkpt))
                      (cadr blkpt)
                      (+ (* i (/ hc$spc:def 12.) hc$slp:def) (caddr blkpt)))))
             ((eq "-y" hc$dir:def)
              (command
                (list (car blkpt)
                      (+ (* -1. i hc$spc:def) (cadr blkpt))
                      (+ (* i (/ hc$spc:def 12.) hc$slp:def) (caddr blkpt)))))
             ) ; end cond
       (command)
       (setq i (1+ i))))

 ; Else No Block was Selected

   (princ "\n<!> No Block Selected <!>"))

 ; Return Sys Vars Back

 (mapcar 'setvar vlst ovar)

 ; Exit Cleanly

 (princ))

Link to comment
Share on other sites

(setq tmp4 (getkword (strcat "\nSpecify Direction [X/-X/Y/-Y] : ")))

(or (not tmp4) (setq hc$dir:def tmp4)

 

 

Something like this maybe

Link to comment
Share on other sites

(setq tmp4 (getkword (strcat "\nSpecify Direction [X/-X/Y/-Y] : ")))

(or (not tmp4) (setq hc$dir:def tmp4)

 

 

Something like this maybe

 

Nice one :D

 

Then you just got to include those terms in the initget function, and also make a few extra conditional statements :)

 

Good work

Link to comment
Share on other sites

Damn much faster than I. I am starting to see how it works though. Thanks again Lee

 

It really isn't too difficult when you get the hang of it :D

 

It just looks like jargon at first glance - you've just gotta break it down bit by bit :)

 

The reason I named the variables so obscurely such as hc$slp:def with dollar signs and colons, is because they are what is known as "Global Variables" as opposed to local variables - meaning they hold their values throughout the drawing session, so one must give them less common names to prevent possible clashes with other programs that may be running.

 

But more obscure names also means more typo's! :P

 

Lee

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...