Help on lisp routine

Discussion in 'AutoCAD' started by Tim, May 10, 2004.

  1. Tim

    Tim Guest

    I have run into my programing limitations so I am asking for help here

    Its probaly not the most elegant of solutuions ( I am sure a dat file would
    work just as well but that really goes over my head as far as coding goes)

    What I want to be able to do is draw a line at whatever distance is needed
    and have the routine chop the line into 20' segments wherein it then excutes
    the "drawpipe" function for each 20' segment and whatever remains. I have it
    where the pipe is drawn automatically at 20' regardless of the length
    specified so that the pipe is not longer than what is obtainable. I even
    have it setting the new start & end points for the next pipe but cant get to
    go to the function.

    Any & all help is greatly appreciated.

    Thanks


    Tim W.

    (defun aop (a)
    (* pi (/ a 180.0))
    )
    (defun pipecl ()
    (initget 1)
    (setq sp (getpoint "\nPick Start of Pipe: "))
    (initget 1)
    (setq ep (getpoint sp "\nEnd point of pipe: " ))
    (setq pangle (angle sp ep))
    (setq plength (distance sp ep))
    (setq diam (getdist "\nDiameter of pipe in inches: <3 4 6 8 10 12> " sp))
    (setq diam1 (/ diam 12))
    (setq sdiam (* 1 diam1))
    (setq shdiam (/ sdiam 2))
    (setq diam1 (/ diam 12))
    (setq sdiam (* 1 diam1))
    (setq shdiam (/ sdiam 2))
    (setq anga90 (+ pangle (aop 90))) ; Angle of pipe + 90 deg
    (setq angb90 (- pangle (aop 90))) ; Angle of pipe - 90 deg
    (if (> plength 20)
    (setq ep (polar sp pangle 20))
    )
    (setq rlength (- plength 20))
    (setq nep (polar ep pangle rlength))

    (cond

    ((= diam 3)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.745))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.245))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.245))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.245)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.245))
    (setq p12 (polar sp anga90 (+ shdiam 0.245)))
    )
    )



    ((= diam 4)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.38))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.2133))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.2133))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.2133)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.2133))
    (setq p12 (polar sp anga90 (+ shdiam 0.2133)))
    (setq sp ep)

    )
    )

    ((= diam 6)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.4633))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.2133))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.2133))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.2133)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.2133))
    (setq p12 (polar sp anga90 (+ shdiam 0.2133)))
    )
    )

    ((= diam 8)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.5571))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.2288))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.2288))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.2288)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.2288))
    (setq p12 (polar sp anga90 (+ shdiam 0.2288)))
    )
    )

    ((= diam 10)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.6506))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.2339))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.2339))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.2339)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.2339))
    (setq p12 (polar sp anga90 (+ shdiam 0.2339)))
    )
    )

    ((= diam 12)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.745))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.245))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.245))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.245)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.245))
    (setq p12 (polar sp anga90 (+ shdiam 0.245)))
    )
    )
    );enf cond
    );end defun

    (defun drawpipe ()
    (command "pline" p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 "c"))

    (defun centerl ()
    (setq #CLE (getvar "clayer"))
    (if (null (tblsearch "layer" "Defpoints"))
    (command "layer" "m" "Defpoints" "c" "7" "" "")
    (command "layer" "s" "Defpoints" "" "")
    );end if
    (command "line" sp ep "")
    (setq ET (entlast))
    (command ".Change" ET "" "P" "LT" "CENTER" "" )
    (setvar "clayer" #CLE)
    )

    (defun C:NPIPE ()
    (pipecl)
    (centerl)
    (drawpipe)
    )
     
    Tim, May 10, 2004
    #1
  2. Tim

    Jason Wilder Guest

    Well, to begin with, you reset you're 'ep' (endpoint) variable from it's
    original value.

    I'd recommend leaving 'sp' and 'ep' alone once you have them and use a
    different set of values for the start/end point of each pipe segment. In
    all reality, all you'd have to do is change the segment start point for each
    new segment of pipe. So if someone draws a 50 unit line, you'll change the
    start point 3 times (2 x 20, 1 x 10).

    Next you can increment your remaining lenght, so once you set plength, then
    you 'chop' it off. For example, if it's over 20 in length, then you
    subtract 20 from 50 = 30. Draw a 20' segment, do that again so that you
    have 10 left. Each time, you can check (if (> plength 20)...); if plength
    comes up less than 20, you simply draw a pipe segment that is 10' long,
    rather than the default 20' max.

    Also, instead of having a different sub function for each pipe diameter, why
    not just pass the variables to a standard routine? Looks as though all the
    routines are the same, just the diam/shdiam change w/ each one, right?

    Let me know if this gives you any ideas, I think I'll have time tomorrow
    morning that I can help you rewrite some of this.
     
    Jason Wilder, May 10, 2004
    #2
  3. Tim

    Jason Wilder Guest

    Ugh, not to mention, you only execute (drawpipe) ONCE, so no wonder it's not
    drawing the other pipes, you don't loop your routine in any pattern, or calc
    out all the pipes that you need to draw.

    Also, you're (centerline) routine uses sp & ep, which you modify both of
    those in your (pipecl) routine, which means you'll never draw a 'correct'
    centerline.

    I have pretty good idea on what you're trying to do, you have all the right
    code, just need to get it organized a little better. I can help there.
     
    Jason Wilder, May 10, 2004
    #3
  4. Tim

    Tim Guest

    I had reset the endpoint to a 20' length regardless of the length given so
    that the drawn pipe would be no longer than 20'. with whatever remains being
    what it is. Just for FYI the centerline is there so that a total length of
    pipe can be had with some of the available routines out there since that
    seems to be easier than trying to get a total length from the individual
    segments.



    I see where you are going with this, but seeing and being able to code
    for it are not necessarily one in the same....I normally look
    for routines that are close to what I am trying to do so I can see how they
    did it and hopefully modify mine to suit my particular situation.
    Yes they are the same..as I said this probably isnt the most elegat way
    of going about doing what I am trying to do...thats why the post for
    help..I know there are other better ways of doing this and probably easier
    to.. :)
    Thanks for taking the time to help me with this by the way I appreciate
    it..

    Tim
     
    Tim, May 11, 2004
    #4
  5. Tim

    Tim Guest

    I ran your modified code and although it didnt bomb out, the pipe didnt come
    out exactely the way it should have..Your code is definitely more consice
    than what I had originally, and I would say probably easier to follow as
    well.

    Thanks for your time & effort in helping

    Tim
     
    Tim, May 11, 2004
    #5
  6. Tim

    TCEBob Guest

    I confess, I didn't run it. Mainly because other matters came up. You
    should be able to troubleshoot pretty easily. My favorite way is to
    execute one line at a time; just copy to the command line. Sounds
    tedious -- and it is -- but you can see what's happening and jump right
    in when something goes haywire. Don't copy if or while, though, just
    barge right through. Incomplete whiles will send the system into a
    different universe and you'll have to use Task Manager to get out.

    Please, tell me what "(setq sdiam (* 1 diam1))" does so I can rest at
    night.

    rs
     
    TCEBob, May 11, 2004
    #6
  7. Tim

    Jason Wilder Guest

    Here's what I have so far - I still haven't quite got it to put the last
    piece on that is less than 20'.

    (defun aop (a)
    (* pi (/ a 180.0))
    )

    (defun pipecl ( / )
    (setq stp (getpoint "\nPick Start of Pipe: "))
    (setq enp (getpoint stp "\nEnd point of pipe: " ))
    (setq pangle (angle stp enp))
    (setq plength (distance stp enp))
    (setq diam (getreal "\nDiameter of pipe in inches: <3 4 6 8 10 12>"))
    (setq diam1 (/ diam 12))
    (setq shdiam (/ diam1 2))
    (setq anga90 (+ pangle (aop 90))) ; Angle of pipe + 90 deg
    (setq angb90 (- pangle (aop 90))) ; Angle of pipe - 90 deg
    ;(if (> plength 20)
    ; (setq ep (polar sp pangle 20))
    ;)
    (setq rlength plength)
    (if (> plength 20)
    (progn
    (setq sp stp)
    (setq ep (polar sp pangle 20))
    );progn
    (progn
    (setq sp stp)
    (setq ep enp)
    );progn
    );if

    (while (> rlength 0)
    (princ rlength)

    (cond

    ((= diam 3)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.745))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.245))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.245))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.245)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.245))
    (setq p12 (polar sp anga90 (+ shdiam 0.245)))
    )
    )



    ((= diam 4)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.38))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.2133))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.2133))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.2133)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.2133))
    (setq p12 (polar sp anga90 (+ shdiam 0.2133)))

    )
    )

    ((= diam 6)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.4633))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.2133))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.2133))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.2133)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.2133))
    (setq p12 (polar sp anga90 (+ shdiam 0.2133)))
    )
    )

    ((= diam 8)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.5571))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.2288))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.2288))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.2288)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.2288))
    (setq p12 (polar sp anga90 (+ shdiam 0.2288)))
    )
    )

    ((= diam 10)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.6506))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.2339))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.2339))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.2339)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.2339))
    (setq p12 (polar sp anga90 (+ shdiam 0.2339)))
    )
    )

    ((= diam 12)
    (progn
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 0.745))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 0.245))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 0.245))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam 0.245)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 0.245))
    (setq p12 (polar sp anga90 (+ shdiam 0.245)))
    )
    )
    );end cond

    (command "pline" p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 "c")
    (command "_line" sp ep "")
    (setq ET (entlast))
    (command ".Change" ET "" "P" "LT" "CENTER" "")
    (command ".Change" ET "" "P" "LA" "defpoints" "")


    ;(if (< rlength 20) (setq rlength -1))

    (if (> rlength 20)
    (progn
    (setq rlength (- rlength 20))
    (setq sp ep)
    (setq ep (polar sp pangle 20))
    );progn
    );if
    (if (< rlength 20)
    (progn
    (setq sp ep)
    (setq ep etp)
    );progn
    )

    );while

    );end defun pipecl

    (defun centerl ()
    (setq #CLE (getvar "clayer"))
    (if (null (tblsearch "layer" "Defpoints"))
    (command "layer" "m" "Defpoints" "c" "7" "" "")
    (command "layer" "s" "Defpoints" "" "")
    );end if
    (setvar "clayer" #CLE)
    )

    (defun C:NPIPE ()
    (centerl)
    (pipecl)
    )
     
    Jason Wilder, May 11, 2004
    #7
  8. Tim

    Jason Wilder Guest

    Now, if mine and TCEBob's routines can be melded, I think we can have a
    pretty good routine here.

    Just need to figure out how to get that last piece out of my routine.

    I need to do my actual job that pays the bills, so maybe I can revisit it
    later.
     
    Jason Wilder, May 11, 2004
    #8
  9. Tim

    Tim Guest

    I am glad to see I am not the only one having a problem with that..I have
    looked at it until I am blue..I have tried a few things but none of them
    worked...I really apprecite the time and effort you are expending on this to
    help.

    Tim
     
    Tim, May 11, 2004
    #9
  10. Tim

    Jason Wilder Guest

    Here you go, I didn't revise it as much as TCEBob tried to, but I
    encorporated a common draw routine.

    (defun aop (a)
    (* pi (/ a 180.0))
    )

    (defun drawit( a b / )
    (setq sp1 (polar sp pangle 0.12))
    (setq ep1 (polar ep pangle -0.12))
    (setq p1 (polar sp angb90 a))
    (setq p2 (polar p1 pangle 0.12))
    (setq p3 (polar p2 anga90 b))
    (setq p4 (polar ep1 angb90 shdiam))
    (setq p5 (polar p4 angb90 b))
    (setq p6 (polar p5 pangle 0.12))
    (setq p7 (polar ep anga90 (+ shdiam b)))
    (setq p8 (polar p7 pangle -0.12))
    (setq p9 (polar ep1 anga90 shdiam))
    (setq p10 (polar sp1 anga90 shdiam))
    (setq p11 (polar p10 anga90 b))
    (setq p12 (polar sp anga90 (+ shdiam b)))

    (command "pline" p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 "c")
    (command "_line" sp ep "")
    (setq ET (entlast))
    (command ".Change" ET "" "P" "LT" "CENTER" "")
    (command ".Change" ET "" "P" "LA" "defpoints" "")

    ) ;drawit

    (defun pipecl ( / )
    (setq stp (getpoint "\nPick Start of Pipe: "))
    (setq enp (getpoint stp "\nEnd point of pipe: " ))
    (setq pangle (angle stp enp))
    (setq plength (distance stp enp))
    (setq diam (getreal "\nDiameter of pipe in inches: <3 4 6 8 10 12>"))
    (setq diam1 (/ diam 12))
    (setq shdiam (/ diam1 2))
    (setq anga90 (+ pangle (aop 90))) ; Angle of pipe + 90 deg
    (setq angb90 (- pangle (aop 90))) ; Angle of pipe - 90 deg
    (setq rlength plength)
    (if (> plength 20)
    (progn
    (setq sp stp)
    (setq ep (polar sp pangle 20))
    );progn
    (progn
    (setq sp stp)
    (setq ep enp)
    );progn
    );if

    (while (> rlength 0.0)
    (princ rlength)

    (if (< rlength 20) (setq rlength -1))

    (cond ;draw it
    ((= diam 3)
    (drawit 0.37 0.245)
    )
    ((= diam 4)
    (drawit 0.38 0.2133)
    )
    ((= diam 6)
    (drawit 0.4633 0.2133)
    )
    ((= diam 8)
    (drawit 0.5571 0.2288)
    )
    ((= diam 10)
    (drawit 0.6506 0.2339)
    )
    ((= diam 12)
    (drawit 0.745 0.245)
    )
    )

    (if (> rlength 20)
    (progn
    (setq rlength (- rlength 20))
    (setq sp ep)
    (setq ep (polar sp pangle 20))
    );progn
    );if
    (if (< rlength 20)
    (progn
    (setq ep enp)
    );progn
    )

    );while

    );end defun pipecl

    (defun centerl ()
    (setq #CLE (getvar "clayer"))
    (if (null (tblsearch "layer" "Defpoints"))
    (command "layer" "m" "Defpoints" "c" "7" "" "")
    (command "layer" "s" "Defpoints" "" "")
    );end if
    (setvar "clayer" #CLE)
    )

    (defun C:NPIPE ()
    (centerl)
    (pipecl)
    )
     
    Jason Wilder, May 12, 2004
    #10
  11. Tim

    PG. Guest

    OSMODE must be 0, to have this pipe drawn properly.

    -PG.
     
    PG., May 12, 2004
    #11
  12. Tim

    Tim Guest

    Thats perfect Jason thank you..

    I saved it as another name so I could compare yesterdays routine to todays
    to see how you got the last rlength to draw..I can use this as a good
    reference routine for the future, study it and learn from it.

    Thanks Again for all yours & TCEBob's help.

    Tim W.
     
    Tim, May 12, 2004
    #12
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.