Jump to content

slope lisp needed


NH3man!

Recommended Posts

What I am looking for is a lisp that if I use the alias (hc) that then it will prompt me to pick a block on my drawing, then prompt for slope to be used (ie. -1/8" per foot, +1/8 per foot or what ever slope I need per foot) then prompt for number of times to be copied, then prompt for spacing between the copied blocks (in feet and inches) and at last prompt for the direction of the copied blocks.

 

This will save me so much time from moving all these blocks manually.

 

Thanks in advance!!!

 

NH3man!

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

Forgot to mention that this is for 3d drawings so the pitch or slope is in the Z axis.

 

Thanks again!

Link to comment
Share on other sites

Hmmmm I don't mean to sound silly but if I had written it I wouldn't need to ask for it. I am not at all familiar with writing lisp code. About all I can do is describe what I need it to do.

Link to comment
Share on other sites

NH3, many of us are more than eager to dash into AutoCAD and cobble together a working script for anyone who comes a'calling.. heck, most people here are doing LISP for fun, and a challenge is always welcome.. but this is a HELP forum, not, as many people have indicated before, a LISP Bazaar. Give it a shot yourself, even if you can read through a few help files and give us a concept.. some idea you might have.. even a conceptual understanding of the raw mechanics of what might yield a plausible solution.. we would be more than happy to fill the gaps in your knowledge and help.

Link to comment
Share on other sites

I'll give you a starting point :P

 

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

Link to comment
Share on other sites

Tbh, this is a boring LISP to write - lots of user prompts, and tedious copying...

 

But, when you say this is in 3D, is the direction that the blocks are going to be copied in 3D space?

 

Or are you saying just to specify either x or y direction to copy?

 

Here is a starter for you to work on if you want... just incorporating defaults:

 

(defun c:hc (/ cBlk tmp1 tmp2 tmp3)
 
 (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))
 
 (if (and (setq cBlk (car (entsel "\nSelect Block: ")))
          (eq "INSERT" (cdr (assoc 0 (entget cBlk)))))
   (progn
     (initget 6)
     (setq tmp1 (getreal (strcat "\nSpecify Slope <" (rtos hc$slp:def) ">  1:")))
     (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))
     

Link to comment
Share on other sites

Tbh, this is a boring LISP to write - lots of user prompts, and tedious copying...

 

But, when you say this is in 3D, is the direction that the blocks are going to be copied in 3D space?

 

Or are you saying just to specify either x or y direction to copy?

 

Here is a starter for you to work on if you want... just incorporating defaults:

 

(defun c:hc (/ cBlk tmp1 tmp2 tmp3)
 
 (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))
 
 (if (and (setq cBlk (car (entsel "\nSelect Block: ")))
          (eq "INSERT" (cdr (assoc 0 (entget cBlk)))))
   (progn
     (initget 6)
     (setq tmp1 (getreal (strcat "\nSpecify Slope <" (rtos hc$slp:def) ">  1:")))
     (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))
     

 

Thanks Lee,

 

Yes the blocks that I need to copy will be copied in the direction of the x,y plane and elevation changes will be in the z axis.

 

I am trying to play with your starter but for some reason autocad just keeps closing on me at the moment. I am going to setup my laptop and try that way.

 

Thanks again.

Link to comment
Share on other sites

Thanks Lee,

 

Yes the blocks that I need to copy will be copied in the direction of the x,y plane and elevation changes will be in the z axis.

 

I am trying to play with your starter but for some reason autocad just keeps closing on me at the moment. I am going to setup my laptop and try that way.

 

Thanks again.

 

My starter is by no means finished... and won't even load in its current state.. but I thought I'd give you something concrete to start on, I may build on it, if I have time :)

Link to comment
Share on other sites

Ok, I couldn't resist... just to put you out of your misery:

 

BUT READ THE COMMENTS :)

 

(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) ">  1:")))
     (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)
                      (+ (* i hc$spc:def (/ 1 hc$slp:def)) (caddr blkpt)))))
             ((eq "Y" hx$dir:def)
              (command
                (car blkpt)
                (list (+ (* i hc$spc:def) (cadr blkpt))
                      (+ (* i hc$spc:def (/ 1 hc$slp:def)) (caddr blkpt))))))
       (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

Ok laptop is in the house and setup. I am going to try you code on a sample drawing.

 

Thanks you for your time and effort.

 

This is a quick drawing of what I am trying to do but in a much larger scale.

 

Thanks again!

block move.dwg

Link to comment
Share on other sites

Ok laptop is in the house and setup. I am going to try you code on a sample drawing.

 

Thanks you for your time and effort.

 

This is a quick drawing of what I am trying to do but in a much larger scale.

 

Thanks again!

 

Ok, I can only open 2004 format or earlier. :)

Link to comment
Share on other sites

I did try your code and it does work but I am trying to figure out why the elevation change is so drastic. I did a copy in x at 48 and slope of .125 and it look as it it did an elevation change of 125 ft. But this will be much faster than my way.

 

Thanks again Lee

Link to comment
Share on other sites

Is that .125 per every 12. I have tried higher numbers and I am getting close using 75 but not quiet there yet.

 

Also it will only allow movement in one direction from the original block. Not that is a big deal I just have to remember to place the original block there.

 

Thanks Lee

Link to comment
Share on other sites

Now you can enter 0.125 for slope:

 

(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 hc$slp:def) (caddr blkpt))[/color][/b][color=Red][color=Black])[/color][/color]))
             ((eq "Y" hx$dir:def)
              (command
                (car blkpt)
                (list (+ (* i hc$spc:def) (cadr blkpt))
                      [b][color=Red](+ (* i hc$spc:def hc$slp:def) (caddr blkpt))[/color][/b][color=Red][color=Black])[/color][/color])))
       (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))

Z value is calculated by red part ^^

 

i.e.

 

Z = ( Base Z) + (Counter * Spacing * Slope)

Link to comment
Share on other sites

This one is closer but still not getting the right slope. When I put in a slope of .125 it rises 30 over a 240 run, it should only rise 2.5 over a 240 run. I know you said it is calculated in red but I didn't see any numbers so I could even begin to play with your script.

 

Thanks Lee

Link to comment
Share on other sites

This one is closer but still not getting the right slope. When I put in a slope of .125 it rises 30 over a 240 run, it should only rise 2.5 over a 240 run.

 

Should it not rise 30? 0.125 x 240 = 30?

 

How do you get 2.5?

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...