Author Topic: Marko ,Please have a look ! Draw trapezoid on the face of 3d solid  (Read 2479 times)

0 Members and 1 Guest are viewing this topic.

andy_lee

  • Newt
  • Posts: 147
Hi guys
Can make this routine draw trapezoid on the face of 3d solid ?

Here is draw isosceles trapezoid
code was at:  http://www.cadtutor.net/forum/showthread.php?88383-Draw-an-isosceles-trapezoid
Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ dtr ac ab p sl a b c d e p)
  2.   ;;    Author : Tharwat Al Shoufi                      ;;
  3.   ;; Draw Trapezoid with angle 55 on the two sides      ;;
  4.   ;; -------------------------------------------------- ;;
  5.   (defun dtr (a) (* pi (/ a 180.0)))
  6.   (if (not *traplen*)
  7.     (setq *traplen* 10.0)
  8.   )
  9.   (if (not *traphgt*)
  10.     (setq *traphgt* 4.0)
  11.   )
  12.   (if (and (setq *traplen* (cond ((getdist (strcat "\n Specify Length of Trapezoid < " (rtos *traplen* 2 2) " > :")))
  13.                                  (*traplen*)
  14.                            )
  15.            )
  16.            (setq *traphgt* (cond ((getdist (strcat "\n Specify Height of Trapezoid < " (rtos *traphgt* 2 2) " > :")))
  17.                                  (*traphgt*)
  18.                            )
  19.            )
  20.            (setq ac (/ *traphgt* (sin (dtr 55.)))
  21.                  ab (* ac (cos (dtr 55.)))
  22.            )
  23.            (if (>= (setq sl (- *traplen* (+ ab ab))) 0.)
  24.              (setq p (getpoint "\n Specify top center point of Trapezoid :"))
  25.              (progn (alert "Length of Trapezoid is too small !!") nil)
  26.            )
  27.       )
  28.     (progn (setq a (polar p pi (/ sl 2.))
  29.                  b (polar a (dtr 235.) ac)
  30.                  c (polar b 0. *traplen*)
  31.                  d (polar c (dtr 125.) ac)
  32.                  e (entmakex
  33.                      (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 4) '(70 . 1))
  34.                              (mapcar '(lambda (pt) (cons 10 (list (car pt) (cadr pt)))) (list a b c d))
  35.                      )
  36.                    )
  37.            )
  38.     )
  39.   )
  40.   (if e
  41.     (command "_.rotate" e "" "_non" p "\\")
  42.   )
  43.   (princ)
  44. )
  45.  


Reference image  from other member. Thanks.
« Last Edit: July 28, 2015, 10:11:05 AM by andy_lee »
andy.
Best regards.

andy_lee

  • Newt
  • Posts: 147
Re: Draw trapezoid on the face of 3d solid
« Reply #1 on: July 28, 2015, 10:04:51 AM »
@ribarm

