Author Topic: Generate a LISP Routine?  (Read 10229 times)

0 Members and 1 Guest are viewing this topic.

MGEE

  • Guest
Generate a LISP Routine?
« on: May 03, 2004, 09:06:44 AM »
How dificult would it be to generate a routine to automate a process i use to make a Pipe template?
I'll email you the instructional drawing that explains how I do it.
Thanks
MGEE

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Generate a LISP Routine?
« Reply #1 on: May 03, 2004, 09:09:56 AM »
why not put the dwg on the lilly.pond for all to see? or do you want too keep it private?

http://theswamp.org/lilly.pond/
TheSwamp.org  (serving the CAD community since 2003)

hendie

  • Guest
Generate a LISP Routine?
« Reply #2 on: May 03, 2004, 09:13:33 AM »
or if you need to keep the drawing private, then if you can give us some more info to go on, I'm sure the combined intellect of the reptillian inhabitants here can come up with something

MGEE

  • Guest
Generate a LISP Routine?
« Reply #3 on: May 03, 2004, 09:41:06 AM »
I would like to keep it a bit private until the routine is finished. I'd like to be able to write the routine myself but need a little guidance. I've been looking at a couple other routines to see how they are done and the similarities of what mine needs to do. Can I link or join basic commands together to do it, cause I'm basically doing a few commands to generate the template? Or is Lisp quicker?
Thanks,
MGEE

hendie

  • Guest
Generate a LISP Routine?
« Reply #4 on: May 03, 2004, 09:47:10 AM »
It all depends upon exactyl what you want to do. Lisp is probably better in the long run.
First of all, start writing some pseudo code ~ i.e. ~ what should the function do, step by step. What prompts do you want to have ? What user interaction should there be ? etc

just take a look at what you do now and write it down, step by step, post that here and we'll try and help

MGEE

  • Guest
Generate a LISP Routine?
« Reply #5 on: May 03, 2004, 09:49:52 AM »
Cool, O.K. I'll do that. Check back in a while.
Thanks
MGEE

MGEE

  • Guest
Generate a LISP Routine?
« Reply #6 on: May 03, 2004, 12:58:48 PM »
Here ya go.

This would be to generate what I call a Fish mouth or saddle connection.

Draw a circle ( could I have a dialog box to choose which pipe to use & it draws the I.D. & I.D.)
? offset the circle by the wall thickness.
This circle will represent the Branch Line.

Draw a line from 180 quadrant of inside circle to 0 quadrant.
Array the line to fill the circle ( ** minimum of 32)
Draw a line from CTR to @30" < 270

Draw a circle ( could I have a dialog box to choose which pie to use & it draws the I.D. & I.D.)
? offset the circle by the wall thickness.
This circle will represent the Main Line.

Project lines from the intersections of the ( End Point of arrayed lines & inner circle)
270 Degrees to the circle below. (Main Line)

Draw 2 Horizontal lines between the 2 circles to trim a short amount of each Vertical line
Approximately 1/2"

Draw a Vertical line the length of the Circumference of the O.D. of the first circle,
The Branch Line circle.

Use Point/ Divide to place points onto the verticle line (match the count of segments spaces,from the array)

rotate & move the projection lines that touch the lower circle (Main Line)
place each one consecutively, it's end on a point that's on the verticle line.

Mirror the lines just placed onto the verticle line to finish the top 1/2 of points.

SMadsen

  • Guest
Generate a LISP Routine?
« Reply #7 on: May 03, 2004, 01:20:05 PM »
Wheew .. do you have a screen shot of that?

t-bear

  • Guest
Generate a LISP Routine?
« Reply #8 on: May 03, 2004, 01:29:49 PM »
Mgee.....
OBVIOUSLY... this isn't mine.  I just use it all the time.  Hopefully, it will do what you need.....

