Author Topic: Drawin duct elbow  (Read 6950 times)

0 Members and 2 Guests are viewing this topic.

DEVITG

  • Bull Frog
  • Posts: 480
Drawin duct elbow
« on: February 26, 2004, 07:32:59 PM »
Hi all Vlisp Gurus.

here I'm againg.
In my prior post I was asking how to choose a rutine on user demand.
http://http://theswamp.org/phpBB2/viewtopic.php?t=954
As the user ask to draw with fewer clicks,  I change the way to draw the elbows.
I use this code.

Code: [Select]

(princ "Elbow DRAWER ... type ELB as a command")
(setvar "angdir" 0)
;(setvar "lunits" 4); the user unit
(setvar "lunits" 2); my units system
 ;_-------------------------------------------------------
;constant definition
(SETQ p (* 4.0 (atan 1 1))) ; a PI definition as I use it just to remember how to get Pi when it is aviable
(SETQ P90 (/ P 2.0)) ; 90 DEGREE
(SETQ P45 (/ P 4.0)) ;45 DEGREE
(SETQ P30 (/ P 6.0)) ; 30 DEGREE
(SETQ P60 (/ P 3.0)) ;60 DEGREE
(setq p180 p) ;180 degre
(Setq p270 (* 3 p90)) ;270 degree
 ;_******************************************************
 ;_RAD TO DEG AND DEG TO RAD
(defun RTD (X) ;define  RADIAN  TO DEGREE function
  (/ (* X 180.0) P)
) ; MULTIPLY THE RAD ING BY 180  AND DIVIDE IT BY PI
(defun DTR (X) ;define DEGREE to RADIAN function
  (/ (* X p) 180.0)
) ;_end dtr rtd

;;#######################################################################################


 ;_FIXED DATA INPUT
;HERE YOU CAN INPUT ANY FIXED DATA SO YOU CAN TEST
;WITHOUT NEEDING TO INPUT THE VALUES EACH TIME
;input  
(DEFUN FIJ () ;FIXED VALUES

  (SETQ A 12.0) ;12 IS THE A DUCT SIZE
 
  (SETQ pt21 (LIST 0.0 0.0 0.0)) ;THIS IS THE C RADIOUS CENTER , AT 0X 0Y 0Z  

  (SETQ ALFA 00.0) ;ORIENTATION ANGLE

) ;_END FIJ
;;#######################################################################################################################
;DATA IMPUT PER USER
(defun ING ()

  (INITGET 7) ; NO 0, NULL, NIETHER NEGATIVE VALUE ALLOWED

  (setq om (getvar "osmode"))
  (setvar "osmode" 1) ; osmode to End

  (Setq pt21 (getpoint " select  insertion point of elbow  "))
  (setq pt22 (getpoint "select  the end point of the other  duct side   "))
  (setq a (distance pt21 pt22))  ; get the duct size
  (Setq alfa (angle pt21 pt22))  ; get the angle between the two sides
    (setvar "osmode" om)


) ;_end ing func
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
;;INPUT CHOOSING ROUTINE
(DEFUN CHOS ()
  (print
    "\nWHICH WAY YOU WANT TO INPUT YOUR VALUES ? :  <1> :FIXED VALUES. <2> USER DATA   "
  )
  (INITGET 6)
  (SETQ CODE (GETINT "\n INPUT METHOD TO USE : <default by user>  "))
  (COND
    ((= CODE 1) (FIJ)) ;IF YOU CHOOSE 1 YOU WILL USE FIXED VALUES
    ((= CODE 2) (ING)) ;IF YOU CHOOSE 2 YOU WILL USE USER VALUES AT THE COMMAND LINE
    (1 (ing))
  )
)
; END ELECTION
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

 ;_ START THE ccw
(DEFUN ccw ()
   (SETQ C (* A 1.5)) ;IT IS THE C RADIOUS AS  1.5 OF A
  (SETQ D (* A 0.25)) ; THE ELLBOW'S STRAIGHT PART
  (setq pt1 PT21)  ; pt1 to pt4 the four point of the straight part of elbow, beside the duct end
  (setq pt2 PT22)
  (setq pt3 (polar pt2 (- alfa p90) d))
  (Setq pt4 (polar pt1 (- alfa p90) d))
  (setq pt10 (polar pt3 (+ alfa 0) c)) ; it is the radious C center
  (setq pt5 (polar pt10 (- alfa P90) c));pt5 to pt8 the other four point of the elbow
  (setq pt6 (polar pt5 (+ alfa 0) d))
  (setq pt7 (polar pt6 (- alfa P90) a))
  (setq pt8 (polar pt5 (- alfa P90) a))
  (setq vw  1 )
) ;_END  CCW CALC  


