Author Topic: if or cond  (Read 1839 times)

0 Members and 1 Guest are viewing this topic.

cadman6735

  • Guest
if or cond
« on: April 23, 2014, 12:52:37 PM »
I am stuck

I am creating a small macro for a fillet command

basically I don't want to enter the radius all the time and if nothing is entered I want it to default to "0"

how can I accomplish this, thanks

Code: [Select]
(defun c:test ( / p1 p2 rad )

  (setq p1 (entsel)
p2 (entsel)
rad 0 ;(getreal "\nEnter Radius: ")
  )

  (setvar "filletrad" rad)
  (command "._fillet" p1 p2)

(princ)

)

cadman6735

  • Guest
Re: if or cond
« Reply #1 on: April 23, 2014, 01:08:03 PM »
sorry, figured it out

Code: [Select]
(defun c:test ( / p1 p2 rad )

  (setq p1 (entsel)
p2 (entsel)
rad (getreal "\nEnter Radius: ")
  )

  (cond
    ((eq rad nil)
     (setq rad 0)
    )
  )

  (setvar "filletrad" rad)
  (command "._fillet" p1 p2)

(princ)

)

thanks

ronjonp

  • Needs a day job
  • Posts: 7533
Re: if or cond
« Reply #2 on: April 23, 2014, 01:34:06 PM »
You could just do an OR statement like so: (or rad (setq rad 0))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cadman6735

  • Guest
Re: if or cond
« Reply #3 on: April 23, 2014, 01:37:29 PM »
Thanks RonJon

ronjonp

  • Needs a day job
  • Posts: 7533
Re: if or cond
« Reply #4 on: April 23, 2014, 02:16:23 PM »
 :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: if or cond
« Reply #5 on: April 23, 2014, 03:19:24 PM »
Or (to avoid the setq):
Code: [Select]
(setvar "filletrad" (cond (rad) (0)))

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: if or cond
« Reply #6 on: April 25, 2014, 04:47:22 AM »
Just asking ... don't you think having someone pick the radius through getdist would be better than getreal? In this case they can specify the radius either by typing or using the cross-hairs.

I'm guessing you want something else with the picked entities. Otherwise, if all you really want is to force picking the radius and then start the fillet command, you could do it through something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:MyFillet  (/)
  2.   (setvar "FilletRad"
  3.           (cond ((getdist (strcat "Specify fillet radius <" (rtos (getvar "FilletRad")) ">: ")))
  4.                 ((getvar "FilletRad"))))
  5.   (command "_.FILLET")
  6.   (princ))
Or even simpler:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:MyFillet2  (/)
  2.   (command "_.FILLET" "_Radius" pause "_.FILLET")
  3.   (princ))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

danallen

  • Guest
Re: if or cond
« Reply #7 on: April 25, 2014, 09:28:12 AM »
I use F for fillet with no radius, and FR for with radius

Code: [Select]
;;; replace error routines with your own, or if you have express tools XYZ-ERROR-INIT > ACET-ERROR-INIT

;;; fillet with zero radius (default mode) & trim on
(defun c:F   ()
  (XYZ-ERROR-INIT (list (list "cmdecho" 0 "filletrad" 0 "trimmode" 1) T)) ;do list of variables to be set/reset
  (princ "\nFILLET with zero radius - use FR to use radius")
  (princ "\n<Select first object>: ")
  (command "FILLET")
  (setvar "cmdecho" 1)
  (XYZ_CMDACTIVE nil) ;finish filleting
  (XYZ-ERROR-RESTORE)
  (princ)
)

;;; fillet with zero radius (default mode) & trim OFF
(defun c:FN   ()
  (XYZ-ERROR-INIT (list (list "cmdecho" 0 "filletrad" 0 "trimmode" 0) T)) ;do list of variables to be set/reset
  (princ "\nFILLET with zero radius - use FR to use radius")
  (princ "\n<Select first object>: ")
  (command "FILLET")
  (setvar "cmdecho" 1)
  (XYZ_CMDACTIVE nil) ;finish filleting
  (XYZ-ERROR-RESTORE)
  (princ)
)