Code: [Select]
;* FLATPIPE.LSP Draws a flat pattern to be wrapped around a pipe indicating
;* Cut line for intersection of two pipes with OPTIONAL LATERAL offset of
;* Pipes' Centerlines.
;* Logical Preconditions taken from FLATPAT.LSP in New Riders' "MAXIMIZING
;* AUTOCAD:Inside Autolisp";
;* Mathematical Formula from "DESIGN OF WELDED STRUCTURES" by O.W. Blodgett
;* THE JAMES F.LINCOLN ARC WELDING FOUNDATION;
;* Worked out by MOSHE AGMON,ISRAEL, i.d. No. at CompuServe 100264,1206
;----------------------------------------------------------------------------
;     P1 = Optional Start point for pattern curve.
;INT_ang = Angle of Intersection between the pipes.
;VAR_ang = Varying Angle.
;INC_ang = Increament of Varying Angle.
;     R1 = Radius of Intersecting Pipe.
;     R2 = Radius of Base Pipe.
;    PR1 = Circumference of Intersecting Pipe.
;      e = Lateral Offset of Pipes' Centers.    Positive for Right,
                                               ;Negative for Left Offset.
;     DX = Increament Length on "X" axis.      
;      X = Length on "X" axis.
;      L = List of Points (X,Y).
;     GA = Go ahead Flag.
;      Q = R1+R2.
;      D = Decreament due to Pipes' Offset.
;    
(defun C:FLATPIPE ( / P1 INT_ang R1 R2 e INC_ang VAR_ang PR1 DX X L Q D GA)

(setq
   P1 (getpoint "\nPick Start Point at Lower Left Corner of the Screen: ")
;                       Get start point of pattern
   R1 (/ (getdist "\nEnter Dia. of Intersecting Pipe: ") 2) ;Get intersecting
;                                                            pipe  diameter
   R2 (/ (getdist "\nEnter Dia. of Base Pipe: ") 2)  ;Get base pipe diameter
   e (getdist "\nEnter Lateral Offset of Pipes' Centers ,Positive for Right,
   Negative for Left Offset, Zero for None: <0.0> ")
   INT_ang (getangle "\nEnter Intersection angle: ")  ;Get angle of Intersecti
   ;  on
   INC_ang (/ PI 10)          ;Calculate the Variable Angle Increment
   VAR_ang 0.0                ;Initiate VAR_ang.
   PR1 (* R1 PI 2)            ;Calculate Circumference of Intersecting Pipe.
   DX (/ (* R1 PI) 10)        ;Calculate the Increment on "X" axis
   X 0.0                      ;Initiate "X" Coordinate.
   L (list P1)                ;Initiate list L
   Q (+ R1 R2)
   e (if e e 0)  ;Check if "e" has been given a value,if not make it zero.
   D (if (= e 0) 0 (- Q (sqrt (- (* Q Q) (* e e)))) ;If e=0 then let D=0
                                                    ;Else Calculate
      );if                                  ;Decreament due to Pipes' Offset.
   );setq    
       (if (<= (+ R1 (abs e)) R2)
    (progn
     (if (< INT_ang 0.35)
      (progn
   (initget "Yes No")
   (prompt "\nAn intersection angle that small may create a")
   (prompt "\nvery long pattern that may be very difficult to")
   (prompt "\nbuild. Do you wish to continue? Yes or <N>o: ")
   (setq ga (getkword))
   (if (= ga nil)
   (setq ga "No")
   );if  
      );thenprogn
    );if
   (if (or (= ga nil) (= ga "Yes"))
   (progn
 ;Generate Curve Coordinates & Append to List L.  
   (repeat 21         ;It Starts from Zero and Completes 2 PI Radians.
   (setq
      L (append L (list (list X        ;The rest is Y
      (+ (/ (* (* R1 (- 1 (cos VAR_ang))) (cos INT_ang)) (sin INT_ang))
      (/ (- (- R2 (sqrt (- (* R2 R2) (expt (- (* R1 (sin VAR_ang)) e) 2)))) D)
      (sin INT_ang))))))
      VAR_ang (+ VAR_ang INC_ang)
      X (+ X DX)
   );setq
   );repeat
    (setq L (cdr L))
    (foreach p L (setq L (subst (mapcar '+ P1 p) p L))) ;Adjust points
     ;to start point
    (command "PLINE" (foreach p L (command p))
    );command
  ;Join&Fit pattern and make it bylayer color.
 (command "PEDIT" "L" "J" (car L) "" "F" "X" "CHANGE" "L" "" "P" "C" "BYLAYER"
 "")  
;Adjust LTSCALE to current Limits            
(setvar "LTSCALE" (/ (- (car (getvar "LIMMAX")) (car (getvar "LIMMIN"))) 25))
; Draw 25 mm wrap section, Make tab line Dashed & Red.
(command "PLINE" "@-5,0" "@-20,0" "@0,-25"
         (polar (getvar "LASTPOINT") 0 (+ PR1 50)) "@0,25" "@-20,0" ""
          "CHANGE" "L" "" "P" "LT" "" "C" "BYLAYER" "")
);thenprogn
      );if
    );elseprogn
 (prompt "\nBase pipe Radius must equal or Exceed Intersecting Pipe's Radius
           Plus Offset.** A B O R T I N G**")
   );if
  (princ)
);defun


Let me know if it helps...OK?

SMadsen

  • Guest
Generate a LISP Routine?
« Reply #9 on: May 03, 2004, 01:56:23 PM »
Oh i see, such a thing...

MGEE

  • Guest
Generate a LISP Routine?
« Reply #10 on: May 04, 2004, 02:12:01 PM »
Smadsen,
Up for a few pointers on the text I posted to create a Lisp routine?
The FLATPIPE.LSP didn't work for me.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Generate a LISP Routine?
« Reply #11 on: May 04, 2004, 05:04:58 PM »
I though the posted routine would do the job but after comparing the
routine against a drawing using the line method it does not match.
It is close but there must be a small math error. Perhaps someone here
could find it or create another routine. I'm tied up at this time.

The yellow line in the branch layout is the routine output and
the maroon line I generated. (not to say that I couldn't be wrong) :)

CAB

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Generate a LISP Routine?
« Reply #12 on: May 04, 2004, 05:57:47 PM »
I take it back, the routine does produce a correct flat template for the branch
WHEN the osnap is OFF.

Here is a tweeked version, osnaps & input error, still room for improvement.
But seems to work ok.
Thanks t-bear for sharing this routine.

CAB

Code: [Select]
;* FLATPIPE.LSP Draws a flat pattern to be wrapped around a pipe indicating
 ;* Cut line for intersection of two pipes with OPTIONAL LATERAL offset of
 ;* Pipes' Centerlines.
 ;* Logical Preconditions taken from FLATPAT.LSP in New Riders' "MAXIMIZING
 ;* AUTOCAD:Inside Autolisp";
 ;* Mathematical Formula from "DESIGN OF WELDED STRUCTURES" by O.W. Blodgett
 ;* THE JAMES F.LINCOLN ARC WELDING FOUNDATION;
 ;* Worked out by MOSHE AGMON,ISRAEL, i.d. No. at CompuServe 100264,1206
 ;----------------------------------------------------------------------------
 ;     P1 = Optional Start point for pattern curve.
 ;INT_ang = Angle of Intersection between the pipes.
 ;VAR_ang = Varying Angle.
 ;INC_ang = Increament of Varying Angle.
 ;     R1 = Radius of Intersecting Pipe.
 ;     R2 = Radius of Base Pipe.
 ;    PR1 = Circumference of Intersecting Pipe.
 ;      e = Lateral Offset of Pipes' Centers.    Positive for Right,
 ;Negative for Left Offset.
 ;     DX = Increament Length on "X" axis.      
 ;      X = Length on "X" axis.
 ;      L = List of Points (X,Y).
 ;     GA = Go ahead Flag.
 ;      Q = R1+R2.
 ;      D = Decreament due to Pipes' Offset.
 ;      
(defun C:FLATPIPE (/ P1 INT_ang R1 R2 e INC_ang VAR_ang PR1 DX X L Q D GA)
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq useros (getvar "osmode"))

  (if (and
        (setq
          P1 (getpoint
               "\nPick Start Point at Lower Left Corner of the Screen: "
             )
        )
        (setq R1 (getdist "\nEnter Dia. of Intersecting Pipe: "))
        (setq R2 (getdist "\nEnter Dia. of Base Pipe: "))
        (setq INT_ang (getangle "\nEnter Intersection angle: "))
      )
    (progn
      (setq e
             (getdist
               (strcat
                 "\nEnter Lateral Offset of Pipes' Centers ,Positive"
                 "for Right, Negative for Left Offset, Zero for None: <0.0> "
               )
             )
      )
      (setq R1      (/ R1 2)
            R2      (/ R2 2)
            INC_ang (/ pi 10) ;Calculate the Variable Angle Increment
            VAR_ang 0.0 ;Initiate VAR_ang.
            PR1     (* R1 pi 2) ;Calculate Circumference of Intersecting Pipe.
            DX      (/ (* R1 pi) 10) ;Calculate the Increment on "X" axis
            X       0.0 ;Initiate "X" Coordinate.
            L       (list P1) ;Initiate list L
            Q       (+ R1 R2)
            ;;Check if "e" has been given a value,if not make it zero.
            e       (if e e 0)
            ;;If e=0 then let D=0
            D       (if (= e 0) 0 ;Else Calculate
                      ;;Decreament due to Pipes' Offset.
                      (- Q (sqrt (- (* Q Q) (* e e))))
                    ) ;if
      ) ;setq    
      (if (<= (+ R1 (abs e)) R2)
        (progn
          (if (< INT_ang 0.35)
            (progn
              (initget "Yes No")
              (prompt "\nAn intersection angle that small may create a")
              (prompt "\nvery long pattern that may be very difficult to")
              (prompt "\nbuild. Do you wish to continue? Yes or <N>o: ")
              (setq ga (getkword))
              (if (= ga nil)
                (setq ga "No")
              ) ;if    
            ) ;thenprogn
          ) ;if
          (if (or (= ga nil) (= ga "Yes"))
            (progn
              ;;Generate Curve Coordinates & Append to List L.    
              (repeat 21 ;It Starts from Zero and Completes 2 PI Radians.
                (setq
                  L       (append
                            L
                            (list
                              (list
                                X ;The rest is Y
                                (+
                                  (/ (* (* R1 (- 1 (cos VAR_ang))) (cos INT_ang))
                                     (sin INT_ang)
                                  )
                                  (/
                                    (- (- R2
                                          (sqrt
                                            (- (* R2 R2)
                                               (expt (- (* R1 (sin VAR_ang)) e) 2)
                                            )
                                          )
                                       )
                                       D
                                    )
                                    (sin INT_ang)
                                  )
                                )
                              )
                            )
                          )
                  VAR_ang (+ VAR_ang INC_ang)
                  X       (+ X DX)
                ) ;setq
              ) ;repeat
              (setq L (cdr L))
              ;;Adjust points to start point
              (foreach p L (setq L (subst (mapcar '+ P1 p) p L)))
              (setvar "osmode" 0)
              (command "PLINE"
                       (foreach p L (command p))
              ) ;command
              ;;Join&Fit pattern and make it bylayer color.
              (command "PEDIT" "L" "J" (car L)  "" "F" "X" "CHANGE"
                       "L" "" "P" "C" "BYLAYER" ""
              )
              ;;Adjust LTSCALE to current Limits            
              (setvar
                "LTSCALE"
                (/ (- (car (getvar "LIMMAX")) (car (getvar "LIMMIN"))) 25)
              )
              ;; Draw 25 mm wrap section, Make tab line Dashed & Red.
              (command "PLINE" "@-5,0" "@-20,0" "@0,-25"
                       (polar (getvar "LASTPOINT") 0 (+ PR1 50))
                       "@0,25" "@-20,0" "" "CHANGE" "L" "" "P"
                       "LT" "" "C" "BYLAYER" ""
              )
            ) ;thenprogn
          ) ;if
        ) ;elseprogn
        (prompt
          (strcat
            "\nBase pipe Radius must equal or Exceed Intersecting "
            "Pipe's Radius Plus Offset.** A B O R T I N G**"
          )
        )
      ) ;if
    )
  )
  (setvar "CMDECHO" usercmd)
  (setvar "osmode" useros)

  (princ)
) ;defun
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
Generate a LISP Routine?
« Reply #13 on: May 04, 2004, 06:10:23 PM »
Quote from: MGEE
Smadsen,
Up for a few pointers on the text I posted to create a Lisp routine?
The FLATPIPE.LSP didn't work for me.


MGEE, I'm a brick'n'mortar kinda guy who never did much piping, so if you can tell me in simple words what you're looking for - preferably in terms of the math - then maybe I can cook something up.
Is it unfolding of the intersecting 'cylinders' like CAB showed?

I thought FLATPIPE did that (but then I didn't test it much). Have you searched the web for a routine that does what you want?

t-bear

  • Guest
Generate a LISP Routine?
« Reply #14 on: May 04, 2004, 07:48:36 PM »
Don't think a thing about it, Mgee...we been usin this for years now and, like I said, it ain't mine...I just pass 'em around.  Thing I like about it is the ability to set an angle and offset.  We cut a lot of pipe tangentral to larger pipes and cylinders.
If Stig or someone comes up with something better, I'd be "all ears".