Author Topic: x,-y quad broken lisp routine.  (Read 233 times)

0 Members and 1 Guest are viewing this topic.

Lonnie

  • Newt
  • Posts: 42
x,-y quad broken lisp routine.
« on: May 21, 2020, 01:19:11 PM »
I have a routine to do ducts. It works fine everywhere but in the x,-y quad. I was hoping someone could tell me what is wrong.

Code: [Select]
(defun c:turn45 (/ SS1 SS2 SS3 SS4 1st_line line_1_info 2nd_line line_2_info 3rd_line line_3_info 4th_line line_4_info vertex_1 vertex_2 tempvar angle_1  angle_2 vertexangle in_angle pt1 pt2 vertexlength perp two_pi mid_1 mid_2); Multi-Angle Elbow


   (command "undo" "begin")
   (dc_store_variables)           ;save current sys settings
   (setq ss1 (ssadd))             ;SELECT SET HOLDER FOR FIRST INNER DUCT LINE
   (setq ss2 (ssadd))             ;SELECT SET HOLDER FOR SECOND INNER DUCT LINE
   (setq ss3 (ssadd))             ;SELECT SET HOLDER FOR FIRST OUTER DUCT LINE
   (setq ss4 (ssadd))             ;SELECT SET HOLDER FOR SECOND OUTER DUCT LINE

   (setq two_pi (* pi 2))

;SELECT INNER LINES AND FILLET

   (setvar "osmode" 0)
(setvar "FILLETRAD" 0)
   (setq 1st_line (entsel "\nPick first inner line for elbow: "))
   (ssadd (car 1st_line) ss1)
   (setq mid_1 (Osnap (Cadr 1st_line) "NEA"))
   (setq line_1_info (entget (car 1st_line)))

   (setq 2nd_line (entsel "\nPick second inner line for elbow: "))
   (ssadd (car 2nd_line) ss2)
   (setq mid_2 (Osnap (Cadr 2nd_line) "NEA"))
   (setq line_2_info (entget (car 2nd_line)))

   (setq 3rd_line (entsel "\nPick first outer line for elbow: "))
   (ssadd (car 3rd_line) ss3)
   (setq line_3_info (entget (car 3rd_line)))

   (setq 4th_line (entsel "\nPick second outer line for elbow: "))
   (ssadd (car 4th_line) ss4)
   (setq line_4_info (entget (car 4th_line)))




;FILLET LINES


(command "_.fillet" 1st_line 2nd_line)

(command "_.fillet" 3rd_line 4th_line)

;ERASE SELECTION SETS

   (setq ss1 nil)
   (setq ss2 nil)
   (setq ss3 nil)
   (setq ss4 nil)

;RESET SS1 FOR FUTURE USE

   (setq ss1 (ssadd))             

;FIND INTERSECTION POINTS OF LINES

   (setq vertex_1 (inters (cdr (assoc 10 line_1_info)) (cdr (assoc 11 line_1_info)) (cdr (assoc 10 line_2_info)) (cdr (assoc 11 line_2_info)) nil))

   (setq vertex_2 (inters (cdr (assoc 10 line_3_info)) (cdr (assoc 11 line_3_info)) (cdr (assoc 10 line_4_info)) (cdr (assoc 11 line_4_info)) nil))



;DRAW LINE CONNECTING VERTICES

   (command "LINE" vertex_1 vertex_2 "")
(command "matchprop" 1st_line (entlast) "")



;GET ANGLES OF FIRST LINE AND SECOND LINE AND FIND DIFFERENCE

   (setq angle_1 (angle vertex_1  mid_1))
   (if (= angle_1 0)                                  ;IF EITHER ANGLE IS ZERO, SET TO 2XPI
       (setq angle_1 two_pi)
   );ENDIF

   (setq angle_2 (angle vertex_1  mid_2))
   (if (= angle_2 0)                                  ;IF EITHER ANGLE IS ZERO, SET TO 2XPI
       (setq angle_2 two_pi)
   );ENDIF

   (setq in_angle (abs(- angle_1 angle_2)))
   (if (> in_angle pi)                                 ;IF ANGLE > 180 DEG,
       (setq in_angle (- two_pi in_angle))             ;SET ANGLE TO 360 - ANGLE
   );ENDIF


;CALCULATE ANGULAR OFFSET FROM VERTEX LINE

   (setq vertexangle (angle vertex_1 vertex_2))
   (setq offangle (/ (- pi in_angle) 2))         ;(PI - INTERIOR ANGLE)/2 = ANGULAR OFFSET FROM VERTEX LINE


;CALCULATE LENGTH OF PERP LINE

   (setq vertexlength (distance vertex_1 vertex_2))
   (setq perp (* (cos offangle) vertexlength))       ;GET LENGTH OF PERP LINE


;SET START POINT FOR 1ST PERPENDICULAR LINE

   (setq pt1 (polar vertex_1 angle_1 2))

;SET END POINT FOR 1ST PERPENDICULAR LINE

   (cond
      ((> angle_1 angle_2) (setq pt2 (polar pt1 (- vertexangle offangle) perp)))
      ((> angle_2 angle_1) (setq pt2 (polar pt1 (+ vertexangle offangle) perp)))     
      (t nil)
   );END CONDITIONAL

   (command "LINE" pt1 pt2 "")
(command "matchprop" 1st_line (entlast) "")
   (ssadd (entlast) ss1)
   (command "MIRROR" ss1 "" vertex_1 vertex_2 "")



;ERASE SELECTION SET

   (setq ss1 nil)


;RESTORE SYSTEM VARIABLES

   (dc_restore_variables)           ;restore current sys settings
(setvar "FILLETRAD" filrad)
   (command "undo" "end")
   (princ)

)



Lonnie

  • Newt
  • Posts: 42
Re: x,-y quad broken lisp routine.
« Reply #2 on: May 26, 2020, 10:34:04 AM »
Company shot down a commercial solution. While this problem does not stop us it is annoying.

I was hoping it was somewhat common and someone could point me in the right direction to fix it.

Jeff_M

  • King Gator
  • Posts: 3973
  • C3D user & customizer
Re: x,-y quad broken lisp routine.
« Reply #3 on: May 26, 2020, 07:12:51 PM »
Lonnie, commenting out these lines allowed it to work fine.

;;;   (if (> in_angle pi)                                 ;IF ANGLE > 180 DEG,
;;;       (setq in_angle (- two_pi in_angle))             ;SET ANGLE TO 360 - ANGLE
;;;   );ENDIF