;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
;;start the CW routine

(DEFUN cw ()

  (SETQ C (* A 1.5)) ;IT IS THE C RADIOUS AS  1.5 OF A

  (SETQ D (* A 0.25)) ; THE ELLBOW'S STRAIGHT PART
  (setq pt1 pt21)
  (setq pt2 pt22)
  (setq pt3 (polar pt2 (+ alfa p90) d))
  (Setq pt4 (polar pt1 (+ alfa p90) d))
  (setq pt10 (polar pt3 (+ alfa 0) c))
  (setq pt5 (polar pt10 (+ alfa p90) c))
  (setq pt6 (polar pt5 (+ alfa 0) d))
  (setq pt7 (polar pt6 (+ alfa p90) a))
  (setq pt8 (polar pt5 (+ alfa p90) a))
  (setq vw 2 )
) ;_END CALC FOR CW

;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
(DEFUN DRAW ()

  (setvar "pdmode" 34)
  (setvar "pdsize" 2)
  (command "point" pt1) ; per user it is the "insertion point of the elbow"
  (command "line" pt1 pt2 pt3 pt4 "c"); draw the straigth part of the elbow beside the duct
  (command "line" pt5 pt6 pt7 pt8 "c"); idem for the elbows's end
 
  (IF (= VW 1) ; IF VW =1 DRAW CCW
    (command "arc" "c" pt10 pt3 pt5) ; THE ARC CCW
    (command "arc" "c" pt10 pt5 pt3) ;THE ARC CW
  ) ;_END IF INTERNAL ARC
  (IF (= VW 1)
    (command "arc" "c" pt10 pt4 pt8  ) ; THE ARC CCW
    (command "arc" "c" pt10 pt8 pt4  ) ;THE ARC CW

  ) ;_END IF external ARC


      ) ;_END DRAW
  ;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
(defun c:elb ()
  (chos)
  (ccw)
  ;(cw)
  (DRAW)
  ) ;_end defun c:elb


Doing trial and error I know which routine to use acording the way I want to draw, but I can not get it done by LISP.
Please see the DWG at .
Layer 0 . the ducts


http://http://theswamp.org/lilly.pond/devitg/elbow-base.dwg

The user only pick at both end of the duct , the first will state the way to draw , this point is the outer side of the elbow.
A point is located at such place just to mark it.
Maybe a third point is needed to pick to get the correct way .

Hope you can help me
 :lol:  :wink:
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Drawin duct elbow
« Reply #1 on: February 27, 2004, 12:39:51 PM »
This is not the answer to your question but.....

Have you ever tried DuctWorks?
http://theswamp.org/swamp.files/mark/DuctWorks.zip
TheSwamp.org  (serving the CAD community since 2003)

DEVITG

  • Bull Frog
  • Posts: 480
Drawin duct elbow
« Reply #2 on: February 27, 2004, 01:13:07 PM »
yes I did , but as it is  compiled I will not learn LISP.
And furthermore, ductworks does not draw the duct as it are build here in my country.

1. A elbow for a squared or rectangiular  duct  is made as my sample or your round duct elbow.

2. A elbow for a round duct is made of cylinders sections .

3. All elbows have a small straigth part .

4. the squared elbow duct work , never is made as it is drawn.

This is an old fact ,
1.-  A lisp programer could be a duct maker?
2.- a duct maker could be a lisp progamer?
3.- a manager could be a engineer?
4.- a Engineer could be a manager?

Hope you understand my way of see it.

I never forget what my firts projet teacher told me.
Before to draw the part , draw the hole ,  but before  put the bolt,  but first of all put the wrench that will tight the bolt to join the part.
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Drawin duct elbow
« Reply #3 on: February 27, 2004, 03:01:19 PM »
Well before I turn over my source code, does the program work the way you want it to? As far as drawing elbows?
TheSwamp.org  (serving the CAD community since 2003)