Hi marko.
I know you are great with 3D models. I need you have a look. :-)
andy.
Best regards.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Marko ,Please have a look ! Draw trapezoid on the face of 3d solid
« Reply #2 on: July 28, 2015, 10:51:28 AM »
You have to experiment for a while to get used to...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test ( / dtr ac ab p sl a b c d e p ucsf cmde )
  2.   ;;    Author : Tharwat Al Shoufi                      ;;
  3.   ;; Draw Trapezoid with angle 55 on the two sides      ;;
  4.   ;; -------------------------------------------------- ;;
  5.   (defun dtr (a) (* pi (/ a 180.0)))
  6.   (if (not *traplen*)
  7.     (setq *traplen* 10.0)
  8.   )
  9.   (if (not *traphgt*)
  10.     (setq *traphgt* 4.0)
  11.   )
  12.   (if (not (eq (getvar 'worlducs) 1))
  13.     (progn
  14.       (command "_.UCS" "_W")
  15.       (setq ucsf t)
  16.     )
  17.   )
  18.   (if (and (setq *traplen* (cond ((getdist (strcat "\n Specify Length of Trapezoid < " (rtos *traplen* 2 2) " > :")))
  19.                                  (*traplen*)
  20.                            )
  21.            )
  22.            (setq *traphgt* (cond ((getdist (strcat "\n Specify Height of Trapezoid < " (rtos *traphgt* 2 2) " > :")))
  23.                                  (*traphgt*)
  24.                            )
  25.            )
  26.            (setq ac (/ *traphgt* (sin (dtr 55.)))
  27.                  ab (* ac (cos (dtr 55.)))
  28.            )
  29.            (if (>= (setq sl (- *traplen* (+ ab ab))) 0.)
  30.              (setq p (getpoint "\n Specify top center point of Trapezoid :"))
  31.              (progn (alert "Length of Trapezoid is too small !!") nil)
  32.            )
  33.       )
  34.     (progn (setq a (polar p pi (/ sl 2.))
  35.                  b (polar a (dtr 235.) ac)
  36.                  c (polar b 0. *traplen*)
  37.                  d (polar c (dtr 125.) ac)
  38.                  e (entmakex
  39.                      (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 4) '(70 . 1))
  40.                              (mapcar '(lambda (pt) (cons 10 (list (car pt) (cadr pt)))) (list a b c d))
  41.                      )
  42.                    )
  43.            )
  44.     )
  45.   )
  46.   (setq cmde (getvar 'cmdecho))
  47.   (setvar 'cmdecho 1)
  48.   (if e
  49.     (progn
  50.       (command "_.copybase" "_non" p e "" "")
  51.       (entdel e)
  52.       (prompt "\nPick face of 3D solid (edge which is parallel to Trapezoid top edge), then adjust UCS further more (Xflip, Yflip, next face if wrong picked) and then press ENTER to accept...")
  53.       (command "_.UCS" "_F")
  54.       (while (< 0 (getvar 'cmdactive)) (command "\\"))
  55.       (setq p (getpoint "\nPick or specify top center point to place Trapezoid : "))
  56.       (command "_.pasteclip" "_non" p)
  57.     )
  58.   )
  59.   (command "_.UCS" "_P")
  60.   (if ucsf
  61.     (command "_.UCS" "_P")
  62.   )
  63.   (setvar 'cmdecho cmde)
  64.   (princ)
  65. )
  66.  

HTH, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

andy_lee

  • Newt
  • Posts: 147
Re: Marko ,Please have a look ! Draw trapezoid on the face of 3d solid
« Reply #3 on: July 28, 2015, 11:43:47 AM »
You have to experiment for a while to get used to...


HTH, M.R.

Hi marko
Thank you very much!

Some feedback
  • Need "Pick or specify top center point to place Trapezoid" twice .
  • Can' rotate

andy.
Best regards.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Marko ,Please have a look ! Draw trapezoid on the face of 3d solid
« Reply #4 on: July 28, 2015, 02:27:31 PM »
OK, try this mod...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test ( / *error* dtr ac ab p sl a b c d e p ucsf cmde )
  2.   ;;    Author : Tharwat Al Shoufi                      ;;
  3.   ;; Draw Trapezoid with angle 55 on the two sides      ;;
  4.   ;; -------------------------------------------------- ;;
  5.   (defun *error* ( msg )
  6.     (if cmde (setvar 'cmdecho cmde))
  7.     (if (not (eq (getvar 'worlducs) 1)) (command "_.UCS" "_P"))
  8.     (if ucsf (command "_.UCS" "_P"))
  9.     (if msg (prompt msg))
  10.     (princ)
  11.   )
  12.   (defun dtr (a) (* pi (/ a 180.0)))
  13.   (if (not *traplen*)
  14.     (setq *traplen* 10.0)
  15.   )
  16.   (if (not *traphgt*)
  17.     (setq *traphgt* 4.0)
  18.   )
  19.   (if (not (eq (getvar 'worlducs) 1))
  20.     (progn
  21.       (command "_.UCS" "_W")
  22.       (setq ucsf t)
  23.     )
  24.   )
  25.   (if (and (setq *traplen* (cond ((getdist (strcat "\n Specify Length of Trapezoid < " (rtos *traplen* 2 2) " > :")))
  26.                                  (*traplen*)
  27.                            )
  28.            )
  29.            (setq *traphgt* (cond ((getdist (strcat "\n Specify Height of Trapezoid < " (rtos *traphgt* 2 2) " > :")))
  30.                                  (*traphgt*)
  31.                            )
  32.            )
  33.            (setq ac (/ *traphgt* (sin (dtr 55.)))
  34.                  ab (* ac (cos (dtr 55.)))
  35.            )
  36.            (if (>= (setq sl (- *traplen* (+ ab ab))) 0.)
  37.              (setq p '(0.0 0.0 0.0))
  38.              (progn (alert "Length of Trapezoid is too small !!") nil)
  39.            )
  40.       )
  41.     (progn (setq a (polar p pi (/ sl 2.))
  42.                  b (polar a (dtr 235.) ac)
  43.                  c (polar b 0. *traplen*)
  44.                  d (polar c (dtr 125.) ac)
  45.                  e (entmakex
  46.                      (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 4) '(70 . 1))
  47.                              (mapcar '(lambda (pt) (cons 10 (list (car pt) (cadr pt)))) (list a b c d))
  48.                      )
  49.                    )
  50.            )
  51.     )
  52.   )
  53.   (setq cmde (getvar 'cmdecho))
  54.   (setvar 'cmdecho 1)
  55.   (if e
  56.     (progn
  57.       (command "_.copybase" "_non" p e "" "")
  58.       (entdel e)
  59.       (prompt "\nPick face of 3D solid (edge which is parallel to Trapezoid top edge), then adjust UCS further more (Xflip, Yflip, next face if wrong picked) and then press ENTER to accept...")
  60.       (command "_.UCS" "_F")
  61.       (while (< 0 (getvar 'cmdactive)) (command "\\"))
  62.       (setq p (getpoint "\nPick or specify top center point to place Trapezoid : "))
  63.       (command "_.pasteclip" "_non" p)
  64.       (command "_.rotate" (entlast) "" "_non" p "\\")
  65.     )
  66.   )
  67.   (command "_.UCS" "_P")
  68.   (*error* nil)
  69. )
  70.  

M.R.
« Last Edit: July 28, 2015, 02:44:41 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

andy_lee

  • Newt
  • Posts: 147
Re: Marko ,Please have a look ! Draw trapezoid on the face of 3d solid
« Reply #5 on: July 29, 2015, 12:00:32 AM »
OK, try this mod...

M.R.

marko
You are great . Your help was greatly appreciated.
andy.
Best regards.