(defun c:FR1  () ;quick fillet with already set radius
  (princ (strcat "\nFILLET with radius <" (rtos (getvar "filletrad")) ">: "))
  (command "fillet")
  (princ)
)

(defun c:FRP1  () ;quick fillet with already set radius
  (princ (strcat "\nFILLET polyline with radius <" (rtos (getvar "filletrad")) ">: "))
  (command "fillet" "polyline")
  (princ)
)

;;; fillet with radius
(defun c:FR ()
  (XYZ-ERROR-INIT (list (list "cmdecho" 0) T)) ;do list of variables to be set/reset
  (princ (strcat "\nFILLET with radius - Enter radius <" (rtos (getvar "filletrad")) ">: "))
  (command "fillet" "radius")(XYZ_CMDACTIVE nil)
  (princ "\nPolyline/Radius/Trim/<Select first object>: ")
    (command "fillet")
    (setvar "cmdecho" 1)
    (XYZ_CMDACTIVE nil) ;finish filleting
  (XYZ-ERROR-RESTORE)
  (princ)
)

;;; fillet with radius - no trim
(defun c:FRN ()
  (XYZ-ERROR-INIT (list (list "cmdecho" 0 "trimmode" 0) T)) ;do list of variables to be set/reset
  (princ (strcat "\nFILLET with radius - Enter radius <" (rtos (getvar "filletrad")) ">: "))
  (command "fillet" "radius")(XYZ_CMDACTIVE nil)
  (princ "\nPolyline/Radius/Trim/<Select first object>: ")
    (command "fillet")
    (setvar "cmdecho" 1)
    (XYZ_CMDACTIVE nil) ;finish filleting
  (XYZ-ERROR-RESTORE)
  (princ)
)

;;; fillet with radius in centimeters
(defun c:FRCM ( / fr1 fr2)
  (XYZ-ERROR-INIT (list (list "cmdecho" 0) T)) ;do list of variables to be set/reset
  (setq fr1 (XYZ_GETREAL "\nFILLET radius in centimeters? " (if XYZ_FilletRadiusCM (cvunit XYZ_FilletRadiusCM "inch" "cm"))))
  (setq fr2 (cvunit fr1 "cm" "inch"))
  (command "fillet" "radius" fr2)(XYZ_CMDACTIVE nil)
  (princ "\nPolyline/Radius/Trim/<Select first object>: ")
    (command "fillet")
    (setvar "cmdecho" 1)
    (XYZ_CMDACTIVE nil) ;finish filleting
  (XYZ-ERROR-RESTORE)
  (setq XYZ_FilletRadiusCM fr2)
  (princ)
)

;;; fillet multiple plines
(defun C:fpm (/ ss n cir )
  (XYZ-ERROR-INIT (list (list "cmdecho" 0) T)) ;do list of variables to be set/reset
  (while (not (setq ss (ssget '((0 . "*POLYLINE*"))))))
  (setq n (1- (sslength ss)))
  (while (>= n 0)
    (setq cir (ssname ss n)
          n (1- n)
    );;setq
    (command "fillet" "p" cir)
    (princ)
  );;while
  (princ
    (strcat
      (itoa (sslength ss))
      " POLYLINEs filleted."
    );;strcat
  );;alert
  (XYZ-ERROR-RESTORE)
)

    ;==========================================================
    ; Continue pausing until exited command mode
    ; nil = pause
    ; otherwise pass string to use
    ;==========================================================
    (defun XYZ_CMDACTIVE ( passcmd / )
      (if (null passcmd) (setq passcmd pause))
      (while (not (= 0 (getvar "cmdactive")))
        (command passcmd)
      ) ;end while
    )