DEVITG

  • Bull Frog
  • Posts: 480
Drawin duct elbow
« Reply #4 on: February 27, 2004, 06:51:03 PM »
Mark , as I told before , my intention is to learn LISP.

Your ductwork , make it in a fair way.
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Drawin duct elbow
« Reply #5 on: February 28, 2004, 11:50:54 PM »
DEVITG

Well here is you code with a few modifications.
I tried to keep it as you started when i could but some changes
were needed.
This code is not in a final state but it is working :)

Enjoy and I hope you can gain a few things from this.

CAB


PS I did not correct spelling. 8)

Code: [Select]
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;     elb.lsp  Draw an elbow from user input
;;
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
(defun c:elb (/       p90     p45     p30     p60     p180    p270
              rtd     dtr     fij     ing     draw    choose om
              calc_points pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 ptc
              get_direction midpoint direction dir alpha ductdia
             )
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;                      Local Functions                            
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-

  ;; RADIAN  TO DEGREE function
  (defun rtd (r) (/ (* r 180.0) pi))
  ;;define DEGREE to RADIAN function
  (defun dtr (d) (/ (* d pi) 180.0))
  ;;  find mid point between two points
  (defun midpoint (p1 p2)(mapcar '(lambda (a b) (* 0.5 (+ a b))) p1 p2))

 
  ;; =========================================================
  ;; (vector-side <origin> <direction> <point> )
  ;;
  ;; Returns an integer code indicating position of <point>
  ;; in relation to the directed vector whose endpoints are
  ;; <origin> and <direction>.
  ;;
  ;;   Result  Meaning
  ;;   ---------------------------------------------------------
  ;;    -1     Point is to the right of vector.
  ;;     0     Point is on (colinear with) vector
  ;;     1     Point is to the left of vector.

  (defun vector-side (v1 v2 p / r *fuzz*)
    (setq *fuzz* 1e-10)
    (setq r (- (* (-(car v2)(car v1))(-(cadr p)(cadr v1)))
               (* (-(cadr v2)(cadr v1))(-(car p)(car v1)))
            )
    )
    (cond ((equal r 0.0 *fuzz*) 0)
          (t (fix (/ (abs r) r)))
    )
  ) ; end defun
 
  ;; =========================================================
  ;;  determine the elbow direction
  (defun calc_direction (/ dircode ang midpt vpt dir)
    (if (= (setq dircode (vector-side pt1 pt2 ptside)) 0)
      (prompt "\nError, Point was on elbow base line.")
      (progn ; got which side of the elbow base line
        ;;  get direction for elbow
        (cond
          ((= dircode 1) ;ccw
           (setq dir '+)
          )
          ((= dircode -1) ; cw
           (setq dir '-)
          )
        ) ; end cond stmt
        (setq ang   (apply dir (list (angle pt1 pt2) p90))
              midpt (midPoint pt1 pt2)
              vpt   (polar midpt ang 20) ; vector point
        )
        (if (= (setq dircode (vector-side midpt vpt ptside)) 0)
          (prompt "\nError, Point was in the middle.")
          (progn ; got which side of duct
            ;;  get direction for elbow
            (cond
              ((= dircode 1) ;ccw
               (setq  direction "CCW")
               (setq dir '+)
              )
              ((= dircode -1) ; cw
               (setq  direction "CW")
               (setq dir '-)
              )
            ) ; end cond stmt
          ) ; end progn
        ) ;end if
      ) ; end progn
    ) ;end if
  )

  ;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
  ;;DATA INPUT PER USER
  (defun Get_Location ()
    (initget 7) ; NO 0, NULL, NIETHER NEGATIVE VALUE ALLOWED
    (setq om (getvar "osmode"))
    (setvar "osmode" 1) ; osmode to End
    (if (setq pt1 (getpoint "\nSelect insertion point of elbow."))
      (if (setq pt2
                 (getpoint "\nSelect the end point of the other duct side.")
          )
        (progn
          (setvar "osmode" 0) ; osmode to None
           (if (setq ptside
                      (getpoint "\nSelect point near other end of elbow.")
               )
             (progn
               (if (> (distance pt1 ptside)(distance pt2 ptside))
                 (setq tmp pt1 ; keep pt1 as inside point of elbow
                       pt1 pt2
                       pt2 tmp)
               )
               (setq alfa    (angle pt1 pt2) ; angle between sides
                     ductdia (distance pt1 pt2)) ; get the duct size
               t ; return True
             ) ; end progn
           ) ; endif
        );end progn
      ) ; endif
    ) ; endif
  ) ;_end ing func

  ;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
  ;;Calculate Points
  (defun calc_points (/ ang elbrad elbstr)
    (setq elbrad (* ductdia 1.5) ;Duct Radious = 1.5 OF A
          elbstr (* ductdia 0.25) ; THE ELLBOW'S STRAIGHT PART
          ang    (apply dir (list alfa p90))
          pt3    (polar pt2 ang elbstr)
          pt4    (polar pt1 ang elbstr)
          ptc    (polar pt4 (+ alfa pi) elbrad)
          pt5    (polar ptc ang elbrad)
          pt6    (polar pt5 ang ductdia)
          pt7    (polar pt6 (+ alfa pi) elbstr)
          pt8    (polar pt5 (+ alfa pi) elbstr)
    ) ; end setq
  ) ;_END CALC FOR CW

  ;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
  (defun draw ()
    (command ".undo" "begin")
    (setvar "osmode" 0) ; osmode to None
    ;; draw the straigth part of the elbow beside the duct
    (command ".pline" pt1 pt2 pt3 pt4 "c")
    ;; idem for the elbows's end
    (command ".pline" pt5 pt6 pt7 pt8 "c")
    (cond
      ((= direction "CCW")
       (command ".arc" "c" ptc pt3 pt6) ; THE ARC CCW
       (command ".arc" "c" ptc pt4 pt5) ; THE ARC CCW
      ) ;_END cond CCW
      ((= direction "CW")
       (command ".arc" "c" ptc pt5 pt4) ;THE ARC CW
       (command ".arc" "c" ptc pt6 pt3) ;THE ARC CW
      ) ;_END cond  CW
    ) ; end cond stmt
    (command ".undo" "end")
  ) ;_END DRAW

  ;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*


;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
;;;================================================================
;;;                    Start of Routine                            
;;;================================================================
;;; -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=- -=<*>=-
  ;;constant definition
  (setq p90 (/ pi 2.0)) ; 90 DEGREE
  (setq p45 (/ pi 4.0)) ;45 DEGREE
  (setq p30 (/ pi 6.0)) ; 30 DEGREE
  (setq p60 (/ pi 3.0)) ;60 DEGREE
  (setq p180 pi) ;180 degre    
  (setq p270 (* pi 1.5)) ;270 degree
  ;;******************************************************
  (setvar "angdir" 0)
  ;;(setvar "lunits" 4); the user unit
  (setvar "lunits" 2) ; my units system
  ;;-------------------------------------------------------

  (if (Get_Location) ; get points
    (if (setq dir (calc_direction))
      (progn
        (calc_points)
        (draw)
      ) ; end progn
      (prompt "\nCalculate direction failed...")
    ) ; endif
    (prompt "\nGet location failed...")
  ) ; endif
  (princ)
  (setvar "osmode" om)

) ;_end defun c:elb

(prompt "\nElbow DRAWER ... type ELB as a command")
(princ)


;;;  //////////////
;;;   End Of File  
;;;  \\\\\\\\\\\\\\
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.

DEVITG

  • Bull Frog
  • Posts: 480
Drawin duct elbow
« Reply #6 on: February 29, 2004, 10:31:28 AM »
Hi CAB , thanks for you answer, I really apreciate it. :D  :D

First  all ,  I shall understand the MAPCAR and LAMBDA, it is the first I will do.

Up today I do not never used it.
Could you give me a brief description how it is used in this routine ?

About my spelling , English is my second language.
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Drawin duct elbow
« Reply #7 on: February 29, 2004, 10:44:40 AM »
Don't worry about the spelling..

Look Here to learn about Mapcar & Lambda.

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.

DEVITG

  • Bull Frog
  • Posts: 480
Drawin duct elbow
« Reply #8 on: February 29, 2004, 01:29:18 PM »
Hi Cab . As a first step I understood how to use it when handling points.
Thanks againg :)  :D  :lol:  :shock:  :wink:  :roll:  :!:  :!:
Location @ Córdoba Argentina Using ACAD 2019  at Window 10